From d08a0ede1d2cb15bb14b0ff75eacf5c682b1fa0a Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Tue, 6 Dec 2011 12:36:58 -0600 Subject: Initial import of year-and-a-half-old upstream version 0.9.6a --- src/Makefile.am | 147 + src/addnetworkroutedialog.cpp | 117 + src/addnetworkroutedialog.h | 68 + src/addnetworkroutedialogbase.ui | 343 + src/advancedprofiledialogbase.ui | 193 + src/advancedprofilesettingsdialogbase.ui | 793 + src/advancedsettingsdialog.cpp | 219 + src/advancedsettingsdialog.h | 56 + src/ciscocertificateenrollment.cpp | 742 + src/ciscocertificateenrollment.h | 104 + src/ciscocertificateenrollmentbase.ui | 272 + src/ciscocertificateenrollmentdatadialog.cpp | 39 + src/ciscocertificateenrollmentdatadialog.h | 46 + src/ciscocertificateenrollmentdatadialogbase.ui | 402 + src/ciscocertificateenrollmentfinishwidgetbase.ui | 33 + src/ciscopasswddecoder.cpp | 227 + src/ciscopasswddecoder.h | 56 + src/configconnectoptions.cpp | 58 + src/configconnectoptions.h | 48 + src/configconnectoptionsbase.ui | 219 + src/configdaemonoptions.cpp | 95 + src/configdaemonoptions.h | 46 + src/configdaemonoptionsbase.ui | 2673 +++ src/configdebugoptions.cpp | 47 + src/configdebugoptions.h | 46 + src/configdebugoptionsbase.ui | 243 + src/configgeneraloptions.ui | 199 + src/confighelperprogramoptions.cpp | 42 + src/confighelperprogramoptions.h | 44 + src/confighelperprogramoptionsbase.ui | 1489 ++ src/configlogoptions.cpp | 98 + src/configlogoptions.h | 63 + src/configlogoptionsbase.ui | 624 + src/debugoutputtextedit.cpp | 55 + src/debugoutputtextedit.h | 48 + src/displaycertdialog.cpp | 76 + src/displaycertdialog.h | 50 + src/displaycertdialogbase.ui | 875 + src/enterpassworddialog.cpp | 94 + src/enterpassworddialog.h | 41 + src/enterpassworddialogbase.ui | 335 + src/enterxauthinteractivepasscodedialog.cpp | 53 + src/enterxauthinteractivepasscodedialog.h | 41 + src/enterxauthinteractivepasscodedialogbase.ui | 158 + src/eventsrc | 120 + src/generateopenvpnkeydialog.cpp | 134 + src/generateopenvpnkeydialog.h | 54 + src/generateopenvpnkeydialogbase.ui | 73 + src/helpdialog.cpp | 28 + src/helpdialog.h | 36 + src/helpdialogbase.ui | 124 + src/icons/Makefile.am | 5 + src/icons/hi16-action-cert.png | Bin 0 -> 640 bytes src/icons/hi16-action-certimport.png | Bin 0 -> 630 bytes src/icons/hi16-action-cisco.png | Bin 0 -> 426 bytes src/icons/hi16-action-connected.png | Bin 0 -> 831 bytes src/icons/hi16-action-connecting.png | Bin 0 -> 740 bytes src/icons/hi16-action-disconnected.png | Bin 0 -> 756 bytes src/icons/hi16-action-donate.png | Bin 0 -> 685 bytes src/icons/hi16-action-fritzboximport.png | Bin 0 -> 1028 bytes src/icons/hi16-action-kame.png | Bin 0 -> 1066 bytes src/icons/hi16-action-openssh.png | Bin 0 -> 3495 bytes src/icons/hi16-action-openswan.png | Bin 0 -> 502 bytes src/icons/hi16-action-openvpn.png | Bin 0 -> 640 bytes src/icons/hi16-action-openvpnimport.png | Bin 0 -> 755 bytes src/icons/hi16-action-pcfimport.png | Bin 0 -> 384 bytes src/icons/hi16-action-profilenew.png | Bin 0 -> 635 bytes src/icons/hi16-action-route.png | Bin 0 -> 610 bytes src/icons/hi16-action-smartcard.png | Bin 0 -> 725 bytes src/icons/hi16-action-user.png | Bin 0 -> 753 bytes src/icons/hi16-app-kvpnc.png | Bin 0 -> 971 bytes src/icons/hi22-action-certimport.png | Bin 0 -> 954 bytes src/icons/hi22-action-cisco.png | Bin 0 -> 529 bytes src/icons/hi22-action-connected.png | Bin 0 -> 1225 bytes src/icons/hi22-action-connecting.png | Bin 0 -> 1336 bytes src/icons/hi22-action-disconnected.png | Bin 0 -> 1309 bytes src/icons/hi22-action-donate.png | Bin 0 -> 1116 bytes src/icons/hi22-action-kame.png | Bin 0 -> 1066 bytes src/icons/hi22-action-openssh.png | Bin 0 -> 3938 bytes src/icons/hi22-action-openswan.png | Bin 0 -> 814 bytes src/icons/hi22-action-openvpn.png | Bin 0 -> 1058 bytes src/icons/hi22-action-openvpnimport.png | Bin 0 -> 694 bytes src/icons/hi22-action-pcfimport.png | Bin 0 -> 1287 bytes src/icons/hi22-action-profilenew.png | Bin 0 -> 819 bytes src/icons/hi22-action-route.png | Bin 0 -> 904 bytes src/icons/hi22-action-smartcard.png | Bin 0 -> 1017 bytes src/icons/hi22-action-user.png | Bin 0 -> 1238 bytes src/icons/hi22-app-kvpnc.png | Bin 0 -> 1543 bytes src/icons/hi32-action-connected.png | Bin 0 -> 2079 bytes src/icons/hi32-action-connecting.png | Bin 0 -> 2216 bytes src/icons/hi32-action-disconnected.png | Bin 0 -> 2337 bytes src/icons/hi32-action-fritzboximport.png | Bin 0 -> 1289 bytes src/icons/hi32-action-openssh.png | Bin 0 -> 4935 bytes src/icons/hi32-action-openswan.png | Bin 0 -> 1387 bytes src/icons/hi32-action-openvpn.png | Bin 0 -> 1954 bytes src/icons/hi32-action-smartcard.png | Bin 0 -> 1700 bytes src/icons/hi32-app-kvpnc.png | Bin 0 -> 2676 bytes src/icons/hi48-action-openvpn.png | Bin 0 -> 3915 bytes src/icons/hi64-action-openswan.png | Bin 0 -> 4089 bytes src/icons/hi64-action-smartcard.png | Bin 0 -> 4243 bytes src/icons/lo16-action-certimport.png | Bin 0 -> 662 bytes src/icons/lo16-action-cisco.png | Bin 0 -> 426 bytes src/icons/lo16-action-connected.png | Bin 0 -> 831 bytes src/icons/lo16-action-connecting.png | Bin 0 -> 740 bytes src/icons/lo16-action-disconnected.png | Bin 0 -> 756 bytes src/icons/lo16-action-donate.png | Bin 0 -> 685 bytes src/icons/lo16-action-fritzboximport.png | Bin 0 -> 1028 bytes src/icons/lo16-action-kame.png | Bin 0 -> 1066 bytes src/icons/lo16-action-openssh.png | Bin 0 -> 3495 bytes src/icons/lo16-action-openswan.png | Bin 0 -> 502 bytes src/icons/lo16-action-openvpn.png | Bin 0 -> 640 bytes src/icons/lo16-action-openvpnimport.png | Bin 0 -> 755 bytes src/icons/lo16-action-pcfimport.png | Bin 0 -> 384 bytes src/icons/lo16-action-profilenew.png | Bin 0 -> 635 bytes src/icons/lo16-action-route.png | Bin 0 -> 610 bytes src/icons/lo16-action-smartcard.png | Bin 0 -> 725 bytes src/icons/lo16-action-user.png | Bin 0 -> 753 bytes src/icons/lo16-app-kvpnc.png | Bin 0 -> 971 bytes src/icons/lo22-action-certimport.png | Bin 0 -> 954 bytes src/icons/lo22-action-cisco.png | Bin 0 -> 529 bytes src/icons/lo22-action-connected.png | Bin 0 -> 1225 bytes src/icons/lo22-action-connecting.png | Bin 0 -> 282 bytes src/icons/lo22-action-disconnected.png | Bin 0 -> 1309 bytes src/icons/lo22-action-donate.png | Bin 0 -> 1116 bytes src/icons/lo22-action-kame.png | Bin 0 -> 1066 bytes src/icons/lo22-action-openssh.png | Bin 0 -> 3938 bytes src/icons/lo22-action-openswan.png | Bin 0 -> 814 bytes src/icons/lo22-action-openvpn.png | Bin 0 -> 1058 bytes src/icons/lo22-action-openvpnimport.png | Bin 0 -> 694 bytes src/icons/lo22-action-pcfimport.png | Bin 0 -> 1287 bytes src/icons/lo22-action-profilenew.png | Bin 0 -> 819 bytes src/icons/lo22-action-route.png | Bin 0 -> 904 bytes src/icons/lo22-action-smartcard.png | Bin 0 -> 1017 bytes src/icons/lo22-action-user.png | Bin 0 -> 1238 bytes src/icons/lo22-app-kvpnc.png | Bin 0 -> 1543 bytes src/icons/lo32-action-connected.png | Bin 0 -> 2064 bytes src/icons/lo32-action-connecting.png | Bin 0 -> 1336 bytes src/icons/lo32-action-disconnected.png | Bin 0 -> 2337 bytes src/icons/lo32-action-fritzboximport.png | Bin 0 -> 1289 bytes src/icons/lo32-action-openssh.png | Bin 0 -> 4935 bytes src/icons/lo32-action-openswan.png | Bin 0 -> 1387 bytes src/icons/lo32-action-openvpn.png | Bin 0 -> 1954 bytes src/icons/lo32-action-smartcard.png | Bin 0 -> 1700 bytes src/icons/lo32-app-kvpnc.png | Bin 0 -> 2676 bytes src/icons/lo48-action-openvpn.png | Bin 0 -> 3915 bytes src/icons/lo64-action-openswan.png | Bin 0 -> 4089 bytes src/icons/lo64-action-smartcard.png | Bin 0 -> 4243 bytes src/importcertificatedialog.cpp | 1362 ++ src/importcertificatedialog.h | 87 + src/importcertificatedialogbase.ui | 349 + src/importipsecprofiledialog.cpp | 1100 + src/importipsecprofiledialog.h | 58 + src/importopenvpnprofiledialog.cpp | 1136 + src/importopenvpnprofiledialog.h | 53 + src/importopenvpnprofiledialogbase.ui | 122 + src/importprofiledialog.cpp | 601 + src/importprofiledialog.h | 54 + src/importprofiledialogbase.ui | 126 + src/kfeedback.cpp | 504 + src/kfeedback.h | 450 + src/kvpnc.cpp | 25220 ++++++++++++++++++++ src/kvpnc.desktop | 27 + src/kvpnc.h | 548 + src/kvpnc.lsm | 14 + src/kvpncconfig.cpp | 4524 ++++ src/kvpncconfig.h | 271 + src/kvpncimportprofileselectiondialog.cpp | 45 + src/kvpncimportprofileselectiondialog.h | 42 + src/kvpncimportprofileselectiondialogbase.ui | 221 + src/kvpnckicker.cpp | 84 + src/kvpnckicker.h | 60 + src/kvpncui.rc | 54 + src/listviewtooltip.cpp | 24 + src/listviewtooltip.h | 73 + src/logviewerdialog.cpp | 275 + src/logviewerdialog.h | 59 + src/logviewerdialogbase.ui | 129 + src/main.cpp | 162 + src/mainview.cpp | 54 + src/mainview.h | 46 + src/mainviewbase.ui | 141 + src/manageciscocert.cpp | 384 + src/manageciscocert.h | 73 + src/manageciscocertbase.ui | 204 + src/networkinterface.cpp | 563 + src/networkinterface.h | 157 + src/newprofiledialog.cpp | 669 + src/newprofiledialog.h | 100 + src/newprofiledialogbase.ui | 703 + src/newprofilewizard.cpp | 4008 ++++ src/newprofilewizard.h | 249 + src/newprofilewizard.png | Bin 0 -> 54866 bytes src/newprofilewizard_final.png | Bin 0 -> 30115 bytes src/newprofilewizardauthselection.ui | 108 + src/newprofilewizardcert.ui | 732 + src/newprofilewizardciscomanually.ui | 234 + src/newprofilewizardciscopcfimport.ui | 20 + src/newprofilewizardciscoselection.ui | 97 + src/newprofilewizardconnectionstatuscheck.ui | 317 + src/newprofilewizardconnectoptions.ui | 165 + src/newprofilewizardfreeswan.ui | 887 + src/newprofilewizardgeneral.ui | 168 + src/newprofilewizardnat.ui | 201 + src/newprofilewizardnetwork.ui | 507 + src/newprofilewizardnetworkroute.ui | 258 + src/newprofilewizardopenvpn.ui | 707 + src/newprofilewizardopenvpnauth.ui | 245 + src/newprofilewizardopenvpnselection.ui | 97 + src/newprofilewizardp12certselection.ui | 134 + src/newprofilewizardpptp.ui | 537 + src/newprofilewizardpsk.ui | 257 + src/newprofilewizardracoon.ui | 779 + src/newprofilewizardstart.ui | 69 + src/newprofilewizardtypeselection.ui | 213 + src/newprofilewizarduser.ui | 224 + src/openvpnmanagementhandler.cpp | 925 + src/openvpnmanagementhandler.h | 69 + src/ovpn.protocol | 11 + src/pcf.protocol | 11 + src/ping_check.sh | 96 + src/preferencesdialog.cpp | 7147 ++++++ src/preferencesdialog.h | 248 + src/profilecertoptions.cpp | 67 + src/profilecertoptions.h | 48 + src/profilecertoptionsbase.ui | 749 + src/profileciscooptions.cpp | 45 + src/profileciscooptions.h | 47 + src/profileciscooptionsbase.ui | 755 + src/profilecmdexecafterconnectoptions.cpp | 64 + src/profilecmdexecafterconnectoptions.h | 48 + src/profilecmdexecafterconnectoptionsbase.ui | 152 + src/profilecmdexecafterdisconnectoptions.cpp | 56 + src/profilecmdexecafterdisconnectoptions.h | 48 + src/profilecmdexecafterdisconnectoptionsbase.ui | 91 + src/profilecmdexecbeforeconnectoptions.cpp | 53 + src/profilecmdexecbeforeconnectoptions.h | 48 + src/profilecmdexecbeforeconnectoptionsbase.ui | 91 + src/profilecmdexecbeforedisconnectoptions.cpp | 52 + src/profilecmdexecbeforedisconnectoptions.h | 48 + src/profilecmdexecbeforedisconnectoptionsbase.ui | 91 + src/profilegeneraloptions.cpp | 55 + src/profilegeneraloptions.h | 53 + src/profilegeneraloptionsbase.ui | 217 + src/profileipsecoptions.cpp | 132 + src/profileipsecoptions.h | 61 + src/profileipsecoptionsbase.ui | 1179 + src/profilemanagerbase.cpp | 53 + src/profilenetworkgeneraloptions.cpp | 130 + src/profilenetworkgeneraloptions.h | 55 + src/profilenetworkgeneraloptionsbase.ui | 1031 + src/profilenetworkhttpproxyoptions.cpp | 110 + src/profilenetworkhttpproxyoptions.h | 49 + src/profilenetworkhttpproxyoptionsbase.ui | 438 + src/profilenetworknatoptions.cpp | 70 + src/profilenetworknatoptions.h | 49 + src/profilenetworknatoptionsbase.ui | 225 + src/profilenetworkrouteoptions.cpp | 227 + src/profilenetworkrouteoptions.h | 60 + src/profilenetworkrouteoptionsbase.ui | 290 + src/profilenetworkvirtualipoptions.cpp | 86 + src/profilenetworkvirtualipoptions.h | 50 + src/profilenetworkvirtualipoptionsbase.ui | 302 + src/profileopenvpnoptions.cpp | 177 + src/profileopenvpnoptions.h | 61 + src/profileopenvpnoptionsbase.ui | 920 + src/profilepptpoptions.cpp | 73 + src/profilepptpoptions.h | 51 + src/profilepptpoptionsbase.ui | 697 + src/profilepskoptions.cpp | 68 + src/profilepskoptions.h | 49 + src/profilepskoptionsbase.ui | 300 + src/profileracoonoptions.cpp | 98 + src/profileracoonoptions.h | 50 + src/profileracoonoptionsbase.ui | 884 + src/profilesmartcardoptions.cpp | 81 + src/profilesmartcardoptions.h | 53 + src/profilesmartcardoptionsbase.ui | 476 + src/profilesshoptions.cpp | 98 + src/profilesshoptions.h | 51 + src/profilesshoptionsbase.ui | 372 + src/profileuseroptions.cpp | 54 + src/profileuseroptions.h | 49 + src/profileuseroptionsbase.ui | 315 + src/profilevtunoptions.cpp | 53 + src/profilevtunoptions.h | 48 + src/profilevtunoptionsbase.ui | 214 + src/toolinfo.cpp | 641 + src/toolinfo.h | 73 + src/toolsinfodialog.cpp | 527 + src/toolsinfodialog.h | 37 + src/toolsinfowidgetbase.ui | 141 + src/utils.cpp | 1912 ++ src/utils.h | 202 + src/vpnaccountdata.cpp | 2291 ++ src/vpnaccountdata.h | 689 + src/vpntypesinfodialog.cpp | 447 + src/vpntypesinfodialog.h | 51 + src/widgetnotifyhelper.cpp | 93 + src/widgetnotifyhelper.h | 39 + src/x-cisco.desktop | 9 + src/x-openvpn.desktop | 9 + 301 files changed, 92867 insertions(+) create mode 100644 src/Makefile.am create mode 100644 src/addnetworkroutedialog.cpp create mode 100644 src/addnetworkroutedialog.h create mode 100644 src/addnetworkroutedialogbase.ui create mode 100644 src/advancedprofiledialogbase.ui create mode 100644 src/advancedprofilesettingsdialogbase.ui create mode 100644 src/advancedsettingsdialog.cpp create mode 100644 src/advancedsettingsdialog.h create mode 100644 src/ciscocertificateenrollment.cpp create mode 100644 src/ciscocertificateenrollment.h create mode 100644 src/ciscocertificateenrollmentbase.ui create mode 100644 src/ciscocertificateenrollmentdatadialog.cpp create mode 100644 src/ciscocertificateenrollmentdatadialog.h create mode 100644 src/ciscocertificateenrollmentdatadialogbase.ui create mode 100644 src/ciscocertificateenrollmentfinishwidgetbase.ui create mode 100644 src/ciscopasswddecoder.cpp create mode 100644 src/ciscopasswddecoder.h create mode 100644 src/configconnectoptions.cpp create mode 100644 src/configconnectoptions.h create mode 100644 src/configconnectoptionsbase.ui create mode 100644 src/configdaemonoptions.cpp create mode 100644 src/configdaemonoptions.h create mode 100644 src/configdaemonoptionsbase.ui create mode 100644 src/configdebugoptions.cpp create mode 100644 src/configdebugoptions.h create mode 100644 src/configdebugoptionsbase.ui create mode 100644 src/configgeneraloptions.ui create mode 100644 src/confighelperprogramoptions.cpp create mode 100644 src/confighelperprogramoptions.h create mode 100644 src/confighelperprogramoptionsbase.ui create mode 100644 src/configlogoptions.cpp create mode 100644 src/configlogoptions.h create mode 100644 src/configlogoptionsbase.ui create mode 100644 src/debugoutputtextedit.cpp create mode 100644 src/debugoutputtextedit.h create mode 100644 src/displaycertdialog.cpp create mode 100644 src/displaycertdialog.h create mode 100644 src/displaycertdialogbase.ui create mode 100644 src/enterpassworddialog.cpp create mode 100644 src/enterpassworddialog.h create mode 100644 src/enterpassworddialogbase.ui create mode 100644 src/enterxauthinteractivepasscodedialog.cpp create mode 100644 src/enterxauthinteractivepasscodedialog.h create mode 100644 src/enterxauthinteractivepasscodedialogbase.ui create mode 100644 src/eventsrc create mode 100644 src/generateopenvpnkeydialog.cpp create mode 100644 src/generateopenvpnkeydialog.h create mode 100644 src/generateopenvpnkeydialogbase.ui create mode 100644 src/helpdialog.cpp create mode 100644 src/helpdialog.h create mode 100644 src/helpdialogbase.ui create mode 100644 src/icons/Makefile.am create mode 100644 src/icons/hi16-action-cert.png create mode 100644 src/icons/hi16-action-certimport.png create mode 100644 src/icons/hi16-action-cisco.png create mode 100644 src/icons/hi16-action-connected.png create mode 100644 src/icons/hi16-action-connecting.png create mode 100644 src/icons/hi16-action-disconnected.png create mode 100644 src/icons/hi16-action-donate.png create mode 100644 src/icons/hi16-action-fritzboximport.png create mode 100644 src/icons/hi16-action-kame.png create mode 100644 src/icons/hi16-action-openssh.png create mode 100644 src/icons/hi16-action-openswan.png create mode 100644 src/icons/hi16-action-openvpn.png create mode 100644 src/icons/hi16-action-openvpnimport.png create mode 100644 src/icons/hi16-action-pcfimport.png create mode 100644 src/icons/hi16-action-profilenew.png create mode 100644 src/icons/hi16-action-route.png create mode 100644 src/icons/hi16-action-smartcard.png create mode 100644 src/icons/hi16-action-user.png create mode 100644 src/icons/hi16-app-kvpnc.png create mode 100644 src/icons/hi22-action-certimport.png create mode 100644 src/icons/hi22-action-cisco.png create mode 100644 src/icons/hi22-action-connected.png create mode 100644 src/icons/hi22-action-connecting.png create mode 100644 src/icons/hi22-action-disconnected.png create mode 100644 src/icons/hi22-action-donate.png create mode 100644 src/icons/hi22-action-kame.png create mode 100644 src/icons/hi22-action-openssh.png create mode 100644 src/icons/hi22-action-openswan.png create mode 100644 src/icons/hi22-action-openvpn.png create mode 100644 src/icons/hi22-action-openvpnimport.png create mode 100644 src/icons/hi22-action-pcfimport.png create mode 100644 src/icons/hi22-action-profilenew.png create mode 100644 src/icons/hi22-action-route.png create mode 100644 src/icons/hi22-action-smartcard.png create mode 100644 src/icons/hi22-action-user.png create mode 100644 src/icons/hi22-app-kvpnc.png create mode 100644 src/icons/hi32-action-connected.png create mode 100644 src/icons/hi32-action-connecting.png create mode 100644 src/icons/hi32-action-disconnected.png create mode 100644 src/icons/hi32-action-fritzboximport.png create mode 100644 src/icons/hi32-action-openssh.png create mode 100644 src/icons/hi32-action-openswan.png create mode 100644 src/icons/hi32-action-openvpn.png create mode 100644 src/icons/hi32-action-smartcard.png create mode 100644 src/icons/hi32-app-kvpnc.png create mode 100644 src/icons/hi48-action-openvpn.png create mode 100644 src/icons/hi64-action-openswan.png create mode 100644 src/icons/hi64-action-smartcard.png create mode 100644 src/icons/lo16-action-certimport.png create mode 100644 src/icons/lo16-action-cisco.png create mode 100644 src/icons/lo16-action-connected.png create mode 100644 src/icons/lo16-action-connecting.png create mode 100644 src/icons/lo16-action-disconnected.png create mode 100644 src/icons/lo16-action-donate.png create mode 100644 src/icons/lo16-action-fritzboximport.png create mode 100644 src/icons/lo16-action-kame.png create mode 100644 src/icons/lo16-action-openssh.png create mode 100644 src/icons/lo16-action-openswan.png create mode 100644 src/icons/lo16-action-openvpn.png create mode 100644 src/icons/lo16-action-openvpnimport.png create mode 100644 src/icons/lo16-action-pcfimport.png create mode 100644 src/icons/lo16-action-profilenew.png create mode 100644 src/icons/lo16-action-route.png create mode 100644 src/icons/lo16-action-smartcard.png create mode 100644 src/icons/lo16-action-user.png create mode 100644 src/icons/lo16-app-kvpnc.png create mode 100644 src/icons/lo22-action-certimport.png create mode 100644 src/icons/lo22-action-cisco.png create mode 100644 src/icons/lo22-action-connected.png create mode 100644 src/icons/lo22-action-connecting.png create mode 100644 src/icons/lo22-action-disconnected.png create mode 100644 src/icons/lo22-action-donate.png create mode 100644 src/icons/lo22-action-kame.png create mode 100644 src/icons/lo22-action-openssh.png create mode 100644 src/icons/lo22-action-openswan.png create mode 100644 src/icons/lo22-action-openvpn.png create mode 100644 src/icons/lo22-action-openvpnimport.png create mode 100644 src/icons/lo22-action-pcfimport.png create mode 100644 src/icons/lo22-action-profilenew.png create mode 100644 src/icons/lo22-action-route.png create mode 100644 src/icons/lo22-action-smartcard.png create mode 100644 src/icons/lo22-action-user.png create mode 100644 src/icons/lo22-app-kvpnc.png create mode 100644 src/icons/lo32-action-connected.png create mode 100644 src/icons/lo32-action-connecting.png create mode 100644 src/icons/lo32-action-disconnected.png create mode 100644 src/icons/lo32-action-fritzboximport.png create mode 100644 src/icons/lo32-action-openssh.png create mode 100644 src/icons/lo32-action-openswan.png create mode 100644 src/icons/lo32-action-openvpn.png create mode 100644 src/icons/lo32-action-smartcard.png create mode 100644 src/icons/lo32-app-kvpnc.png create mode 100644 src/icons/lo48-action-openvpn.png create mode 100644 src/icons/lo64-action-openswan.png create mode 100644 src/icons/lo64-action-smartcard.png create mode 100644 src/importcertificatedialog.cpp create mode 100644 src/importcertificatedialog.h create mode 100644 src/importcertificatedialogbase.ui create mode 100644 src/importipsecprofiledialog.cpp create mode 100644 src/importipsecprofiledialog.h create mode 100644 src/importopenvpnprofiledialog.cpp create mode 100644 src/importopenvpnprofiledialog.h create mode 100644 src/importopenvpnprofiledialogbase.ui create mode 100644 src/importprofiledialog.cpp create mode 100644 src/importprofiledialog.h create mode 100644 src/importprofiledialogbase.ui create mode 100644 src/kfeedback.cpp create mode 100644 src/kfeedback.h create mode 100644 src/kvpnc.cpp create mode 100644 src/kvpnc.desktop create mode 100644 src/kvpnc.h create mode 100644 src/kvpnc.lsm create mode 100644 src/kvpncconfig.cpp create mode 100644 src/kvpncconfig.h create mode 100644 src/kvpncimportprofileselectiondialog.cpp create mode 100644 src/kvpncimportprofileselectiondialog.h create mode 100644 src/kvpncimportprofileselectiondialogbase.ui create mode 100644 src/kvpnckicker.cpp create mode 100644 src/kvpnckicker.h create mode 100644 src/kvpncui.rc create mode 100644 src/listviewtooltip.cpp create mode 100644 src/listviewtooltip.h create mode 100644 src/logviewerdialog.cpp create mode 100644 src/logviewerdialog.h create mode 100644 src/logviewerdialogbase.ui create mode 100644 src/main.cpp create mode 100644 src/mainview.cpp create mode 100644 src/mainview.h create mode 100644 src/mainviewbase.ui create mode 100644 src/manageciscocert.cpp create mode 100644 src/manageciscocert.h create mode 100644 src/manageciscocertbase.ui create mode 100644 src/networkinterface.cpp create mode 100644 src/networkinterface.h create mode 100644 src/newprofiledialog.cpp create mode 100644 src/newprofiledialog.h create mode 100644 src/newprofiledialogbase.ui create mode 100644 src/newprofilewizard.cpp create mode 100644 src/newprofilewizard.h create mode 100644 src/newprofilewizard.png create mode 100644 src/newprofilewizard_final.png create mode 100644 src/newprofilewizardauthselection.ui create mode 100644 src/newprofilewizardcert.ui create mode 100644 src/newprofilewizardciscomanually.ui create mode 100644 src/newprofilewizardciscopcfimport.ui create mode 100644 src/newprofilewizardciscoselection.ui create mode 100644 src/newprofilewizardconnectionstatuscheck.ui create mode 100644 src/newprofilewizardconnectoptions.ui create mode 100644 src/newprofilewizardfreeswan.ui create mode 100644 src/newprofilewizardgeneral.ui create mode 100644 src/newprofilewizardnat.ui create mode 100644 src/newprofilewizardnetwork.ui create mode 100644 src/newprofilewizardnetworkroute.ui create mode 100644 src/newprofilewizardopenvpn.ui create mode 100644 src/newprofilewizardopenvpnauth.ui create mode 100644 src/newprofilewizardopenvpnselection.ui create mode 100644 src/newprofilewizardp12certselection.ui create mode 100644 src/newprofilewizardpptp.ui create mode 100644 src/newprofilewizardpsk.ui create mode 100644 src/newprofilewizardracoon.ui create mode 100644 src/newprofilewizardstart.ui create mode 100644 src/newprofilewizardtypeselection.ui create mode 100644 src/newprofilewizarduser.ui create mode 100644 src/openvpnmanagementhandler.cpp create mode 100644 src/openvpnmanagementhandler.h create mode 100644 src/ovpn.protocol create mode 100644 src/pcf.protocol create mode 100755 src/ping_check.sh create mode 100644 src/preferencesdialog.cpp create mode 100644 src/preferencesdialog.h create mode 100644 src/profilecertoptions.cpp create mode 100644 src/profilecertoptions.h create mode 100644 src/profilecertoptionsbase.ui create mode 100644 src/profileciscooptions.cpp create mode 100644 src/profileciscooptions.h create mode 100644 src/profileciscooptionsbase.ui create mode 100644 src/profilecmdexecafterconnectoptions.cpp create mode 100644 src/profilecmdexecafterconnectoptions.h create mode 100644 src/profilecmdexecafterconnectoptionsbase.ui create mode 100644 src/profilecmdexecafterdisconnectoptions.cpp create mode 100644 src/profilecmdexecafterdisconnectoptions.h create mode 100644 src/profilecmdexecafterdisconnectoptionsbase.ui create mode 100644 src/profilecmdexecbeforeconnectoptions.cpp create mode 100644 src/profilecmdexecbeforeconnectoptions.h create mode 100644 src/profilecmdexecbeforeconnectoptionsbase.ui create mode 100644 src/profilecmdexecbeforedisconnectoptions.cpp create mode 100644 src/profilecmdexecbeforedisconnectoptions.h create mode 100644 src/profilecmdexecbeforedisconnectoptionsbase.ui create mode 100644 src/profilegeneraloptions.cpp create mode 100644 src/profilegeneraloptions.h create mode 100644 src/profilegeneraloptionsbase.ui create mode 100644 src/profileipsecoptions.cpp create mode 100644 src/profileipsecoptions.h create mode 100644 src/profileipsecoptionsbase.ui create mode 100644 src/profilemanagerbase.cpp create mode 100644 src/profilenetworkgeneraloptions.cpp create mode 100644 src/profilenetworkgeneraloptions.h create mode 100644 src/profilenetworkgeneraloptionsbase.ui create mode 100644 src/profilenetworkhttpproxyoptions.cpp create mode 100644 src/profilenetworkhttpproxyoptions.h create mode 100644 src/profilenetworkhttpproxyoptionsbase.ui create mode 100644 src/profilenetworknatoptions.cpp create mode 100644 src/profilenetworknatoptions.h create mode 100644 src/profilenetworknatoptionsbase.ui create mode 100644 src/profilenetworkrouteoptions.cpp create mode 100644 src/profilenetworkrouteoptions.h create mode 100644 src/profilenetworkrouteoptionsbase.ui create mode 100644 src/profilenetworkvirtualipoptions.cpp create mode 100644 src/profilenetworkvirtualipoptions.h create mode 100644 src/profilenetworkvirtualipoptionsbase.ui create mode 100644 src/profileopenvpnoptions.cpp create mode 100644 src/profileopenvpnoptions.h create mode 100644 src/profileopenvpnoptionsbase.ui create mode 100644 src/profilepptpoptions.cpp create mode 100644 src/profilepptpoptions.h create mode 100644 src/profilepptpoptionsbase.ui create mode 100644 src/profilepskoptions.cpp create mode 100644 src/profilepskoptions.h create mode 100644 src/profilepskoptionsbase.ui create mode 100644 src/profileracoonoptions.cpp create mode 100644 src/profileracoonoptions.h create mode 100644 src/profileracoonoptionsbase.ui create mode 100644 src/profilesmartcardoptions.cpp create mode 100644 src/profilesmartcardoptions.h create mode 100644 src/profilesmartcardoptionsbase.ui create mode 100644 src/profilesshoptions.cpp create mode 100644 src/profilesshoptions.h create mode 100644 src/profilesshoptionsbase.ui create mode 100644 src/profileuseroptions.cpp create mode 100644 src/profileuseroptions.h create mode 100644 src/profileuseroptionsbase.ui create mode 100644 src/profilevtunoptions.cpp create mode 100644 src/profilevtunoptions.h create mode 100644 src/profilevtunoptionsbase.ui create mode 100644 src/toolinfo.cpp create mode 100644 src/toolinfo.h create mode 100644 src/toolsinfodialog.cpp create mode 100644 src/toolsinfodialog.h create mode 100644 src/toolsinfowidgetbase.ui create mode 100644 src/utils.cpp create mode 100644 src/utils.h create mode 100644 src/vpnaccountdata.cpp create mode 100644 src/vpnaccountdata.h create mode 100644 src/vpntypesinfodialog.cpp create mode 100644 src/vpntypesinfodialog.h create mode 100644 src/widgetnotifyhelper.cpp create mode 100644 src/widgetnotifyhelper.h create mode 100644 src/x-cisco.desktop create mode 100644 src/x-openvpn.desktop (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..b05e48a --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,147 @@ +bin_PROGRAMS = kvpnc + +kvpnc_SOURCES = addnetworkroutedialog.cpp addnetworkroutedialogbase.ui \ + ciscocertificateenrollment.cpp ciscocertificateenrollmentbase.ui \ + ciscocertificateenrollmentdatadialog.cpp ciscocertificateenrollmentdatadialogbase.ui \ + ciscocertificateenrollmentfinishwidgetbase.ui ciscopasswddecoder.cpp configconnectoptions.cpp \ + configconnectoptionsbase.ui configdaemonoptions.cpp configdaemonoptionsbase.ui \ + configdebugoptions.cpp configdebugoptionsbase.ui configgeneraloptions.ui \ + confighelperprogramoptions.cpp confighelperprogramoptionsbase.ui configlogoptions.cpp \ + configlogoptionsbase.ui debugoutputtextedit.cpp displaycertdialog.cpp displaycertdialogbase.ui \ + enterpassworddialog.cpp enterpassworddialogbase.ui enterxauthinteractivepasscodedialog.cpp \ + enterxauthinteractivepasscodedialogbase.ui generateopenvpnkeydialog.cpp generateopenvpnkeydialogbase.ui \ + helpdialog.cpp helpdialogbase.ui importcertificatedialog.cpp \ + importcertificatedialogbase.ui importipsecprofiledialog.cpp importopenvpnprofiledialog.cpp \ + importopenvpnprofiledialogbase.ui importprofiledialog.cpp importprofiledialogbase.ui kfeedback.cpp \ + kfeedback.h kvpnc.cpp kvpnc.skel kvpncconfig.cpp \ + kvpncimportprofileselectiondialog.cpp kvpncimportprofileselectiondialogbase.ui kvpnckicker.cpp \ + listviewtooltip.cpp logviewerdialog.cpp logviewerdialogbase.ui main.cpp mainview.cpp \ + mainviewbase.ui manageciscocert.cpp manageciscocertbase.ui networkinterface.cpp \ + newprofiledialog.cpp newprofiledialogbase.ui newprofilewizard.cpp newprofilewizard.h \ + newprofilewizardauthselection.ui newprofilewizardcert.ui newprofilewizardciscomanually.ui \ + newprofilewizardciscoselection.ui newprofilewizardconnectionstatuscheck.ui \ + newprofilewizardconnectoptions.ui newprofilewizardfreeswan.ui newprofilewizardgeneral.ui \ + newprofilewizardnat.ui newprofilewizardnetwork.ui newprofilewizardnetworkroute.ui \ + newprofilewizardopenvpn.ui newprofilewizardopenvpnauth.ui newprofilewizardopenvpnselection.ui \ + newprofilewizardp12certselection.ui newprofilewizardpptp.ui newprofilewizardpsk.ui \ + newprofilewizardracoon.ui newprofilewizardstart.ui newprofilewizardtypeselection.ui \ + newprofilewizarduser.ui openvpnmanagementhandler.cpp openvpnmanagementhandler.h \ + preferencesdialog.cpp profilecertoptions.cpp profilecertoptionsbase.ui \ + profileciscooptions.cpp profileciscooptionsbase.ui profilecmdexecafterconnectoptions.cpp \ + profilecmdexecafterconnectoptionsbase.ui profilecmdexecafterdisconnectoptions.cpp \ + profilecmdexecafterdisconnectoptionsbase.ui profilecmdexecbeforeconnectoptions.cpp \ + profilecmdexecbeforeconnectoptionsbase.ui profilecmdexecbeforedisconnectoptions.cpp \ + profilecmdexecbeforedisconnectoptionsbase.ui profilegeneraloptions.cpp profilegeneraloptionsbase.ui \ + profileipsecoptions.cpp profileipsecoptionsbase.ui profilenetworkgeneraloptions.cpp \ + profilenetworkgeneraloptions.h profilenetworkgeneraloptionsbase.ui profilenetworkhttpproxyoptions.cpp \ + profilenetworkhttpproxyoptionsbase.ui profilenetworknatoptions.cpp profilenetworknatoptions.h \ + profilenetworknatoptionsbase.ui profilenetworkrouteoptions.cpp profilenetworkrouteoptionsbase.ui \ + profilenetworkvirtualipoptions.cpp profilenetworkvirtualipoptionsbase.ui profileopenvpnoptions.cpp \ + profileopenvpnoptionsbase.ui profilepptpoptions.cpp profilepptpoptionsbase.ui profilepskoptions.cpp \ + profilepskoptionsbase.ui profileracoonoptions.cpp profileracoonoptionsbase.ui \ + profilesmartcardoptions.cpp profilesmartcardoptionsbase.ui profilesshoptions.cpp \ + profilesshoptionsbase.ui profileuseroptions.cpp profileuseroptionsbase.ui profilevtunoptions.cpp \ + profilevtunoptionsbase.ui toolinfo.cpp toolsinfodialog.cpp toolsinfowidgetbase.ui utils.cpp \ + vpnaccountdata.cpp vpntypesinfodialog.cpp widgetnotifyhelper.cpp + + +kvpnc_METASOURCES = AUTO + +#CXXFLAGS = $(libgcrypt-config --libs --cflags) + +kvpnc_LDADD = $(LIB_KFILE) $(LIB_KDEUI) $(LIB_KDECORE) $(LIB_QT) $(LIBSOCKET) -lgcrypt + + + +EXTRA_DIST = main.cpp kvpnc.cpp kvpnc.h kvpnc.desktop preferencesdialog.cpp kvpncui.rc kvpnckicker.cpp kvpnckicker.h eventsrc klpreferencesdlg.h + + +install-data-local: + $(mkinstalldirs) $(kde_appsdir)/ + $(INSTALL_DATA) $(srcdir)/kvpnc.desktop $(kde_appsdir)/kvpnc.desktop + $(mkinstalldirs) $(kde_datadir)/kvpnc/ + $(INSTALL_DATA) $(srcdir)/kvpncui.rc $(kde_datadir)/kvpnc/kvpncui.rc + $(mkinstalldirs) $(kde_datadir)/kvpnc/ + $(INSTALL_DATA) $(srcdir)/eventsrc $(kde_datadir)/kvpnc/eventsrc + $(INSTALL_DATA) $(srcdir)/ping_check.sh $(kde_datadir)/kvpnc/ping_check.sh + $(INSTALL_DATA) $(srcdir)/newprofilewizard.png $(kde_datadir)/kvpnc/newprofilewizard.png + $(INSTALL_DATA) $(srcdir)/newprofilewizard_final.png $(kde_datadir)/kvpnc/newprofilewizard_final.png +# $(INSTALL_DATA) $(srcdir)/x-cisco.desktop $(kde_mimedir)/application/x-cisco.desktop +# $(INSTALL_DATA) $(srcdir)/x-openvpn.desktop $(kde_mimedir)/application/x-openvpn.desktop + $(mkinstalldirs) $(DESTDIR)$(kde_datadir)/kvpnc/ + $(INSTALL_DATA) $(srcdir)/pcf.protocol $(DESTDIR)$(kde_datadir)/kvpnc/pcf.protocol + $(INSTALL_DATA) $(srcdir)/ovpn.protocol $(DESTDIR)$(kde_datadir)/kvpnc/ovpn.protocol + +# this 10 paths are KDE specific. Use them: +# kde_htmldir Where your docs should go to. (contains lang subdirs) +# kde_appsdir Where your application file (.kdelnk) should go to. +# kde_icondir Where your icon should go to. +# kde_minidir Where your mini icon should go to. +# kde_datadir Where you install application data. (Use a subdir) +# kde_locale Where translation files should go to.(contains lang subdirs) +# kde_cgidir Where cgi-bin executables should go to. +# kde_confdir Where config files should go to. +# kde_mimedir Where mimetypes should go to. +# kde_toolbardir Where general toolbar icons should go to. +# kde_wallpaperdir Where general wallpapers should go to. + +# set the include path for X, qt and KDE +INCLUDES= $(all_includes) + +METASOURCES = AUTO + + +SUBDIRS = icons + +# the library search path. +kvpnc_LDFLAGS = $(all_libraries) $(KDE_RPATH) + +# Uncomment the following two lines if you add a ui.rc file for your application to make use of +# KDE +rcdir = $(kde_datadir)/kvpnc + + +#WARNING: if you use a ui.rc file above, use: + +# messages: rc.cpp + +# instead of + +# messages: + +messages: rc.cpp + LIST=`find . -name \*.h -o -name \*.hh -o -name \*.H -o -name \*.hxx -o -name \*.hpp -o -name \*.cpp -o -name \*.cc -o -name \*.cxx -o -name \*.ecpp -o -name \*.C`; \ + if test -n "$$LIST"; then \ + $(XGETTEXT) -C -ki18n $$LIST -o ../po/kvpnc.pot; \ + fi + +noinst_HEADERS = addnetworkroutedialog.h addnetworkroutedialogbase.h \ + ciscocertificateenrollment.h ciscocertificateenrollmentdatadialog.h configconnectoptionsbase.h \ + configdaemonoptions.h configdaemonoptionsbase.h configdebugoptions.h configdebugoptionsbase.h \ + confighelperprogramoptions.h confighelperprogramoptionsbase.h configlogoptions.h \ + configlogoptionsbase.h debugoutputtextedit.h displaycertdialog.h enterpassworddialog.h \ + enterpassworddialogbase.h enterxauthinteractivepasscodedialogbase.h generateopenvpnkeydialog.h \ + generateopenvpnkeydialogbase.h helpdialogbase.h importcertificatedialog.h \ + importcertificatedialogbase.h importipsecprofiledialog.h importopenvpnprofiledialog.h \ + importopenvpnprofiledialogbase.h importprofiledialogbase.h kvpncconfig.h \ + kvpncimportprofileselectiondialog.h kvpncimportprofileselectiondialogbase.h listviewtooltip.h \ + logviewerdialog.h logviewerdialogbase.h mainview.h mainviewbase.h manageciscocert.h \ + networkinterface.h newprofiledialog.h newprofiledialogbase.h newprofilewizard.h \ + openvpnmanagementhandler.h preferencesdialog.h profilecertoptions.h profilecertoptionsbase.h \ + profileciscooptionsbase.h profilecmdexecafterconnectoptions.h \ + profilecmdexecafterconnectoptionsbase.h profilecmdexecafterdisconnectoptions.h \ + profilecmdexecafterdisconnectoptionsbase.h profilecmdexecbeforeconnectoptions.h \ + profilecmdexecbeforeconnectoptionsbase.h profilecmdexecbeforedisconnectoptions.h \ + profilecmdexecbeforedisconnectoptionsbase.h profilegeneraloptions.h profilegeneraloptionsbase.h \ + profileipsecoptions.h profileipsecoptionsbase.h profilenetworkgeneraloptions.h \ + profilenetworkgeneraloptionsbase.h profilenetworkhttpproxyoptions.h profilenetworknatoptions.h \ + profilenetworknatoptionsbase.h profilenetworkrouteoptions.h profilenetworkrouteoptionsbase.h \ + profilenetworkvirtualipoptions.h profilenetworkvirtualipoptionsbase.h profileopenvpnoptions.h \ + profileopenvpnoptionsbase.h profilepptpoptions.h profilepptpoptionsbase.h profilepskoptions.h \ + profilepskoptionsbase.h profileracoonoptions.h profileracoonoptionsbase.h \ + profilesmartcardoptions.h profilesshoptions.h profilesshoptionsbase.h profileuseroptions.h \ + profileuseroptionsbase.h profilevtunoptions.h toolinfo.h toolsinfodialog.h toolsinfowidgetbase.h \ + utils.h vpnaccountdata.h vpntypesinfodialog.h widgetnotifyhelper.h + + + diff --git a/src/addnetworkroutedialog.cpp b/src/addnetworkroutedialog.cpp new file mode 100644 index 0000000..64c2512 --- /dev/null +++ b/src/addnetworkroutedialog.cpp @@ -0,0 +1,117 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "addnetworkroutedialog.h" +#include +#include +#include +#include +#include +#include "widgetnotifyhelper.h" +#include + +AddNetworkRouteDialog::AddNetworkRouteDialog(QWidget *parent, const QString& caption) : KDialogBase( parent, "Add_new_network_route", false, caption, + KDialogBase::Ok|KDialogBase::Cancel,KDialogBase::Ok, true ) +{ + main = new AddNetworkRouteDialogBase (this); + setMainWidget(main); + main->setMinimumSize(main->sizeHint()); + connect(main->UseGatewayCheckBox,SIGNAL(toggled(bool)),this, SLOT(useGatewayToggled(bool))); + connect(main->UseInterfaceCheckBox,SIGNAL(toggled(bool)),this, SLOT(useInterfaceToggled(bool))); + + WidgetNotifyHelper h; + h.setupChangedAction(this); + dialogModified=false; + + Network=""; + Netmask=""; + Gateway=""; + Interface=""; + useGateway=false; + useInterface=false; +} + +AddNetworkRouteDialog::~AddNetworkRouteDialog() +{ + delete main; +} + +void AddNetworkRouteDialog::accept() +{ + Network = main->RemoteNetAddrLineEdit->text(); + Netmask = main->RemoteNetMaskComboBox->currentText(); + Gateway = main->RemoteGatewayAddrLineEdit->text(); + Interface = main->InterfaceComboBox->currentText(); + useGateway = main->UseGatewayCheckBox->isChecked(); + useInterface = main->UseInterfaceCheckBox->isChecked(); + QDialog::accept(); +} + +QString AddNetworkRouteDialog::getNetwork() +{ + return Network; +} + +QString AddNetworkRouteDialog::getNetmask() +{ + return Netmask; +} + +QString AddNetworkRouteDialog::getGateway() +{ + return Gateway; +} + +QString AddNetworkRouteDialog::getInterface() +{ + return Interface; +} + +bool AddNetworkRouteDialog::getUseGateway() +{ + return useGateway; +} + +bool AddNetworkRouteDialog::getUseInterface() +{ + return useInterface; +} + +void AddNetworkRouteDialog::useGatewayToggled(bool) +{ + if (main->UseGatewayCheckBox->isChecked()) + main->RemoteGatewayAddrLineEdit->setEnabled(true); + else + main->RemoteGatewayAddrLineEdit->setEnabled(false); +} + +void AddNetworkRouteDialog::useInterfaceToggled(bool) +{ + if (main->UseInterfaceCheckBox->isChecked()) + main->InterfaceComboBox->setEnabled(true); + else + main->InterfaceComboBox->setEnabled(false); +} + +void AddNetworkRouteDialog::dialogChanged() +{ +// std::cout << "AddNetworkRouteDialog::dialogChanged()" << std::endl; + dialogModified=true; +} + diff --git a/src/addnetworkroutedialog.h b/src/addnetworkroutedialog.h new file mode 100644 index 0000000..2c58265 --- /dev/null +++ b/src/addnetworkroutedialog.h @@ -0,0 +1,68 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef ADDNETWORKROUTEDIALOG_H +#define ADDNETWORKROUTEDIALOG_H + +#include "addnetworkroutedialogbase.h" +#include +#include + +/** +@author Christoph Thielecke +*/ +class AddNetworkRouteDialog : public KDialogBase +{ + Q_OBJECT +public: + AddNetworkRouteDialog(QWidget *parent, const QString& caption); + + ~AddNetworkRouteDialog(); + QString getNetwork(); + QString getNetmask(); + QString getGateway(); + QString getInterface(); + bool getUseGateway(); + bool getUseInterface(); + AddNetworkRouteDialogBase *main; + bool dialogModified; + +public slots: + void accept(); + void useGatewayToggled(bool); + void useInterfaceToggled(bool); + +private: + QString Network; + QString Netmask; + QString Gateway; + QString Interface; + bool useGateway; + bool useInterface; + + +private slots: + void dialogChanged(); + +signals: + void changed(); + +}; + +#endif diff --git a/src/addnetworkroutedialogbase.ui b/src/addnetworkroutedialogbase.ui new file mode 100644 index 0000000..dbf2cb7 --- /dev/null +++ b/src/addnetworkroutedialogbase.ui @@ -0,0 +1,343 @@ + +AddNetworkRouteDialogBase + + + AddNetworkRouteDialogBase + + + + 0 + 0 + 365 + 145 + + + + Add Network Route + + + + + + + + + + unnamed + + + + layout12 + + + + unnamed + + + + layout9 + + + + unnamed + + + + LabelRemoteNetwork + + + true + + + Remote network: + + + + + RemoteNetAddrLineEdit + + + Remote network address + + + This is the remote network where the connection should going to. Use this at a PPTP connection for set another network than the retrieved IP is located. + + + + + RemoteNetDividetextLabel + + + / + + + + + + 8 + + + + + 9 + + + + + 10 + + + + + 11 + + + + + 12 + + + + + 13 + + + + + 14 + + + + + 15 + + + + + 16 + + + + + 17 + + + + + 18 + + + + + 19 + + + + + 20 + + + + + 21 + + + + + 22 + + + + + 23 + + + + + 24 + + + + + 25 + + + + + 26 + + + + + 27 + + + + + 28 + + + + + 29 + + + + + 30 + + + + + 31 + + + + + 32 + + + + RemoteNetMaskComboBox + + + 16 + + + Prefix (netmask) of the remote network + + + This is the netmask of the remote network. The value describes how many bits are used for the network part. For example /24 stands for the netmask 255.255.255.0 (3*8 bits) + + + + + + + layout5 + + + + unnamed + + + + UseGatewayCheckBox + + + Use gatewa&y + + + Alt+Y + + + Use the gateway to reach this network + + + + + + + + spacer55 + + + Horizontal + + + Expanding + + + + 49 + 20 + + + + + + RemoteGatewayAddrLineEdit + + + false + + + Gateway address + + + + + + + + + + layout11 + + + + unnamed + + + + UseInterfaceCheckBox + + + Use &interface + + + Alt+I + + + Use the gateway to reach this network + + + + + + + + spacer55_2 + + + Horizontal + + + Expanding + + + + 88 + 20 + + + + + + InterfaceComboBox + + + true + + + + + + + + + + RemoteNetAddrLineEdit + RemoteNetMaskComboBox + UseGatewayCheckBox + RemoteGatewayAddrLineEdit + + + + klineedit.h + kcombobox.h + klineedit.h + kcombobox.h + klineedit.h + + diff --git a/src/advancedprofiledialogbase.ui b/src/advancedprofiledialogbase.ui new file mode 100644 index 0000000..abe7445 --- /dev/null +++ b/src/advancedprofiledialogbase.ui @@ -0,0 +1,193 @@ + +AdvancedProfileDialogBase + + + AdvancedProfileDialogBase + + + + 0 + 0 + 539 + 303 + + + + Advanced Profile Settings + + + + unnamed + + + + AdvancedSettingsCheckbox + + + &Enable advanced settings + + + Alt+E + + + Enable advanced settings for profile + + + + + spacer63 + + + Vertical + + + Expanding + + + + 20 + 56 + + + + + + groupBox3 + + + Advanced profile settings + + + + unnamed + + + + SingleDesCheckbox + + + Allow single DES encr&yption + + + Alt+Y + + + Allow single DES encryption (insecure) + + + + + IkeGroupCheckbox + + + &IKE DH group: + + + Alt+I + + + Use special Diffie Hellman group + + + + + PerfectForwardSecurityCheckbox + + + Perfect for&ward secrecy (PFS): + + + Alt+W + + + Use perfect forward secrety (PFS) + + + + + ApplicationVersionCheckbox + + + Application &version: + + + Alt+V + + + Send an own application version string + + + + + PerfectForwardSecrecyCombobox + + + Diffie Helman group for Perfect Forward Secrecy + Automatic keying has a property called perfect forward secrecy. This is the Diffie Helman group for PFS. + + + This is the Diffie Helman group for PFS. +The following assignment will is used: +server = DH group is recieved from server (cisco only) +nopfs = no pfs is used +dh1 = modp768 +dh2 = modp1024 +dh5 = modp1536 +d14 = modp2048 (racoon only) +dh15= modp3072 (racoon only) +dh16 = modp4096 (racoon only) +dh17 = modp6144 (racoon only) +dh18 = modp8192 (racoon only) + + + + + IkeGroupCombobox + + + Diffie Hellman group + + + This define the group used for the Diffie-Hellman exponentiations. The following assignment is used: +dh1 = modp768 +dh2 = modp1024 +dh5 = modp1536 +d14 = modp2048 (only racoon) +dh15 = modp3072 (only racoon) +dh16 = modp4096 (only racoon) +dh17 = modp6144 (only racoon) +dh18 = modp8192 (only racoon) + + + + + ApplicationVersionLineedit + + + + + + Application version string + + + + + + + + AdvancedSettingsCheckbox + ApplicationVersionCheckbox + ApplicationVersionLineedit + IkeGroupCheckbox + IkeGroupCombobox + PerfectForwardSecurityCheckbox + PerfectForwardSecrecyCombobox + SingleDesCheckbox + + + + kcombobox.h + kcombobox.h + klineedit.h + + diff --git a/src/advancedprofilesettingsdialogbase.ui b/src/advancedprofilesettingsdialogbase.ui new file mode 100644 index 0000000..93f57d2 --- /dev/null +++ b/src/advancedprofilesettingsdialogbase.ui @@ -0,0 +1,793 @@ + +AdvancedProfileSettingsDialogBase + + + AdvancedProfileSettingsDialogBase + + + + 0 + 0 + 506 + 544 + + + + Advanced Profile Settings + + + true + + + + unnamed + + + + layout15 + + + + unnamed + + + + AdvancedSettingsCheckbox + + + Enable advanced settings + + + Check for use of advanced settings + + + + + groupBox3 + + + Advanced Profile Settings + + + + unnamed + + + + layout39 + + + + unnamed + + + + layout38 + + + + unnamed + + + + LocalPortCheckbox + + + Local port: + + + Check this if you want to specify an own local port for use with the tunnel + + + + + SingleDesCheckbox + + + Enable single DES: + + + Check for use of Single DES (insecure) + + + + + layout75_2 + + + + unnamed + + + + UseNoDeflateCheckbox + + + Do not use deflate method + + + Check this for disabling deflate decompression method (disabled by default) + + + + + spacer62_2 + + + Horizontal + + + Expanding + + + + 181 + 20 + + + + + + + + DnsServerLineedit + + + + + + IP address of DNS server (no hostname) + + + + + NtDomainNameLineedit + + + Domain name for authentication: + + + + + layout76 + + + + unnamed + + + + AllowStatefulModeCheckbox + + + Allow MPPE stateful mode + + + Check this for allow stateful mode of MPPE + + + + + spacer60 + + + Horizontal + + + Expanding + + + + 110 + 20 + + + + + + + + Refuse40BitEncryptionCheckbox + + + Refuse &40 bit encryption + + + Check this for refusing 40 bit length encryption of MPPE + + + + + requireMppeCheckbox + + + Re&quire MPPE + + + Check this for use of MPPE encrpytion (enabled by default) + + + + + GetDnsFromPeerCheckbox + + + Get DNS server from peer + + + Check this for retrieve DNS server from peer + + + + + IkeGroupCheckbox + + + IKE DH group: + + + Check this for use a special Diffie Hellman group + + + + + ApplicationVersionLineedit + + + + + + Application string + + + + + MtuCheckbox + + + MTU + + + Check this for set a own MTU size + + + If you enable this you can set a own MTU size. + + + + + layout75 + + + + unnamed + + + + RefuseEapCheckbox + + + Refuse EAP + + + Check this for refuse EAP + + + + + spacer62 + + + Horizontal + + + Expanding + + + + 181 + 20 + + + + + + + + PerfectForwardSecurityCheckbox + + + Perfect forward secrec&y: + + + Check this if you want to select perfect forward secrety method + + + + + ApplicationVersionCheckbox + + + Application version: + + + Check if you want to send an own application version string + + + + + layout15 + + + + unnamed + + + + LocalPortSpinbox + + + 65535 + + + 500 + + + The local port for use with tunnel + + + + + spacer7 + + + Horizontal + + + Expanding + + + + 167 + 21 + + + + + + + + DnsServerCheckbox + + + Userdefinied DNS server: + + + Check this for specify a own DNS server + + + + + IkeGroupCombobox + + + Diffie Hellman group + + + + + SetDefaultRouteCheckbox + + + Set default route + + + Check this for adding a new default route + + + + + layout78 + + + + unnamed + + + + UseGlobalIpsecSecretCheckbox + + + Use global IPSec secret + + + Check for use global IPSec secret from /etc/vpnc/default.conf + + + + + spacer61 + + + Horizontal + + + Expanding + + + + 141 + 20 + + + + + + + + UseNoBsdCompCheckbox + + + Do not use BSD compression + + + Check this for refuse BSD compression (disabled by default) + + + + + layout15_2 + + + + unnamed + + + + MtuSpinbox + + + 1500 + + + 1300 + + + 1492 + + + The MTU size for the ppp connection + + + Here you can specify the MTU size for use with pppd. + + + + + spacer7_3 + + + Horizontal + + + Expanding + + + + 167 + 21 + + + + + + + + PerfectForwardSecrecyCombobox + + + + + layout77 + + + + unnamed + + + + Refuse128BitEncryptionCheckbox + + + Refuse 1&28 bit encryption + + + Check this for refusing 128 bit length encryption of MPPE + + + + + spacer59 + + + Horizontal + + + Expanding + + + + 121 + 20 + + + + + + + + NtDomainNameCheckbox + + + (NT-) Domain name for authentication + + + Check if domain name for authentication is needed + + + + + layout75_2_2 + + + + unnamed + + + + ReplaceDefaultRouteCheckbox + + + Replace default route + + + Check this for replacing the existing default route. Needs 'set default route' enabled (warning: only for experts). + + + + + spacer62_2_2 + + + Horizontal + + + Expanding + + + + 181 + 20 + + + + + + + + + + spacer63 + + + Vertical + + + Expanding + + + + 20 + 20 + + + + + + + + + + Layout1 + + + + unnamed + + + 0 + + + 6 + + + + buttonHelp + + + &Help + + + F1 + + + true + + + Click for more help + + + + + Horizontal Spacing2 + + + Horizontal + + + Expanding + + + + 20 + 20 + + + + + + buttonOk + + + &OK + + + + + + true + + + true + + + Click for closing the dialog by accepting the settings + + + + + buttonCancel + + + &Cancel + + + + + + true + + + Click for closing the dialog by canceling + + + + + + + + + + + buttonOk + clicked() + AdvancedProfileSettingsDialogBase + accept() + + + buttonCancel + clicked() + AdvancedProfileSettingsDialogBase + reject() + + + buttonHelp + clicked() + AdvancedProfileSettingsDialogBase + helpClicked() + + + AdvancedSettingsCheckbox + toggled(bool) + AdvancedProfileSettingsDialogBase + advancedSettingsToggled() + + + NtDomainNameCheckbox + toggled(bool) + AdvancedProfileSettingsDialogBase + domainNameToggled() + + + SetDefaultRouteCheckbox + toggled(bool) + AdvancedProfileSettingsDialogBase + setDefaultRouteToggled() + + + DnsServerCheckbox + toggled(bool) + AdvancedProfileSettingsDialogBase + useDnsServerToggled() + + + ApplicationVersionCheckbox + toggled(bool) + AdvancedProfileSettingsDialogBase + applicationVersionToggled() + + + PerfectForwardSecurityCheckbox + toggled(bool) + AdvancedProfileSettingsDialogBase + perfectForwardSecurityToggled() + + + MtuCheckbox + toggled(bool) + AdvancedProfileSettingsDialogBase + mtuToggled() + + + IkeGroupCheckbox + toggled(bool) + AdvancedProfileSettingsDialogBase + IkeGroupToggled() + + + SingleDesCheckbox + toggled(bool) + AdvancedProfileSettingsDialogBase + singleDesToggled() + + + LocalPortCheckbox + toggled(bool) + AdvancedProfileSettingsDialogBase + localPortToggled() + + + + advancedSettingsToggled() + domainNameToggled() + applicationVersionToggled() + IkeGroupToggled() + perfectForwardSecurityToggled() + singleDesToggled() + helpClicked() + localPortToggled() + udpPortToggled() + useDnsServerToggled() + useUdpToggled() + setDefaultRouteToggled() + mtuToggled() + + + + klineedit.h + klineedit.h + klineedit.h + kcombobox.h + kcombobox.h + + diff --git a/src/advancedsettingsdialog.cpp b/src/advancedsettingsdialog.cpp new file mode 100644 index 0000000..866fc0f --- /dev/null +++ b/src/advancedsettingsdialog.cpp @@ -0,0 +1,219 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ + +//BEGIN includes +#include +#include +#include +#include +#include +#include +#include +#include "advancedsettingsdialog.h" +#include "toolinfo.h" +#include +//END includes + +AdvancedSettingsDialog::AdvancedSettingsDialog(QWidget *parent, const QString& caption, VpnAccountData *currentProfile, VpnAccountData::ConnectionType connectionType, KVpncConfig *GlobalConfig) : KDialogBase( parent, "Advanced_settings", true, caption, KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, true ) +{ + main = new AdvancedProfileDialogBase(this); + setMainWidget(main); + main->setMinimumSize(main->sizeHint()); + + this->currentProfile = currentProfile; + this->connectionType = connectionType; + + connect (main->AdvancedSettingsCheckbox, SIGNAL(toggled(bool)),this, SLOT(advancedSettingsToggled(bool))); + connect (main->ApplicationVersionCheckbox, SIGNAL(toggled(bool)),this, SLOT(applicationVersionToggled(bool))); + connect (main->PerfectForwardSecurityCheckbox, SIGNAL(toggled(bool)),this, SLOT(perfectForwardSecurityToggled(bool))); + connect (main->IkeGroupCheckbox, SIGNAL(toggled(bool)),this, SLOT(IkeGroupToggled(bool))); + connect (main->SingleDesCheckbox, SIGNAL(toggled(bool)),this, SLOT(singleDesToggled(bool))); + + main->IkeGroupCheckbox->setEnabled( false ); + main->PerfectForwardSecrecyCombobox->setEnabled( false ); + main->SingleDesCheckbox->setEnabled( false ); + main->ApplicationVersionLineedit->setEnabled( false ); + main->PerfectForwardSecurityCheckbox->setEnabled( false ); + main->IkeGroupCombobox->setEnabled( false ); + main->ApplicationVersionCheckbox->setEnabled( false ); + main->IkeGroupCombobox->setEnabled( false ); + + QString vpnc_version=""; + ToolInfo *tool; + for ( tool = GlobalConfig->ToolList->first(); tool; tool = GlobalConfig->ToolList->next() ) + { + // std::cout << "tool: " << tool->Name << std::endl; + // std::cout << "Version: " << tool->Version << std::endl; + // std::cout << "Path: " << tool->PathToExec << std::endl << std::endl; + if (tool->Name == "vpnc" ) + { + vpnc_version=tool->Version; + break; + } + } + + + + if (currentProfile->getConnectionType() == VpnAccountData::ConnectionType(VpnAccountData::cisco)) + { + //main->PerfectForwardSecrecyCombobox->setEnabled( false ); + main->PerfectForwardSecrecyCombobox->clear(); + main->PerfectForwardSecrecyCombobox->insertItem( "server" ); + main->PerfectForwardSecrecyCombobox->insertItem( "nopfs" ); + main->PerfectForwardSecrecyCombobox->insertItem( "dh1" ); + main->PerfectForwardSecrecyCombobox->insertItem( "dh2" ); + main->PerfectForwardSecrecyCombobox->insertItem( "dh5"); + + //main->IkeGroupCombobox->setEnabled( false ); + main->IkeGroupCombobox->clear(); + main->IkeGroupCombobox->insertItem( "dh1"); + main->IkeGroupCombobox->insertItem( "dh2"); + main->IkeGroupCombobox->insertItem( "dh5"); + } + else if (currentProfile->getConnectionType() == VpnAccountData::ConnectionType(VpnAccountData::racoon)) + { + //main->PerfectForwardSecrecyCombobox->setEnabled( false ); + main->PerfectForwardSecrecyCombobox->clear(); + main->PerfectForwardSecrecyCombobox->insertItem( "dh1" ); + main->PerfectForwardSecrecyCombobox->insertItem( "dh2" ); + main->PerfectForwardSecrecyCombobox->insertItem( "dh5" ); + main->PerfectForwardSecrecyCombobox->insertItem( "dh14" ); + main->PerfectForwardSecrecyCombobox->insertItem( "dh15" ); + main->PerfectForwardSecrecyCombobox->insertItem( "dh16" ); + main->PerfectForwardSecrecyCombobox->insertItem( "dh17" ); + main->PerfectForwardSecrecyCombobox->insertItem( "dh18" ); + + + main->IkeGroupCheckbox->setEnabled( false ); + main->IkeGroupCombobox->clear(); + main->IkeGroupCombobox->insertItem( "dh1" ); + main->IkeGroupCombobox->insertItem( "dh2" ); + main->IkeGroupCombobox->insertItem( "dh5" ); + main->IkeGroupCombobox->insertItem( "dh1" ); + main->IkeGroupCombobox->insertItem( "dh2" ); + main->IkeGroupCombobox->insertItem( "dh5" ); + main->IkeGroupCombobox->insertItem( "dh14" ); + main->IkeGroupCombobox->insertItem( "dh15" ); + main->IkeGroupCombobox->insertItem( "dh16" ); + main->IkeGroupCombobox->insertItem( "dh17" ); + main->IkeGroupCombobox->insertItem( "dh18" ); + } + + main->ApplicationVersionLineedit->setText( "Cisco Systems VPN Client "+vpnc_version+":Linux" ); + + main->AdvancedSettingsCheckbox->setChecked(currentProfile->getUseAdvancedSettings()); + this->advancedSettingsToggled(true); +} + +AdvancedSettingsDialog::~AdvancedSettingsDialog() +{ + delete main; +} + +void AdvancedSettingsDialog::advancedSettingsToggled(bool) +{ + main->IkeGroupCheckbox->setEnabled( false ); + main->PerfectForwardSecrecyCombobox->setEnabled( false ); + main->SingleDesCheckbox->setEnabled( false ); + main->ApplicationVersionLineedit->setEnabled( false ); + main->PerfectForwardSecurityCheckbox->setEnabled( false ); + main->IkeGroupCombobox->setEnabled( false ); + main->ApplicationVersionCheckbox->setEnabled( false ); + + if ( this->main->AdvancedSettingsCheckbox->isChecked() ) + { + main->groupBox3->setEnabled(true); + if (connectionType == VpnAccountData::ConnectionType(VpnAccountData::cisco)) + { + //if (currentProfile->getUseAdvancedSettings()) + //{ + main->SingleDesCheckbox->setEnabled( true ); + main->PerfectForwardSecurityCheckbox->setEnabled( true ); + main->ApplicationVersionCheckbox->setEnabled( true ); + main->PerfectForwardSecurityCheckbox->setEnabled ( true ); + main->IkeGroupCheckbox->setEnabled ( true ); + + } + else if (connectionType == VpnAccountData::ConnectionType(VpnAccountData::racoon)) + { + + //main->PerfectForwardSecrecyCombobox->setEnabled( false ); + main->SingleDesCheckbox->setEnabled( false ); + main->ApplicationVersionLineedit->setEnabled( false ); + main->PerfectForwardSecurityCheckbox->setEnabled( true ); + main->IkeGroupCombobox->setEnabled( false ); + main->ApplicationVersionCheckbox->setEnabled( false ); + main->IkeGroupCheckbox->setEnabled( true ); + } + + } + + else + { + main->groupBox3->setEnabled(false); + } +} + +void AdvancedSettingsDialog::applicationVersionToggled(bool) +{ + if ( main->ApplicationVersionCheckbox->isChecked() ) + main->ApplicationVersionLineedit->setEnabled( true ); + else + main->ApplicationVersionLineedit->setEnabled( false ); +} + +void AdvancedSettingsDialog::IkeGroupToggled(bool) +{ + if ( main->IkeGroupCheckbox->isChecked() ) + main->IkeGroupCombobox->setEnabled( true ); + else + main->IkeGroupCombobox->setEnabled( false ); +} + +void AdvancedSettingsDialog::perfectForwardSecurityToggled(bool) +{ + if ( main->PerfectForwardSecurityCheckbox->isChecked() ) + main->PerfectForwardSecrecyCombobox->setEnabled( true ); + else + main->PerfectForwardSecrecyCombobox->setEnabled( false ); +} + +void AdvancedSettingsDialog::singleDesToggled(bool) +{} + +void AdvancedSettingsDialog::helpClicked() +{} + + +void AdvancedSettingsDialog::accept() +{ + currentProfile->setUseAdvancedSettings( this->main->AdvancedSettingsCheckbox->isChecked() ); + currentProfile->setApplicationVersion( this->main->ApplicationVersionLineedit->text() ); + currentProfile->setUseApplicationVersion( this->main->ApplicationVersionCheckbox->isChecked() ); + currentProfile->setIkeGroup( this->main->IkeGroupCombobox->currentText() ); + currentProfile->setUseIkeGroup( this->main->IkeGroupCheckbox->isChecked() ); + currentProfile->setPerfectForwardSecrety( this->main->PerfectForwardSecrecyCombobox->currentText() ); + currentProfile->setUsePerfectForwardSecrety( this->main->PerfectForwardSecurityCheckbox->isChecked() ); + currentProfile->setUseSingleDes( this->main->SingleDesCheckbox->isChecked() ); + + QDialog::accept(); +} + +#include "advancedsettingsdialog.moc" diff --git a/src/advancedsettingsdialog.h b/src/advancedsettingsdialog.h new file mode 100644 index 0000000..b98c940 --- /dev/null +++ b/src/advancedsettingsdialog.h @@ -0,0 +1,56 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef ADVANCEDSETTINGSDIALOG_H +#define ADVANCEDSETTINGSDIALOG_H + +#include "advancedprofiledialogbase.h" +#include +#include "vpnaccountdata.h" +#include "kvpncconfig.h" + +/** +@author Christoph Thielecke +*/ +class AdvancedSettingsDialog : public KDialogBase { +Q_OBJECT +public: + AdvancedSettingsDialog(QWidget *parent, const QString& caption, VpnAccountData *currentProfile, VpnAccountData::ConnectionType connectionType, KVpncConfig *GlobalConfig); + ~AdvancedSettingsDialog(); + VpnAccountData::ConnectionType connectionType; + +protected slots: + void advancedSettingsToggled(bool); + void applicationVersionToggled(bool); + void IkeGroupToggled(bool); + void perfectForwardSecurityToggled(bool); + void singleDesToggled(bool); + void helpClicked(); + void accept(); + + +private: + VpnAccountData *currentProfile; + +public: + AdvancedProfileDialogBase *main; + +}; + +#endif diff --git a/src/ciscocertificateenrollment.cpp b/src/ciscocertificateenrollment.cpp new file mode 100644 index 0000000..bb1d54c --- /dev/null +++ b/src/ciscocertificateenrollment.cpp @@ -0,0 +1,742 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +//BEGIN INCLUDES +#include "ciscocertificateenrollment.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "utils.h" +//END INCLUDES + +CiscoCertificateEnrollment::CiscoCertificateEnrollment ( QWidget *, const char*, KVpncConfig *GlobalConfig ) +{ + this->GlobalConfig = GlobalConfig; + valuesOk=true; + type=""; + CA=""; + CaUrl=""; + ChallengePassword=""; + CaDomain=""; + FileEncoding=""; + FilenameURL=""; + Ip=""; + State=""; + Department=""; + Company=""; + Domain=""; + Name=""; + Email=""; + Country=""; + + success=0; + successmsg=""; + EnrollmentProcess=0; + + setupPages(); +} + +CiscoCertificateEnrollment::~CiscoCertificateEnrollment() +{ + delete selectionpage; + delete datapage; +} + +void CiscoCertificateEnrollment::accept() +{ + finished=true; + QWizard::accept(); +} + +void CiscoCertificateEnrollment::canAccept() +{ + + + + QDialog::accept(); +} + +void CiscoCertificateEnrollment::reject() +{ + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Enrollment break requested, user cancel" ), GlobalConfig->debug ); + + if ( EnrollmentProcess != 0 && EnrollmentProcess->isRunning() ) + { + EnrollmentProcess->tryTerminate(); + QTimer::singleShot ( 2000, EnrollmentProcess, SLOT ( kill() ) ); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "process %1 killed" ).arg ( "cisco_cert_mgr" ), GlobalConfig->debug ); + } + finished = false; + QWizard::reject(); +} + +void CiscoCertificateEnrollment::setupPages() +{ + GlobalConfig->appPointer->setOverrideCursor( QCursor(Qt::WaitCursor) ); + selectionpage = new CiscoCertificateEnrollmentBase ( 0 ); + selectionpage->sizeHint(); + addPage ( selectionpage, "" + i18n ( "Select enrollment type..." ) + "" ); + + connect ( selectionpage->FileEnrollementRadioButton, SIGNAL ( toggled ( bool ) ), this, SLOT ( enrollmentToggled ( bool ) ) ); + connect ( selectionpage->OnlineEnrollementRadioButton, SIGNAL ( toggled ( bool ) ), this, SLOT ( enrollmentToggled ( bool ) ) ); + + GlobalConfig->slotStatusMsg(i18n("Collecting cisco CA certs from Cisco certificate store..."), ID_STATUS_MSG); + if (GlobalConfig->KvpncDebugLevel > 2) + GlobalConfig->appendLogEntry(i18n("Looking for CA certs in Cisco certificate store..."), GlobalConfig->debug); + QStringList CiscoCaCerts = Utils(GlobalConfig).getCertsFromCiscoCertStore("ca"); + if (GlobalConfig->KvpncDebugLevel > 2) + GlobalConfig->appendLogEntry(i18n("Done."), GlobalConfig->debug); + + GlobalConfig->slotStatusMsg(i18n("Done."), ID_FLASH_MSG); + GlobalConfig->slotStatusMsg(i18n("Ready."), ID_STATUS_MSG); + + for ( QStringList::Iterator it = CiscoCaCerts.begin(); it != CiscoCaCerts.end(); ++it ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + std::cout << "insert item (cisco ca certs): " << QString ( *it ) << std::endl; + selectionpage->CAComboBox->insertItem ( *it ); + } + + datapage = new CiscoCertificateEnrollmentDataDialog ( 0, "datapage",GlobalConfig ); + datapage->sizeHint(); + addPage ( datapage, "" + i18n ( "Enter certificate data..." ) + "" ); + + finishpage = new CiscoCertificateEnrollmentFinishWidgetBase ( 0 ); + finishpage->sizeHint(); + addPage ( finishpage, "" + i18n ( "Finish" ) + "" ); + GlobalConfig->appPointer->restoreOverrideCursor(); + +} + +void CiscoCertificateEnrollment::next () +{ + // called at each finish of a page + bool ok = true; + QString msg = i18n ( "Please fill in all fields!" ); + msg = i18n ( "These fields must be filled in:\n" ); + if ( currentpage == selectionpage ) + { + if ( selectionpage->FileEnrollementRadioButton->isChecked() ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Enrollment type: %1" ).arg ( i18n ( "File" ) ), KVpncConfig::debug ); + type="file"; + + if ( selectionpage->FilenameURLRequester->url().isEmpty() ) + { + ok = false; + msg += "- " + i18n ( "Filename" ) + "\n"; + GlobalConfig->appendLogEntry ( i18n ( "Filename is empty!" ), GlobalConfig->error ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Filename: %1" ).arg ( selectionpage->FilenameURLRequester->url() ), KVpncConfig::debug ); + FilenameURL = selectionpage->FilenameURLRequester->url(); + } + + if ( selectionpage->NewPasswordPasswordEdit->text().isEmpty() ) + { + ok = false; + msg += "- " + i18n ( "Password" ) + "\n"; + GlobalConfig->appendLogEntry ( i18n ( "Password is empty!" ), GlobalConfig->error ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 && GlobalConfig->KvpncDebugLevel < 4 ) + GlobalConfig->appendLogEntry ( i18n ( "Password: %1" ).arg ( "******" ), KVpncConfig::debug ); + + else if ( GlobalConfig->KvpncDebugLevel > 4 ) + GlobalConfig->appendLogEntry ( i18n ( "Password (cleartext): %1" ).arg ( selectionpage->NewPasswordPasswordEdit->password() ), KVpncConfig::debug ); + ChallengePassword =QString(selectionpage->NewPasswordPasswordEdit->password()); + } + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File encoding: %1" ).arg ( selectionpage->FileEncodingComboBox->currentText() ), KVpncConfig::debug ); + FileEncoding = selectionpage->FileEncodingComboBox->currentText(); + } + if ( selectionpage->OnlineEnrollementRadioButton->isChecked() ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Enrollment type: %1" ).arg ( i18n ( "Online" ) ), KVpncConfig::debug ); + type="online"; + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "CA: %1" ).arg ( selectionpage->CAComboBox->currentText() ), KVpncConfig::debug ); + CA = selectionpage->CAComboBox->currentText(); + + if ( selectionpage->CaUrlLineEdit->text().isEmpty() ) + { + ok = false; + msg += "- " + i18n ( "CA URL" ) + "\n"; + GlobalConfig->appendLogEntry ( i18n ( "CA URL is empty!" ), GlobalConfig->error ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "CA URL: %1" ).arg ( selectionpage->CaUrlLineEdit->text() ), KVpncConfig::debug ); + CaUrl = selectionpage->CaUrlLineEdit->text(); + } + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "CA domain: %1" ).arg ( selectionpage->CaDomainLineEdit->text() ), KVpncConfig::debug ); + CaDomain = selectionpage->CaDomainLineEdit->text(); + + if ( selectionpage->ChallengePasswordPasswordEdit->text().isEmpty() ) + { + ok = false; + msg += "- " + i18n ( "Challenge password" ) + "\n"; + GlobalConfig->appendLogEntry ( i18n ( "Challenge password is empty!" ), GlobalConfig->error ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 && GlobalConfig->KvpncDebugLevel < 4 ) + GlobalConfig->appendLogEntry ( i18n ( "Challenge password: %1" ).arg ( "*****" ), KVpncConfig::debug ); + + else if ( GlobalConfig->KvpncDebugLevel > 4 ) + GlobalConfig->appendLogEntry ( i18n ( "Challenge password (cleartext): %1" ).arg ( selectionpage->ChallengePasswordPasswordEdit->password() ), KVpncConfig::debug ); + ChallengePassword =QString(selectionpage->ChallengePasswordPasswordEdit->password()); + } + + } + } + + if ( currentpage == datapage ) + { + if ( datapage->NameLineEdit->text().isEmpty() ) + { + ok = false; + msg += "- " + i18n ( "Name" ) + "\n"; + GlobalConfig->appendLogEntry ( i18n ( "Name is empty!" ), GlobalConfig->error ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Name: %1" ).arg ( datapage->NameLineEdit->text() ), KVpncConfig::debug ); + Name = datapage->NameLineEdit->text(); + } + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "IP address: %1" ).arg ( datapage->IpLineEdit->text() ), KVpncConfig::debug ); + Ip = datapage->IpLineEdit->text(); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "State: %1" ).arg ( datapage->StateLineEdit->text() ), KVpncConfig::debug ); + State = datapage->StateLineEdit->text(); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Department: %1" ).arg ( datapage->DepartmentLineEdit->text() ), KVpncConfig::debug ); + Department = datapage->DepartmentLineEdit->text(); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Company: %1" ).arg ( datapage->CompanyLineEdit->text() ), KVpncConfig::debug ); + Company = datapage->CompanyLineEdit->text(); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Domain: %1" ).arg ( datapage->DomainLineEdit->text() ), KVpncConfig::debug ); + Domain = datapage->DomainLineEdit->text(); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Email: %1" ).arg ( datapage->EmailLineEdit->text() ), KVpncConfig::debug ); + Email = datapage->EmailLineEdit->text(); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Country: %1" ).arg ( datapage->CountryLineEdit->text() ), KVpncConfig::debug ); + Country = datapage->CountryLineEdit->text(); + + + // now do the work + successmsg =i18n ( "Enrollment was sucessful." ); + success=0; + QString bin="cisco_cert_mgr"; + ToolInfo *tool; + //std::cout << "Tool (bin): " << bin << std::endl; + if ( !GlobalConfig->ToolList->isEmpty() ) + { + for ( tool = GlobalConfig->ToolList->first(); tool; tool = GlobalConfig->ToolList->next() ) + { + if ( bin == tool->Name ) + { + if ( tool->PathToExec.section ( '/',-1 ) != bin ) + { + // program is NOT installed + KMessageBox::information ( this, i18n ( "The required tool (%1) is not installed, please install it before you are connecting and restart kvpnc." ).arg ( bin ), i18n ( "Tool Missing" ) ); + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } + break; + } + } + } + + + GlobalConfig->appPointer->setOverrideCursor ( QCursor ( Qt::WaitCursor ) ); + + env = new QStringList(); + *env << "LC_ALL=C" << "LANG=C" << "PATH=/bin:/usr/bin:/usr/sbin:/sbin"; + + EnrollmentProcess = new QProcess ( this ); + EnrollmentProcess->addArgument ( GlobalConfig->pathToCiscoCertMgr ); + + if ( type == "file" ) + { + EnrollmentProcess->addArgument ( "-U" ); + EnrollmentProcess->addArgument ( "-op" ); + EnrollmentProcess->addArgument ( "enroll_file" ); + EnrollmentProcess->addArgument ( "-f" ); + EnrollmentProcess->addArgument ( FilenameURL ); + EnrollmentProcess->addArgument ( "-cn" ); + EnrollmentProcess->addArgument ( Name ); + EnrollmentProcess->addArgument ( "-enc" ); + EnrollmentProcess->addArgument ( FileEncoding ); + } + + if ( type == "online" ) + { + EnrollmentProcess->addArgument ( "-U" ); + EnrollmentProcess->addArgument ( "-op" ); + EnrollmentProcess->addArgument ( "enroll" ); + EnrollmentProcess->addArgument ( "-cn" ); + EnrollmentProcess->addArgument ( Name ); + EnrollmentProcess->addArgument ( "-caurl" ); + EnrollmentProcess->addArgument ( CaUrl ); + EnrollmentProcess->addArgument ( "-cadn" ); + EnrollmentProcess->addArgument ( CaDomain ); + + if ( !Department.isEmpty() ) + { + EnrollmentProcess->addArgument ( "-ou" ); + EnrollmentProcess->addArgument ( Department ); + } + + if ( !State.isEmpty() ) + { + EnrollmentProcess->addArgument ( "-st" ); + EnrollmentProcess->addArgument ( State ); + } + if ( !Company.isEmpty() ) + { + EnrollmentProcess->addArgument ( "-o" ); + EnrollmentProcess->addArgument ( Company ); + } + if ( !Domain.isEmpty() ) + { + EnrollmentProcess->addArgument ( "-dn" ); + EnrollmentProcess->addArgument ( Domain ); + } + if ( !Email.isEmpty() ) + { + EnrollmentProcess->addArgument ( "-e" ); + EnrollmentProcess->addArgument ( Email ); + } + if ( !Country.isEmpty() ) + { + EnrollmentProcess->addArgument ( "-c" ); + EnrollmentProcess->addArgument ( Country ); + } + if ( !Ip.isEmpty() ) + { + EnrollmentProcess->addArgument ( "-ip" ); + EnrollmentProcess->addArgument ( Ip ); + } + + + } + + connect ( EnrollmentProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout() ) ); + connect ( EnrollmentProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr() ) ); + connect ( EnrollmentProcess, SIGNAL ( processExited()) , this, SLOT(enrollmentProcessFinished())); + +// if ( GlobalConfig->KvpncDebugLevel > 3 ) + { + QString args = ""; + QStringList list = EnrollmentProcess->arguments(); + QStringList::Iterator it2 = list.begin(); + while ( it2 != list.end() ) + { + args += QString ( " " + *it2 ) ; + ++it2; + } + + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "EnrollmentProcess args: " )+EnrollmentProcess->arguments().join (" "), GlobalConfig->debug ); + } + + if ( !EnrollmentProcess->start ( env ) ) + { + KMessageBox::sorry ( this, i18n ( "Unable to start process (%1)!" ).arg ( "cisco_cert_mgr" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Unable to start process (%1)!" ).arg ( "cisco_cert_mgr" ), KVpncConfig::error ); + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Process %1 started." ).arg ( "cisco_cert_mgr" ), KVpncConfig::debug ); + + ProgressDlg = new KProgressDialog ( 0, "enrollmentprogress", i18n ( "Enrollment progress" ), i18n ( "Certificate enrollment..." ), true ); + ProgressDlg->progressBar()->setTotalSteps ( 100 ); + ProgressDlg->setAllowCancel ( true ); + ProgressDlg->show(); + ProgressDlg->resize ( ProgressDlg->width() +100,ProgressDlg->height() ); + + connect ( &CheckEnrollmentTimer, SIGNAL ( timeout() ), this, SLOT ( checkProgress() ) ); + CheckEnrollmentTimer.start ( 500, FALSE ); + + // we stupid have to send the password :( +// EnrollmentProcess->writeToStdin ( ChallengePassword + "\n" ); + +// if ( GlobalConfig->KvpncDebugLevel > 4 ) +// GlobalConfig->appendLogEntry ( i18n ( "Send challenge password: %1" ).arg (selectionpage->ChallengePasswordPasswordEdit->text() ), KVpncConfig::debug ); + + + + if ( ProgressDlg!= 0 ) + ProgressDlg->progressBar()->setValue ( 33 ); + + } + + + } + + if ( currentpage == finishpage ) + { + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Enrollment finished: %1." ).arg ( successmsg ), KVpncConfig::debug ); + } + + + if ( ok ) + { + previouspage = currentpage; + QWizard::next(); + } + else + { + KMessageBox::error ( this, msg ); + } +} + +void CiscoCertificateEnrollment::back() +{ + /* + currentpage=previouspage; + // showPage(previouspage); + + if ( currentpage == page1 ) + { + // nothing here + } + + + */ + QWizard::back(); +} + +void CiscoCertificateEnrollment::showPage ( QWidget* page ) +{ + currentpage = page; + QWizard::showPage ( page ); + + + // FIXME set currentpage at back() + //backButton()->setEnabled(false); + + helpButton() ->setEnabled ( false ); + + if ( page == finishpage ) + { + finishpage->SucessTextLabel->setText(successmsg); + } +} + +void CiscoCertificateEnrollment::enrollmentProcessFinished() +{ + disconnect ( EnrollmentProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout() ) ); + disconnect ( EnrollmentProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr() ) ); + disconnect ( EnrollmentProcess, SIGNAL ( processExited()) , this, SLOT(enrollmentProcessFinished())); + if ( ProgressDlg!= 0 ) + ProgressDlg->progressBar()->setValue ( 100 ); + GlobalConfig->appPointer->restoreOverrideCursor(); + finishpage->SucessTextLabel->setText ( successmsg ); + finishButton() ->setEnabled ( TRUE ); + finishButton() ->setFocus(); + ProgressDlg->hide(); +// delete ProgressDlg; +// delete EnrollmentProcess; +} + +void CiscoCertificateEnrollment::enrollmentToggled ( bool ) +{ + if ( selectionpage->FileEnrollementRadioButton->isChecked() ) + { + selectionpage->CaTextLabel->setEnabled ( false ); + selectionpage->CAComboBox->setEnabled ( false ); + selectionpage->CaUrlLineEdit->setEnabled ( false ); + selectionpage->CaUrlTextLabel->setEnabled ( false ); + selectionpage->ChallengePasswordTextLabel->setEnabled ( false ); + selectionpage->ChallengePasswordPasswordEdit->setEnabled ( false ); + selectionpage->CaDomainTextLabel->setEnabled ( false ); + selectionpage->CaDomainLineEdit->setEnabled ( false ); + + selectionpage->FilenameTextLabel->setEnabled ( true ); + selectionpage->FilenameURLRequester->setEnabled ( true ); + selectionpage->FileEncodingComboBox->setEnabled ( true ); + selectionpage->FileEncodingTextLabel->setEnabled ( true ); + selectionpage->FileEncodingComboBox->setEnabled ( true ); + selectionpage->NewPasswordTextLabel->setEnabled ( true ); + selectionpage->NewPasswordPasswordEdit->setEnabled ( true ); + } + if ( selectionpage->OnlineEnrollementRadioButton->isChecked() ) + { + selectionpage->CaTextLabel->setEnabled ( true ); + selectionpage->CAComboBox->setEnabled ( true ); + selectionpage->CaUrlTextLabel->setEnabled ( true ); + selectionpage->CaUrlLineEdit->setEnabled ( true ); + selectionpage->ChallengePasswordTextLabel->setEnabled ( true ); + selectionpage->ChallengePasswordPasswordEdit->setEnabled ( true ); + selectionpage->CaDomainTextLabel->setEnabled ( true ); + selectionpage->CaDomainLineEdit->setEnabled ( true ); + + selectionpage->FileEncodingComboBox->setEnabled ( false ); + selectionpage->FilenameTextLabel->setEnabled ( false ); + selectionpage->FilenameURLRequester->setEnabled ( false ); + selectionpage->FileEncodingTextLabel->setEnabled ( false ); + selectionpage->FileEncodingComboBox->setEnabled ( false ); + selectionpage->NewPasswordTextLabel->setEnabled ( false ); + selectionpage->NewPasswordPasswordEdit->setEnabled ( false ); + } +} + +void CiscoCertificateEnrollment::readFromStdout() +{ + + QString line2 = QString( EnrollmentProcess->readStdout() ); + QStringList lines = QStringList::split( '\n', line2 ); + for ( QStringList::Iterator it = lines.begin(); it != lines.end(); ++it ) +// while ( EnrollmentProcess->canReadLineStdout() ) + { +// QString line = QString ( EnrollmentProcess->readLineStdout() ); + QString line = *it; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( "[cisco_cert_mgr raw] "+line,GlobalConfig->debug ); + + + if ( line.find ( "Password:" , 0, FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Certificate enrollment: %1 was requested, send it..." ).arg ( i18n ( " challenge password" ) ),GlobalConfig->debug ); + + EnrollmentProcess->writeToStdin ( ChallengePassword + "\n" ); + if ( GlobalConfig->KvpncDebugLevel > 4 ) + GlobalConfig->appendLogEntry ( i18n ( "Send challenge password: %1" ).arg ( ChallengePassword ), KVpncConfig::debug ); + } + + if ( line.find ( "Request Pending." , 0, FALSE ) > -1 ) + { + if ( ProgressDlg!= 0 ) + ProgressDlg->progressBar()->setValue ( 66 ); + GlobalConfig->appendLogEntry ( i18n ( "Certificate enrollment: request sent to CA, waiting for grant..." ) ,GlobalConfig->info ); + } + if ( line.find ( "contacting certificate authority." , 0, FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( i18n ( "Certificate enrollment: contacting CA..." ) ,GlobalConfig->info ); + } + + + if ( line.find ( "Success: certificate enrollment completed with no errors." , 0, FALSE ) > -1 ) + { + if ( ProgressDlg!= 0 ) + ProgressDlg->progressBar()->setValue ( 99 ); + if (success==0) + { + GlobalConfig->appendLogEntry ( i18n ( "Certificate enrollment: enrollment was successful." ) ,GlobalConfig->info ); + success=0; + successmsg="The enrollment was successful. The CA has granted the request. The user and CA certificates are imported."; + } + } + + } +} + +void CiscoCertificateEnrollment::readFromStderr() +{ + QString line2 = QString( EnrollmentProcess->readStderr() ); + QStringList lines = QStringList::split( '\n', line2 ); + for ( QStringList::Iterator it = lines.begin(); it != lines.end(); ++it ) +// while ( EnrollmentProcess->canReadLineStderr() ) + { +// QString line = QString ( EnrollmentProcess->readLineStderr() ); + QString line = *it; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( "[cisco_cert_mgr err raw] "+line,GlobalConfig->debug ); + + if ( line.find ( "certificate enrollment failed." , 0, FALSE ) > -1 ) + { + + KMessageBox::error ( 0, i18n ( "Certificate enrollment: enrollment has been failed." ), i18n ( "Enrollment failed" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Certificate enrollment: enrollment has been failed." ),GlobalConfig->error ); + success=-1; + successmsg=i18n ( "Enrollment has been failed" ); +// GlobalConfig->appPointer->restoreOverrideCursor(); + + + } + } + +// sucess=-1; +} + +void CiscoCertificateEnrollment::checkProgress() +{ + if ( GlobalConfig->KvpncDebugLevel > 6 ) + GlobalConfig->appendLogEntry ( i18n ( "Enrollment timer event" ), GlobalConfig->debug ); + + + if ( ProgressDlg->wasCancelled () ) + { + // user has canceled the dlg, so we have to stop here + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Enrollment break requested, user cancel" ), GlobalConfig->debug ); + + CheckEnrollmentTimer.stop(); + + // kill process + disconnect ( EnrollmentProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout() ) ); + disconnect ( EnrollmentProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr() ) ); + if ( EnrollmentProcess->isRunning() ) + { + EnrollmentProcess->tryTerminate(); + QTimer::singleShot ( 2000, EnrollmentProcess, SLOT ( kill() ) ); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "process %1 killed" ).arg ( "cisco_cert_mgr" ), GlobalConfig->debug ); + } + + QStringList CiscoCertRequests = Utils ( GlobalConfig ).getCertsFromCiscoCertStore ( "enrollment" ); + if ( !CiscoCertRequests.isEmpty() ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "removing pending enrollment requests: %1" ).arg ( CiscoCertRequests.join ( ", " ) ), GlobalConfig->debug ); + + for ( int i=0; i< ( int ) CiscoCertRequests.count() ; i++ ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "delete enrollment request..." ), GlobalConfig->debug ); + + DeleteProcess = new QProcess ( 0 ); + DeleteProcess->addArgument ( GlobalConfig->pathToCiscoCertMgr ); + DeleteProcess->addArgument ( "-E" ); + DeleteProcess->addArgument ( "-op" ); + DeleteProcess->addArgument ( "delete" ); + DeleteProcess->addArgument ( "-ct" ); + DeleteProcess->addArgument ( 0 ); + connect ( DeleteProcess, SIGNAL ( processExited()) , this, SLOT(cancelProcessFinished())); + connect ( DeleteProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_cancel() ) ); + connect ( DeleteProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_cancel() ) ); + + if ( !DeleteProcess->start ( env ) ) + { + GlobalConfig->appendLogEntry ( i18n ( "Process (%1) could not started!" ).arg ( "cisco_cert_mgr" ),GlobalConfig->error ); +// KMessageBox::sorry ( this, i18n ( "Unable to start process (%1)!" ).arg ( "cisco_cert_mgr" ) ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Process (%1) started." ).arg ( "cisco_cert_mgr: delete" ),GlobalConfig->debug ); + + DeleteProcess->writeToStdin ( ChallengePassword + "\n" ); + if ( GlobalConfig->KvpncDebugLevel > 4 ) + GlobalConfig->appendLogEntry ( i18n ( "Send challenge password: %1" ).arg ( ChallengePassword ), KVpncConfig::debug ); + + while (DeleteProcess->isRunning()) + { + sleep(1); + } + } + disconnect ( DeleteProcess, SIGNAL ( processExited()) , this, SLOT(cancelProcessFinished())); + disconnect ( DeleteProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_cancel() ) ); + disconnect ( DeleteProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_cancel() ) ); + delete DeleteProcess; + DeleteProcess=0L; + + } + } + } + else + { + // nothing to do... + } + +} + +void CiscoCertificateEnrollment::cancelProcessFinished() +{ + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Process (%1) finished." ).arg ( "cisco_cert_mgr: delete" ),GlobalConfig->debug ); +// delete DeleteProcess; + successmsg=i18n ( "Request canceled." ); + success=-1; + finishpage->SucessTextLabel->setText ( successmsg ); + +} + +void CiscoCertificateEnrollment::readFromStdout_cancel() +{ + + QString line = QString( DeleteProcess->readStdout() ); +// while ( DeleteProcess->canReadLineStdout() ) +// { +// QString line = QString ( DeleteProcess->readLineStdout() ); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( "[cisco_cert_mgr raw] "+line,GlobalConfig->debug ); + +// } +} + +void CiscoCertificateEnrollment::readFromStderr_cancel() +{ + QString line = QString ( DeleteProcess->readStderr() ); +// while ( DeleteProcess->canReadLineStderr() ) +// { +// QString line = QString ( DeleteProcess->readLineStderr() ); + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( "[cisco_cert_mgr err raw] "+line,GlobalConfig->debug ); + +// } + +// sucess=-1; +} + + diff --git a/src/ciscocertificateenrollment.h b/src/ciscocertificateenrollment.h new file mode 100644 index 0000000..179627a --- /dev/null +++ b/src/ciscocertificateenrollment.h @@ -0,0 +1,104 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef CISCOCERTIFICATEENROLLMENT_H +#define CISCOCERTIFICATEENROLLMENT_H + +#include +#include "ciscocertificateenrollmentbase.h" +#include "ciscocertificateenrollmentfinishwidgetbase.h" +#include "ciscocertificateenrollmentdatadialog.h" +#include +#include +#include +#include +#include +#include +#include +#include "kvpncconfig.h" + +/** + @author Christoph Thielecke +*/ +class CiscoCertificateEnrollment : public QWizard +{ + Q_OBJECT + public: + CiscoCertificateEnrollment ( QWidget *parent, const char* caption, KVpncConfig *GlobalConfig ); + ~CiscoCertificateEnrollment(); + QProcess *EnrollmentProcess; + QProcess *DeleteProcess; + KVpncConfig *GlobalConfig; + bool done; + bool finished; + bool valuesOk; + QStringList *env; + + + public slots: + void accept(); + void canAccept(); + void enrollmentToggled(bool); + void setupPages(); + void showPage( QWidget* page ); + void next (); + void back(); + void reject(); + void readFromStdout(); + void readFromStderr(); + void readFromStdout_cancel(); + void readFromStderr_cancel(); + void checkProgress(); + void enrollmentProcessFinished(); + void cancelProcessFinished(); + + + public: + CiscoCertificateEnrollmentBase *selectionpage; + CiscoCertificateEnrollmentDataDialogBase *datapage; + CiscoCertificateEnrollmentFinishWidgetBase *finishpage; + QWidget* currentpage; // pointer to current page + QWidget* previouspage; //< pointer to previous page + KProgressDialog *ProgressDlg; + + public: + QString type; + QString successmsg; + int success; + QString CA; + QString CaUrl; + QString ChallengePassword; + QString CaDomain; + QString FileEncoding; + QString FilenameURL; + QString Ip; + QString State; + QString Department; + QString Company; + QString Domain; + QString Name; + QString Email; + QString Country; + + private: + QTimer CheckEnrollmentTimer; + +}; + +#endif diff --git a/src/ciscocertificateenrollmentbase.ui b/src/ciscocertificateenrollmentbase.ui new file mode 100644 index 0000000..45995a3 --- /dev/null +++ b/src/ciscocertificateenrollmentbase.ui @@ -0,0 +1,272 @@ + +CiscoCertificateEnrollmentBase + + + CiscoCertificateEnrollmentBase + + + + 0 + 0 + 529 + 368 + + + + Certificate enrollment + + + + unnamed + + + + layout71 + + + + unnamed + + + + textLabel8 + + + <b>Select your enrollment method:</b> + + + + + buttonGroup1 + + + Enrollment method + + + + unnamed + + + + ChallengePasswordPasswordEdit + + + + + FileEnrollementRadioButton + + + Fi&le + + + Alt+L + + + + + FilenameURLRequester + + + false + + + + + CAComboBox + + + + + NewPasswordTextLabel + + + false + + + New password: + + + + + spacer40 + + + Horizontal + + + Expanding + + + + 331 + 21 + + + + + + spacer41 + + + Horizontal + + + Expanding + + + + 331 + 21 + + + + + + ChallengePasswordTextLabel + + + Challenge password: + + + + + CaDomainTextLabel + + + CA domain: + + + + + CaUrlTextLabel + + + CA URL: + + + + + CaTextLabel + + + Certificate authority: + + + + + FileEncodingTextLabel + + + false + + + File encoding: + + + + + FilenameTextLabel + + + false + + + Filename: + + + + + CaUrlLineEdit + + + + + CaDomainLineEdit + + + + + + Binary + + + + + Base64 + + + + FileEncodingComboBox + + + false + + + + + OnlineEnrollementRadioButton + + + &Online + + + Alt+O + + + true + + + + + NewPasswordPasswordEdit + + + false + + + + + + + spacer46 + + + Vertical + + + Expanding + + + + 20 + 20 + + + + + + + + + OnlineEnrollementRadioButton + CAComboBox + CaUrlLineEdit + CaDomainLineEdit + ChallengePasswordPasswordEdit + FileEncodingComboBox + NewPasswordPasswordEdit + FilenameURLRequester + + + + kpassdlg.h + kurlrequester.h + klineedit.h + kpushbutton.h + kcombobox.h + klineedit.h + klineedit.h + kcombobox.h + kpassdlg.h + + diff --git a/src/ciscocertificateenrollmentdatadialog.cpp b/src/ciscocertificateenrollmentdatadialog.cpp new file mode 100644 index 0000000..3fbbd57 --- /dev/null +++ b/src/ciscocertificateenrollmentdatadialog.cpp @@ -0,0 +1,39 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "ciscocertificateenrollmentdatadialog.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +CiscoCertificateEnrollmentDataDialog::CiscoCertificateEnrollmentDataDialog(QWidget *parent, const char* caption, KVpncConfig *GlobalConfig) +{ +} + + +CiscoCertificateEnrollmentDataDialog::~CiscoCertificateEnrollmentDataDialog() +{ +} + diff --git a/src/ciscocertificateenrollmentdatadialog.h b/src/ciscocertificateenrollmentdatadialog.h new file mode 100644 index 0000000..b2c57c9 --- /dev/null +++ b/src/ciscocertificateenrollmentdatadialog.h @@ -0,0 +1,46 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef CISCOCERTIFICATEENROLLMENTDATADIALOG_H +#define CISCOCERTIFICATEENROLLMENTDATADIALOG_H + +#include +#include "ciscocertificateenrollmentdatadialogbase.h" +#include +#include +#include +#include +#include "kvpncconfig.h" + +/** + @author Christoph Thielecke +*/ +class CiscoCertificateEnrollmentDataDialog : public CiscoCertificateEnrollmentDataDialogBase +{ + public: + CiscoCertificateEnrollmentDataDialog(QWidget *parent, const char* caption, KVpncConfig *GlobalConfig); + + ~CiscoCertificateEnrollmentDataDialog(); + KVpncConfig *GlobalConfig; + + public: + +}; + +#endif diff --git a/src/ciscocertificateenrollmentdatadialogbase.ui b/src/ciscocertificateenrollmentdatadialogbase.ui new file mode 100644 index 0000000..cb3bbce --- /dev/null +++ b/src/ciscocertificateenrollmentdatadialogbase.ui @@ -0,0 +1,402 @@ + +CiscoCertificateEnrollmentDataDialogBase + + + CiscoCertificateEnrollmentDataDialogBase + + + + 0 + 0 + 440 + 320 + + + + Certificate details... + + + + unnamed + + + + layout73 + + + + unnamed + + + + layout72 + + + + unnamed + + + + layout69 + + + + unnamed + + + + textLabel12 + + + State (ST): + + + + + spacer53 + + + Horizontal + + + Expanding + + + + 51 + 21 + + + + + + + + layout65 + + + + unnamed + + + + textLabel15 + + + IP address: + + + + + spacer56 + + + Horizontal + + + Expanding + + + + 40 + 20 + + + + + + + + IpLineEdit + + + + + StateLineEdit + + + + + layout68 + + + + unnamed + + + + textLabel11 + + + Country (C): + + + + + spacer54 + + + Horizontal + + + Expanding + + + + 40 + 20 + + + + + + + + layout67 + + + + unnamed + + + + textLabel14 + + + Email (E): + + + + + spacer55 + + + Horizontal + + + Expanding + + + + 40 + 20 + + + + + + + + layout63 + + + + unnamed + + + + textLabel10 + + + Department (OU): + + + + + spacer51 + + + Horizontal + + + Expanding + + + + 31 + 21 + + + + + + + + DepartmentLineEdit + + + + + layout64 + + + + unnamed + + + + textLabel16 + + + Domain + + + + + spacer57 + + + Horizontal + + + Expanding + + + + 40 + 20 + + + + + + + + CompanyLineEdit + + + + + layout70 + + + + unnamed + + + + textLabel13 + + + Company: + + + + + spacer52 + + + Horizontal + + + Expanding + + + + 40 + 20 + + + + + + + + DomainLineEdit + + + + + NameLineEdit + + + + + EmailLineEdit + + + + + CountryLineEdit + + + + + layout62 + + + + unnamed + + + + textLabel9 + + + Name (CN): + + + + + spacer50 + + + Horizontal + + + Expanding + + + + 31 + 21 + + + + + + + + + + spacer65 + + + Vertical + + + Expanding + + + + 20 + 41 + + + + + + + + + NameLineEdit + DepartmentLineEdit + CompanyLineEdit + StateLineEdit + CountryLineEdit + EmailLineEdit + IpLineEdit + DomainLineEdit + + + + klineedit.h + klineedit.h + klineedit.h + klineedit.h + klineedit.h + klineedit.h + klineedit.h + klineedit.h + + diff --git a/src/ciscocertificateenrollmentfinishwidgetbase.ui b/src/ciscocertificateenrollmentfinishwidgetbase.ui new file mode 100644 index 0000000..3ec1b72 --- /dev/null +++ b/src/ciscocertificateenrollmentfinishwidgetbase.ui @@ -0,0 +1,33 @@ + +CiscoCertificateEnrollmentFinishWidgetBase + + + CiscoCertificateEnrollmentFinishWidgetBase + + + + 0 + 0 + 600 + 480 + + + + Finished + + + + unnamed + + + + SucessTextLabel + + + ok. + + + + + + diff --git a/src/ciscopasswddecoder.cpp b/src/ciscopasswddecoder.cpp new file mode 100644 index 0000000..f4d98bb --- /dev/null +++ b/src/ciscopasswddecoder.cpp @@ -0,0 +1,227 @@ +/*************************************************************************** +  *   Copyright (C) 2005 by hal9000                             * + *   Copyright (C) 2005 by Maurice Massar                             * + *   Copyright (C) 2005 by Christoph Thielecke                             * +  *                                                                         * +  *   This program is free software; you can redistribute it and/or modify  * +  *   it under the terms of the GNU General Public License as published by  * +  *   the Free Software Foundation; either version 2 of the License, or     * +  *   (at your option) any later version.                                   * +  *                                                                         * +  *   This program is distributed in the hope that it will be useful,       * +  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * +  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * +  *   GNU General Public License for more details.                          * +  *                                                                         * +  *   You should have received a copy of the GNU General Public License     * +  *   along with this program; if not, write to the                         * +  *   Free Software Foundation, Inc.,                                       * +  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             * +  ***************************************************************************/ +#include "ciscopasswddecoder.h" + +#include +#include +#include +#include + +CiscoPasswdDecoder::CiscoPasswdDecoder(QString& profileFile) +{ + profile = profileFile; +} + +CiscoPasswdDecoder::~CiscoPasswdDecoder() +{} + +/* read hex strings for "enc_GroupPwd" and "enc_UserPassword" from profile file */ +void CiscoPasswdDecoder::readProfileData(QString& profile, QString& userData, QString& groupData) +{ + QFile PcfFile(profile); + QTextStream stream ( &PcfFile ); + + if ( PcfFile.open(IO_ReadOnly)) + { + QString line = ""; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' and replace all white chars with one blank + if ( !line.startsWith("#") ) + { + if (line.startsWith("enc_GroupPwd") || line.startsWith("enc_GroupPwd") ) + groupData=line.section('=',1,1).stripWhiteSpace(); + if (line.startsWith("enc_UserPassword") || line.startsWith("enc_GroupPwd") ) + userData=line.section('=',1,1).stripWhiteSpace(); + } + } + PcfFile.close(); + } + else + { + KMessageBox::error ( 0, i18n ( "Reading of \"%1\" has been failed!" ).arg ( PcfFile.name() ) ); + } +} + +int CiscoPasswdDecoder::hex2bin_c(unsigned int c) +{ + if ((c >= '0')&&(c <= '9')) + return c - '0'; + if ((c >= 'A')&&(c <= 'F')) + return c - 'A' + 10; + if ((c >= 'a')&&(c <= 'f')) + return c - 'a' + 10; + return -1; +} + +int CiscoPasswdDecoder::hex2bin(QString str, QString& bin, int& len) +{ +QString p; + int i, l; + + for (i = 0; str[i] != '\0'; i++) + if (hex2bin_c(QChar(str[i]).unicode()) == -1) + return EINVAL; + + l = i; + if ((l & 1) != 0) + return EINVAL; + l /= 2; + + for (i = 0; i < l; i++) + p+= hex2bin_c(QChar(str[i*2]).unicode()) << 4 | hex2bin_c(QChar(str[i*2+1]).unicode()); + + bin = p; + if (len) + len = l; + + return 0; +} + +int CiscoPasswdDecoder::c_decrypt(QString ct, int len, char **resp, int reslenp) +{ + QString h1 = ct; + const char *h4 = ct.ascii() + 20; + const char *enc = ct.ascii() + 40; + + char ht[20], h2[20], h3[20], key[24]; + const char *iv = h1.ascii(); + char *res; + gcry_cipher_hd_t ctx; + int reslen; + + if (len < 48) + return 0; + len -= 40; + + memcpy(ht, h1.ascii(), 20); + + ht[19]++; + gcry_md_hash_buffer(GCRY_MD_SHA1, h2, ht, 20); + + ht[19] += 2; + gcry_md_hash_buffer(GCRY_MD_SHA1, h3, ht, 20); + + memcpy(key, h2, 20); + memcpy(key+20, h3, 4); + /* who cares about parity anyway? */ + + gcry_md_hash_buffer(GCRY_MD_SHA1, ht, enc, len); + + if (memcmp(h4, ht, 20) != 0) + return -1; + + res = (char *)malloc(len); + if (res == NULL) + return -1; + + gcry_cipher_open(&ctx, GCRY_CIPHER_3DES, GCRY_CIPHER_MODE_CBC, 0); + gcry_cipher_setkey(ctx, key, 24); + gcry_cipher_setiv(ctx, iv, 8); + gcry_cipher_decrypt(ctx, (unsigned char *)res, len, (unsigned char *)enc, len); + gcry_cipher_close(ctx); + + reslen = len - res[len-1]; + res[reslen] = '\0'; + + if (resp) + *resp = res; + + reslenp = reslen; + return 0; +} + +bool CiscoPasswdDecoder::decodePasswords(QString& userPasswd, QString& groupPasswd) +{ + QString encUserPasswd=""; + QString encGroupPasswd=""; + int i, len, ret = 0; + char *pw, *pw2; + QString bin,bin2; + int len2=0; + bool success=true; + + readProfileData(profile, encUserPasswd, encGroupPasswd); + + + if (!encGroupPasswd.isEmpty()) + { + ret = hex2bin( encGroupPasswd, bin, len); + + + if (ret != 0) + { + perror("error: groupPasswd: decoding input"); + success=false; + } + ret = c_decrypt(bin, len, &pw, 0); + + if (ret != 0) + { + perror("error: groupPasswd: decrypting input"); + success=false; + } + else + { +// printf("groupPasswd: %s\n", pw); +// std::cout << "groupPasswd: " << QString::fromLocal8Bit(pw) << std::endl; + + + groupPasswd = QString::fromLocal8Bit(pw); + //free(pw); + } + } + if (!encUserPasswd.isEmpty() ) + { + i=0; + len2=0; + ret = 0; + ret = hex2bin( encUserPasswd, bin2, len2); + + if (ret != 0) + { + perror("error: userPasswd: decoding input"); + success=false; + } + ret = c_decrypt(bin2, len2, &pw2, 0); + //free(bin2); + if (ret != 0) + { + perror("error: userPasswd: decrypting input"); + success=false; + } + else + { + +// // printf("userPasswd: %s\n", pw2); +// std::cout << "userPasswd " << QString::fromLocal8Bit(pw2) << std::endl; + userPasswd = QString::fromLocal8Bit(pw2); + + + //free(pw); + } + } + + + + return success; + +} diff --git a/src/ciscopasswddecoder.h b/src/ciscopasswddecoder.h new file mode 100644 index 0000000..f73f702 --- /dev/null +++ b/src/ciscopasswddecoder.h @@ -0,0 +1,56 @@ +/*************************************************************************** +* Copyright (C) 2005 by hal9000 * + * Copyright (C) 2005 by Maurice Massar * + * Copyright (C) 2005 by Christoph Thielecke * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#pragma once + +#include +#include +#include +#include +// #include + +#include +#include +#include +#include + +using namespace std; + +/* +* To get some .pcf file specifications, +* see Cisco VPN Client Administrator Guide +* chapter Preconfiguring the VPN Client for Remote Users +*/ +class CiscoPasswdDecoder +{ +public: + CiscoPasswdDecoder(QString& profileFile); + ~CiscoPasswdDecoder(); + bool decodePasswords(QString& userPasswd, QString& groupPasswd); + +private: + void readProfileData(QString& profile, QString& userData, QString& groupData); + QString profile; + + int hex2bin_c(unsigned int c); + int hex2bin(QString str, QString& bin, int& len); + int c_decrypt(QString ct, int len, char **resp, int reslenp); + +}; diff --git a/src/configconnectoptions.cpp b/src/configconnectoptions.cpp new file mode 100644 index 0000000..e0cddfe --- /dev/null +++ b/src/configconnectoptions.cpp @@ -0,0 +1,58 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "configconnectoptions.h" +#include +#include + +#include + +ConfigConnectOptions::ConfigConnectOptions(QWidget *parent) : ConfigConnectOptionsBase(parent) +{ + dialogModified=false; + + // connect changed signals to own signal + connect(AutoConnectProfileComboBox,SIGNAL(textChanged ( const QString & )),this,SIGNAL(changed())); + connect(checkMinimizeAfterConnectCheck,SIGNAL(stateChanged ( int )),this,SIGNAL(changed())); + connect(SilentQuitcheckBox,SIGNAL(stateChanged ( int )),this,SIGNAL(changed())); + connect(DoAutoConnectCheckBox,SIGNAL(stateChanged ( int )),this,SIGNAL(changed())); + + // connect changed to slot + connect(this,SIGNAL(changed ()),this,SLOT(dialogChanged())); +} + + +ConfigConnectOptions::~ConfigConnectOptions() +{} + + +void ConfigConnectOptions::autoConnectToggled(bool) +{ + if (DoAutoConnectCheckBox->isChecked()) + AutoConnectProfileComboBox->setEnabled(true); + else + AutoConnectProfileComboBox->setEnabled(false); +} + +void ConfigConnectOptions::dialogChanged() +{ +// std::cout << "ConfigConnectOptions::dialogChanged()" << std::endl; + dialogModified=true; +} + diff --git a/src/configconnectoptions.h b/src/configconnectoptions.h new file mode 100644 index 0000000..2d6fef0 --- /dev/null +++ b/src/configconnectoptions.h @@ -0,0 +1,48 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef CONFIGCONNECTOPTIONS_H +#define CONFIGCONNECTOPTIONS_H + +#include "configconnectoptionsbase.h" +#include + +/** +@author Christoph Thielecke +*/ +class ConfigConnectOptions : public ConfigConnectOptionsBase +{ +Q_OBJECT +public: + ConfigConnectOptions(QWidget *parent); + ~ConfigConnectOptions(); + bool dialogModified; + +public slots: + void autoConnectToggled(bool); + +private slots: + void dialogChanged(); + +signals: + void changed(); + +}; + +#endif diff --git a/src/configconnectoptionsbase.ui b/src/configconnectoptionsbase.ui new file mode 100644 index 0000000..ea6fe7b --- /dev/null +++ b/src/configconnectoptionsbase.ui @@ -0,0 +1,219 @@ + +ConfigConnectOptionsBase + + + ConfigConnectOptionsBase + + + + 0 + 0 + 414 + 155 + + + + Connect + + + + unnamed + + + + layout10 + + + + unnamed + + + + checkMinimizeAfterConnectCheck + + + + 1 + 0 + 0 + 0 + + + + &Minimize after connect + + + Alt+M + + + true + + + Hide main window after connect + + + Enable this to let kvpnc minimize in kicker after succesful connect. + + + + + spacer24 + + + Horizontal + + + Expanding + + + + 154 + 20 + + + + + + + + layout11 + + + + unnamed + + + + SilentQuitcheckBox + + + + 1 + 5 + 0 + 0 + + + + Use silent &quit + + + Alt+Q + + + Enable exit without warning +about the active connecions + + + + + spacer25 + + + Horizontal + + + Expanding + + + + 210 + 20 + + + + + + + + spacer6 + + + Vertical + + + Expanding + + + + 41 + 16 + + + + + + layout12 + + + + unnamed + + + + DoAutoConnectCheckBox + + + Au&tomatically connect at startup: + + + Alt+T + + + true + + + After startup initiate connection using selected profile + + + + + spacer24_2_2 + + + Horizontal + + + Expanding + + + + 59 + 20 + + + + + + AutoConnectProfileComboBox + + + Profile to connect at startup + + + + + + + + + DoAutoConnectCheckBox + toggled(bool) + ConfigConnectOptionsBase + autoConnectToggled(bool) + + + + SilentQuitcheckBox + checkMinimizeAfterConnectCheck + DoAutoConnectCheckBox + AutoConnectProfileComboBox + + + autoConnectToggled(bool) + + + + kcombobox.h + + diff --git a/src/configdaemonoptions.cpp b/src/configdaemonoptions.cpp new file mode 100644 index 0000000..6936021 --- /dev/null +++ b/src/configdaemonoptions.cpp @@ -0,0 +1,95 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ + +//BEGIN INCLUDES +#include + +#include "configdaemonoptions.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "widgetnotifyhelper.h" + +#include +//END INCLUDES + + +/* + * Constructs a ConfigDaemonOptions as a child of 'parent', with the + * name 'name' and widget flags set to 'f'. + */ +ConfigDaemonOptions::ConfigDaemonOptions( QWidget* parent) : ConfigDaemonOptionsBase( parent) +{ + WidgetNotifyHelper h; + h.setupChangedAction(this); + dialogModified=false; +} + +ConfigDaemonOptions::~ConfigDaemonOptions() +{ +} + + +void ConfigDaemonOptions::programsInPathToggled( bool ) +{ + if ( ProgramsInPathcheckBox->isChecked() ) + { + //spinVpncDebugLevel->setEnabled( false ); + VpncPathInput->setEnabled( false ); + FreeswanPathInput->setEnabled( false ); + //spinRacoonDebugLevel->setEnabled( false ); + RacoonPathInput->setEnabled( false ); + OpenvpnPathInput->setEnabled( false ); +// ConfigHelperProgramOptionsWidget->OpenSSLPathInput->setEnabled( false ); +// ConfigHelperProgramOptionsWidget->IptablesPathInput->setEnabled( false ); + PppdPathInput->setEnabled( false ); + } + else + { + //spinVpncDebugLevel->setEnabled( true ); + VpncPathInput->setEnabled( true ); + FreeswanPathInput->setEnabled( true ); + //spinRacoonDebugLevel->setEnabled( true ); + RacoonPathInput->setEnabled( true ); + OpenvpnPathInput->setEnabled( true ); +// ConfigHelperProgramOptionsWidget->OpenSSLPathInput->setEnabled( true ); +// ConfigHelperProgramOptionsWidget->IptablesPathInput->setEnabled( true ); + PppdPathInput->setEnabled( true ); + } +} + + +void ConfigDaemonOptions::dialogChanged() +{ +// std::cout << "ConfigDaemonOptions::dialogChanged()" << std::endl; + dialogModified=true; +} diff --git a/src/configdaemonoptions.h b/src/configdaemonoptions.h new file mode 100644 index 0000000..3f397e0 --- /dev/null +++ b/src/configdaemonoptions.h @@ -0,0 +1,46 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ + +#ifndef CONFIGDAEMONOPTIONS_H +#define CONFIGDAEMONOPTIONS_H + +#include "configdaemonoptionsbase.h" +#include + +class ConfigDaemonOptions : public ConfigDaemonOptionsBase +{ + Q_OBJECT + +public: + ConfigDaemonOptions( QWidget* parent); + ~ConfigDaemonOptions(); + bool dialogModified; + +public slots: + void programsInPathToggled(bool); + +private slots: + void dialogChanged(); + +signals: + void changed(); +}; + +#endif diff --git a/src/configdaemonoptionsbase.ui b/src/configdaemonoptionsbase.ui new file mode 100644 index 0000000..9e8f502 --- /dev/null +++ b/src/configdaemonoptionsbase.ui @@ -0,0 +1,2673 @@ + +ConfigDaemonOptionsBase + + + ConfigDaemonOptionsBase + + + + 0 + 0 + 639 + 1431 + + + + + 3 + 3 + 0 + 0 + + + + Daemon + + + + unnamed + + + + layout154 + + + + unnamed + + + + layout153 + + + + unnamed + + + + layout39 + + + + unnamed + + + + ProgramsInPathcheckBox + + + true + + + A&ll programs are in PATH + + + Alt+L + + + true + + + Search for programs on default places. <br>Uncheck only in non standard installations. + + + + + spacer34 + + + Horizontal + + + Expanding + + + + 71 + 31 + + + + + + ShowInterfaceIPinTooltipCheckBox + + + Sho&w tunnel IP in tooltip + + + Alt+W + + + Show retrieved IP address for tunnel in kvpnc icon tooltip + + + + + + + + + + groupBox7 + + + true + + + vpnc (free client of Cisco VPN concentrators) + + + + unnamed + + + + layout7 + + + + unnamed + + + + layout6 + + + + unnamed + + + + textLabel1_4_2_2_2 + + + true + + + vpnc + + + + + spacer67 + + + Horizontal + + + Expanding + + + + 20 + 20 + + + + + + VpncVersionLineEdit + + + + 3 + 0 + 0 + 0 + + + + + 32767 + 32767 + + + + true + + + Version information for the program + + + + + VpncPathInput + + + true + + + + 250 + 0 + + + + Program path + + + + + VpncStatePixmapLabel + + + image0 + + + true + + + AlignJustify|AlignVCenter + + + Program availability (found or not found) + + + + + + + layout4 + + + + unnamed + + + + textLabel1_3_2 + + + Debug level: + + + vpnc debug level + + + Debug level of the program. Increase to show more verbose debug output of program. This is helpful if you have any trouble with your VPN connection. + + + + + spinVpncDebugLevel + + + true + + + 99 + + + 0 + + + 0 + + + vpnc debug level + + + Debug level of the program. <br>Increase to show more verbose debug output of program. <br>This is helpful if you have any trouble with your VPN connection. + + + + + spacer28 + + + Horizontal + + + Expanding + + + + 16 + 20 + + + + + + + + + + + + groupBox7_2 + + + true + + + vpnclient (original Cisco VPN client) + + + + unnamed + + + + layout7_2 + + + + unnamed + + + + layout6_2 + + + + unnamed + + + + textLabel1_4_2_2_2_2 + + + true + + + vpnclient + + + + + spacer67_3 + + + Horizontal + + + Expanding + + + + 20 + 20 + + + + + + CiscoVpncVersionLineEdit + + + + 3 + 0 + 0 + 0 + + + + + 32767 + 32767 + + + + true + + + Version information for the program + + + + + CiscoVpncPathInput + + + true + + + + 250 + 0 + + + + Program path + + + + + CiscoVpncStatePixmapLabel + + + image0 + + + true + + + AlignJustify|AlignVCenter + + + Program availability (found or not found) + + + + + + + layout4_2 + + + + unnamed + + + + textLabel1_3_2_3 + + + Debug level: + + + vpnc debug level + + + Debug level of the program. Increase to show more verbose debug output of program. This is helpful if you have any trouble with your VPN connection. + + + + + spinCiscoVpncDebugLevel_2 + + + true + + + 99 + + + 0 + + + 0 + + + vpnc debug level + + + Debug level of the program. <br>Increase to show more verbose debug output of program. <br>This is helpful if you have any trouble with your VPN connection. + + + + + spacer28_2 + + + Horizontal + + + Expanding + + + + 16 + 20 + + + + + + + + + + + + groupBox8_2_2 + + + true + + + FreeS/WAN, Openswan, strongSwan + + + + unnamed + + + + layout15 + + + + unnamed + + + + layout8 + + + + unnamed + + + + textLabel1_4_2_2 + + + true + + + ipsec + + + + + spacer67_2 + + + Horizontal + + + Expanding + + + + 60 + 20 + + + + + + IpsecVersionLineEdit + + + + 3 + 0 + 0 + 0 + + + + + 32767 + 32767 + + + + true + + + Version information for the program + + + + + FreeswanPathInput + + + true + + + + 250 + 0 + + + + Program path + + + + + IpsecStatePixmapLabel + + + image0 + + + true + + + AlignJustify|AlignVCenter + + + Program availability (found or not found) + + + + + + + + + layout162 + + + + unnamed + + + + PlutoGroupBox + + + Pluto debug + + + + unnamed + + + + layout158 + + + + unnamed + + + + layout157 + + + + unnamed + + + + IpsecCryptDebugCheckBox + + + cr&ypt + + + Alt+Y + + + Show debug output from pppd + + + Enable this to show debug output of program. <br>This is helpful if you have any trouble with your VPN connection. + + + + + IpsecPrivateDebugCheckBox + + + &private + + + Alt+P + + + Show debug output from pppd + + + Enable this to show debug output of program. <br>This is helpful if you have any trouble with your VPN connection. + + + + + IpsecKlipsDebugCheckBox + + + &klips + + + Alt+K + + + Show debug output from pppd + + + Enable this to show debug output of program. <br>This is helpful if you have any trouble with your VPN connection. + + + + + IpsecEmittingDebugCheckBox + + + emitting + + + + + + Show debug output from pppd + + + Enable this to show debug output of program. <br>This is helpful if you have any trouble with your VPN connection. + + + + + IpsecRawDebugCheckBox + + + &raw + + + Alt+R + + + Show debug output from pppd + + + Enable this to show debug output of program. <br>This is helpful if you have any trouble with your VPN connection. + + + + + IpsecControlDebugCheckBox + + + &control + + + Alt+C + + + Show debug output from pppd + + + Enable this to show debug output of program. <br>This is helpful if you have any trouble with your VPN connection. + + + + + IpsecParsingDebugCheckBox + + + &parsing + + + Alt+P + + + Show debug output from pppd + + + Enable this to show debug output of program. <br>This is helpful if you have any trouble with your VPN connection. + + + + + + + + + + + KlipsGroupBox + + + KLIPS debug + + + + unnamed + + + + layout161 + + + + unnamed + + + + layout160 + + + + unnamed + + + + layout159 + + + + unnamed + + + + KlipsDebugSpiCheckBox + + + spi + + + + + + + + KlipsDebugAhCheckBox + + + ah + + + + + + + + KlipsDebugEspCheckBox + + + esp + + + + + + + + KlipsDebugErouteCheckBox + + + eroute + + + + + + + + KlipsDebugPfkeyCheckBox + + + pfkey + + + + + + + + KlipsDebugRadijCheckBox + + + radij + + + + + + + + KlipsDebugVerboseCheckBox + + + verbose + + + + + + + + KlipsDebugIpcompCheckBox + + + ipcomp + + + + + + + + KlipsDebugXformCheckBox + + + xform + + + + + + + + KlipsDebugTunnel_xmitCheckBox + + + &tunnel-xmit + + + Alt+T + + + + + + + + + + + + + + + + + groupBox8 + + + true + + + racoon + ipsec-tools (native Linux 2.6 or BSD) + + + + + + + unnamed + + + + layout71 + + + + unnamed + + + + layout10 + + + + unnamed + + + + RacoonPathInput + + + true + + + + 250 + 0 + + + + Program path + + + + + spacer67_2_2 + + + Horizontal + + + Expanding + + + + 87 + 20 + + + + + + textLabel1_4 + + + racoon/setkey + + + + + RacoonVersionLineEdit + + + + 3 + 0 + 0 + 0 + + + + + 32767 + 32767 + + + + true + + + Version information for the program + + + + + RacoonStatePixmapLabel + + + image0 + + + true + + + AlignJustify|AlignVCenter + + + Program availability (found or not found) + + + + + + + layout70 + + + + unnamed + + + + layout69 + + + + unnamed + + + + textLabel1_3_2_2 + + + Debug level: + + + ipsec-tools debug level + + + Debug level of the program. Increase to show more verbose debug output of program. This is helpful if you have any trouble with your VPN connection. + + + + + RacoonDebugLevelComboBox + + + Debug level of racoon + + + Debug level of the program. <br>Increase to show more verbose debug output of program. <br>This is helpful if you have any trouble with your VPN connection. + + + + + + + layout68 + + + + unnamed + + + + spacer45_2 + + + Horizontal + + + Expanding + + + + 117 + 20 + + + + + + DoKillRacoonIfStillRunningCheckBox + + + Do kill &racoon if still running + + + Alt+R + + + + + + + + + + + + + groupBox8_2_3_2 + + + true + + + PPTP + + + + + + + unnamed + + + + layout13 + + + + unnamed + + + + textLabel1_4_2_3_2 + + + true + + + pppd + + + + + spacer67_2_3_2 + + + Horizontal + + + Expanding + + + + 82 + 20 + + + + + + PppdVersionLineEdit + + + + 3 + 0 + 0 + 0 + + + + + 32767 + 32767 + + + + true + + + Version information for the program + + + + + PppdPathInput + + + true + + + + 250 + 0 + + + + Program path + + + + + PppdStatePixmapLabel + + + image0 + + + true + + + AlignJustify|AlignVCenter + + + Program availability (found or not found) + + + + + + + layout13_2 + + + + unnamed + + + + textLabel1_4_2_3_2_3 + + + true + + + pptp + + + + + spacer67_2_3_2_3 + + + Horizontal + + + Expanding + + + + 82 + 20 + + + + + + PptpVersionLineEdit + + + + 3 + 0 + 0 + 0 + + + + + 32767 + 32767 + + + + true + + + Version information for the program + + + + + PptpPathInput + + + true + + + + 250 + 0 + + + + Program path + + + + + PptpStatePixmapLabel + + + image0 + + + true + + + AlignJustify|AlignVCenter + + + Program availability (found or not found) + + + + + + + layout36 + + + + unnamed + + + + layout34 + + + + unnamed + + + + DebugPppdcheckBox + + + Ena&ble pppd debug + + + Alt+B + + + Show debug output from pppd + + + Enable this to show debug output of program. <br>This is helpful if you have any trouble with your VPN connection. + + + + + spacer20 + + + Horizontal + + + Expanding + + + + 51 + 21 + + + + + + + + layout33 + + + + unnamed + + + + DebugPptpdcheckBox + + + Ena&ble pptpd debug + + + Alt+B + + + Show debug output from pppd + + + Enable this to show debug output of program. <br>This is helpful if you have any trouble with your VPN connection. + + + + + spacer19 + + + Horizontal + + + Expanding + + + + 31 + 21 + + + + + + + + + + layout56 + + + + unnamed + + + + PppdKernelLogLevelTextLabel + + + pppd kernel log level: + + + pptp debug level + + + Debug level of the program. Increase to show more verbose debug output of program. This is helpful if you have any trouble with your VPN connection. + + + + + + none + + + + + general + + + + + general + packets + + + + PppdKernelLogLevelComboBox + + + pptp debug level + + + Debug level of the program. <br>Increase to show more verbose debug output of program. <br>This is helpful if you have any trouble with your VPN c + + + + + + + layout57 + + + + unnamed + + + + spacer18 + + + Horizontal + + + Expanding + + + + 80 + 21 + + + + + + textLabel1_3_2_2_3 + + + pptpd log level: + + + pptp debug level + + + Debug level of the program. Increase to show more verbose debug output of program. This is helpful if you have any trouble with your VPN connection. + + + + + + default + + + + + low + + + + + high + + + + PptpLogLevelComboBox + + + pptp debug level + + + Debug level of the program. <br>Increase to show more verbose debug output of program. <br>This is helpful if you have any trouble with your VPN c + + + + + + + + + groupBox8_2_3_2_2 + + + true + + + OpenVPN + + + + unnamed + + + + layout18 + + + + unnamed + + + + layout16 + + + + unnamed + + + + textLabel1_4_2_3_2_2 + + + true + + + openvpn + + + + + spacer67_2_3_2_2 + + + Horizontal + + + Expanding + + + + 87 + 20 + + + + + + OpenvpnVersionLineEdit + + + + 3 + 0 + 0 + 0 + + + + + 32767 + 32767 + + + + true + + + Version information for the program + + + + + OpenvpnPathInput + + + true + + + + 250 + 0 + + + + Program path + + + + + OpenvpnStatePixmapLabel + + + image0 + + + true + + + AlignJustify|AlignVCenter + + + Program availability (found or not found) + + + + + + + layout17 + + + + unnamed + + + + textLabel1_3_2_2_2 + + + Debug level: + + + openvpn debug level + + + Debug level of the program. Increase to show more verbose debug output of program. This is helpful if you have any trouble with your VPN connection. + + + + + spinOpenvpnDebugLevel + + + true + + + 99 + + + 0 + + + 0 + + + openvpn debug level + + + Debug level of the program. <br>Increase to show more verbose debug output of program. <br>This is helpful if you have any trouble with your VPN connection. + + + + + spacer13_2 + + + Horizontal + + + Expanding + + + + 151 + 20 + + + + + + + + + + + + groupBox8_2_3_2_2_2 + + + true + + + L2TP + + + + unnamed + + + + layout36 + + + + unnamed + + + + layout16_2 + + + + unnamed + + + + textLabel1_4_2_3_2_2_2 + + + true + + + l2tpd + + + + + spacer67_2_3_2_2_2 + + + Horizontal + + + Expanding + + + + 87 + 20 + + + + + + L2tpdVersionLineEdit + + + + 3 + 0 + 0 + 0 + + + + + 32767 + 32767 + + + + true + + + Version information for the program + + + + + L2tpdPathInput + + + true + + + + 250 + 0 + + + + Program path + + + + + L2tpdStatePixmapLabel + + + image0 + + + true + + + AlignJustify|AlignVCenter + + + Program availability (found or not found) + + + + + + + layout35 + + + + unnamed + + + + DebugL2tpdCheckBox + + + Enable l2tpd debug + + + + + + Show debug output from pppd + + + Enable this to show debug output of program. <br>This is helpful if you have any trouble with your VPN connection. + + + + + DoKillL2tpdIfStillRunningCheckBox + + + Do kill l&2tpd if still running + + + Alt+2 + + + + + + + + + + + groupBox8_2_3_2_2_2_2 + + + true + + + XL2TP + + + + unnamed + + + + layout16_2_2 + + + + unnamed + + + + textLabel1_4_2_3_2_2_2_2 + + + true + + + xl2tpd + + + + + spacer67_2_3_2_2_2_2 + + + Horizontal + + + Expanding + + + + 87 + 20 + + + + + + Xl2tpdVersionLineEdit + + + + 3 + 0 + 0 + 0 + + + + + 32767 + 32767 + + + + true + + + Version information for the program + + + + + Xl2tpdPathInput + + + true + + + + 250 + 0 + + + + Program path + + + + + Xl2tpdStatePixmapLabel + + + image0 + + + true + + + AlignJustify|AlignVCenter + + + Program availability (found or not found) + + + + + + + layout37 + + + + unnamed + + + + layout65_2 + + + + unnamed + + + + DoKillXl2tpdIfStillRunningCheckBox + + + Do kill &xl2tpd if still running + + + Alt+X + + + + + + + + + layout37 + + + + unnamed + + + + EnableDebugXl2tpdstateCheckBox + + + enable L2TP state debug + + + + + + + + EnableDebugXl2tpdtunnelCheckBox + + + enable L2TP AVP debug + + + + + + + + EnableDebugXl2tpdpacketCheckBox + + + enable L2TP packet debug + + + + + + + + EnableDebugXl2tpdNetworkCheckBox + + + enable L2TP network debug + + + + + + + + + + + + groupBox8_2_3_2_2_2_3 + + + true + + + OpenL2tp + + + + unnamed + + + + layout36_2 + + + + unnamed + + + + layout16_2_3 + + + + unnamed + + + + textLabel1_4_2_3_2_2_2_3 + + + true + + + openl2tpd + + + + + spacer67_2_3_2_2_2_3 + + + Horizontal + + + Expanding + + + + 87 + 20 + + + + + + Openl2tpVersionLineEdit + + + + 3 + 0 + 0 + 0 + + + + + 32767 + 32767 + + + + true + + + Version information for the program + + + + + Openl2tpPathInput + + + true + + + + 250 + 0 + + + + Program path + + + + + Openl2tpStatePixmapLabel + + + image0 + + + true + + + AlignJustify|AlignVCenter + + + Program availability (found or not found) + + + + + + + layout35_2 + + + + unnamed + + + + DebugOpenl2tpCheckBox + + + true + + + Enable &openl2tp debug + + + Alt+O + + + Show debug output from pppd + + + Enable this to show debug output of program. <br>This is helpful if you have any trouble with your VPN connection. + + + + + + + + + + + groupBox8_2_3_2_2_2_2_2 + + + true + + + Vtun + + + + unnamed + + + + layout16_2_2_2 + + + + unnamed + + + + textLabel1_4_2_3_2_2_2_2_2 + + + true + + + vtund + + + + + spacer67_2_3_2_2_2_2_2 + + + Horizontal + + + Expanding + + + + 87 + 20 + + + + + + VtunVersionLineEdit + + + + 3 + 0 + 0 + 0 + + + + + 32767 + 32767 + + + + true + + + Version information for the program + + + + + VtundPathInput + + + true + + + + 250 + 0 + + + + Program path + + + + + VtundStatePixmapLabel + + + image0 + + + true + + + AlignJustify|AlignVCenter + + + Program availability (found or not found) + + + + + + + + + groupBox8_2_3_2_2_2_2_2_2 + + + true + + + SSH + + + + unnamed + + + + layout140 + + + + unnamed + + + + layout16_2_2_2_2 + + + + unnamed + + + + textLabel1_4_2_3_2_2_2_2_2_2 + + + true + + + ssh + + + + + spacer67_2_3_2_2_2_2_2_2 + + + Horizontal + + + Expanding + + + + 87 + 20 + + + + + + SshVersionLineEdit + + + + 3 + 0 + 0 + 0 + + + + + 32767 + 32767 + + + + true + + + Version information for the program + + + + + SshPathInput + + + true + + + + 250 + 0 + + + + Program path + + + + + SshStatePixmapLabel + + + image0 + + + true + + + AlignJustify|AlignVCenter + + + Program availability (found or not found) + + + + + + + layout139 + + + + unnamed + + + + textLabel1_3_2_2_2_2 + + + Debug level: + + + openvpn debug level + + + Debug level of the program. Increase to show more verbose debug output of program. This is helpful if you have any trouble with your VPN connection. + + + + + spinSshDebugLevel + + + true + + + 8 + + + 0 + + + 0 + + + openvpn debug level + + + Debug level of the program. <br>Increase to show more verbose debug output of program. <br>This is helpful if you have any trouble with your VPN connection. + + + + + spacer13_2_2 + + + Horizontal + + + Expanding + + + + 365 + 20 + + + + + + + + + + + + spacer12 + + + Vertical + + + Expanding + + + + 20 + 16 + + + + + + + + spacer97 + + + Horizontal + + + Expanding + + + + 16 + 21 + + + + + + + + + + 789c7dd0b96e83401006e09ea740d059516cce80a214d8d8ae22a58c14a558aee1345e0c3610e5dde33d9da430a2f9e6df19865d2ed4f7b75775b1544e3dea8b588d73d4a98b64689ae9e3f3e54bd10c57bdbe96a31ada83a2811aabfa8a3e84b9a4479871da2c2d24697ae6f4585a517a06efdd121a2b831f1e283d93732234578281a041474594bee5b1341664e94c68198223a18d1c9f712d497b1167c2d296d03105778caec3585322978f3a48d25117c227cbe3bd9d244d1b42cff239434664b0c389244d4f9c0ea34e198974c3c9d39ed0b723938dc292344d09911df3742f49d392d36537f928c80e1f2559faefb95bd35114a3e4772d451900e4054a4b594350d54d72a8a03d8a9a9e557a59e2ee5465baa821a8cbb21fce971a46518ba029f100136e604e792d8604070001a9c9defcd09da700863520f98da2da74f8da0d59287719afbb84e11a608b6f3bb76467c8b6d9eef66f477d9ce736c4bbfd9f3b48efdc4ba97d3f2b3fcf12c742 + + + + + ProgramsInPathcheckBox + toggled(bool) + ConfigDaemonOptionsBase + programsInPathToggled(bool) + + + + ProgramsInPathcheckBox + VpncVersionLineEdit + VpncPathInput + spinVpncDebugLevel + IpsecVersionLineEdit + FreeswanPathInput + RacoonVersionLineEdit + RacoonPathInput + RacoonDebugLevelComboBox + PppdVersionLineEdit + PppdPathInput + PptpVersionLineEdit + PptpPathInput + DebugPppdcheckBox + PptpLogLevelComboBox + OpenvpnVersionLineEdit + OpenvpnPathInput + spinOpenvpnDebugLevel + + + programsInPathToggled(bool) + + + + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + kcombobox.h + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + kcombobox.h + kcombobox.h + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + + diff --git a/src/configdebugoptions.cpp b/src/configdebugoptions.cpp new file mode 100644 index 0000000..e5402b5 --- /dev/null +++ b/src/configdebugoptions.cpp @@ -0,0 +1,47 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "configdebugoptions.h" +#include "widgetnotifyhelper.h" + +#include + +ConfigDebugOptions::ConfigDebugOptions(QWidget *parent, const QString& caption): ConfigDebugOptionsBase(parent) +{ + WidgetNotifyHelper h; + h.setupChangedAction(this); + dialogModified=false; +} + + +ConfigDebugOptions::~ConfigDebugOptions() +{ +} + +void ConfigDebugOptions::dialogChanged() +{ +// std::cout << "ConfigDebugOptions::dialogChanged()" << std::endl; + dialogModified=true; +} + + + + + + diff --git a/src/configdebugoptions.h b/src/configdebugoptions.h new file mode 100644 index 0000000..b3eee36 --- /dev/null +++ b/src/configdebugoptions.h @@ -0,0 +1,46 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef CONFIGDEBUGOPTIONS_H +#define CONFIGDEBUGOPTIONS_H + +#include "configdebugoptionsbase.h" +#include +#include + +/** + @author Christoph Thielecke +*/ +class ConfigDebugOptions : public ConfigDebugOptionsBase +{ + Q_OBJECT +public: + ConfigDebugOptions(QWidget *parent, const QString& caption); + ~ConfigDebugOptions(); + bool dialogModified; + +private slots: + void dialogChanged(); + +signals: + void changed(); + +}; + +#endif diff --git a/src/configdebugoptionsbase.ui b/src/configdebugoptionsbase.ui new file mode 100644 index 0000000..efc0a65 --- /dev/null +++ b/src/configdebugoptionsbase.ui @@ -0,0 +1,243 @@ + +ConfigDebugOptionsBase + + + ConfigDebugOptionsBase + + + + 0 + 0 + 337 + 210 + + + + + 3 + 1 + 0 + 0 + + + + Debug + + + + unnamed + + + + layout7 + + + + unnamed + + + + showDebugCheck + + + S&how debug console + + + Alt+H + + + Show the debug console in main window + + + Enable this if you want to see the debug console <br>in main KVpnc window. + + + + + spacer29_2 + + + Horizontal + + + Expanding + + + + 110 + 20 + + + + + + + + layout8 + + + + unnamed + + + + WriteLogCheck + + + Write log &file + + + Alt+F + + + Write logs to file: $HOME/.kde/share/apps/kvpnc/kvpnc.log + + + + + + + + spacer28_4 + + + Horizontal + + + Expanding + + + + 170 + 20 + + + + + + + + layout9 + + + + unnamed + + + + spinKvpncDebugLevel + + + true + + + 99 + + + 0 + + + 0 + + + KVpnc debug level. Increase to show more <br>verbose debug output of KVpnc. + + + Debug level of the KVpnc program. <br>Increase to show more verbose debug output of KVpnc. <br>This is helpful if you have any trouble with using KVpnc. + + + + + textLabel1_3_2_3 + + + Debug level: + + + KVpnc debug level. Increase to show more <br>verbose debug output of KVpnc. + + + Debug level of the KVpnc program. <br>Increase to show more verbose debug output of KVpnc. <br>This is helpful if you have any trouble with using KVpnc. + + + + + spacer28_2 + + + Horizontal + + + Expanding + + + + 150 + 20 + + + + + + + + layout10 + + + + unnamed + + + + KeepConnectionFilesCheckBox + + + Keep connec&tion files + + + Alt+T + + + Do not remove connection config files after use + + + + + spacer31 + + + Horizontal + + + Expanding + + + + 110 + 20 + + + + + + + + spacer6 + + + Vertical + + + Expanding + + + + 20 + 21 + + + + + + + diff --git a/src/configgeneraloptions.ui b/src/configgeneraloptions.ui new file mode 100644 index 0000000..9c202a4 --- /dev/null +++ b/src/configgeneraloptions.ui @@ -0,0 +1,199 @@ + +ConfigGeneralOptions + + + ConfigGeneralOptions + + + + 0 + 0 + 341 + 215 + + + + + 3 + 1 + 0 + 0 + + + + General + + + + unnamed + + + + layout9 + + + + unnamed + + + + + + layout9 + + + + unnamed + + + + layout7 + + + + unnamed + + + + useKwalletCheckBox + + + Use K&Wallet + + + Alt+W + + + Use KWallet for secure store passwords + + + + + + + + spacer29_2 + + + Horizontal + + + Expanding + + + + 110 + 20 + + + + + + + + layout11 + + + + unnamed + + + + DontQuitOnCloseEventCheckBox + + + Do not &quit by clicking close button + + + Alt+Q + + + Close button minimizes to system tray <br>(kicker) instead of quit the program + + + + + spacer31_2 + + + Horizontal + + + Expanding + + + + 16 + 20 + + + + + + + + layout11_2 + + + + unnamed + + + + HideOnStartupCheckBox + + + Hide on startup + + + + + + Hides the KVpnc mainwindow on startup. KVpnc is still accessable vrom dock menu. + + + + + spacer31_2_2 + + + Horizontal + + + Expanding + + + + 16 + 20 + + + + + + + + spacer6 + + + Vertical + + + Expanding + + + + 20 + 80 + + + + + + + + + useKwalletToggled(bool) + + + diff --git a/src/confighelperprogramoptions.cpp b/src/confighelperprogramoptions.cpp new file mode 100644 index 0000000..d82ab34 --- /dev/null +++ b/src/confighelperprogramoptions.cpp @@ -0,0 +1,42 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "confighelperprogramoptions.h" +#include "widgetnotifyhelper.h" +#include + +ConfigHelperProgramOptions::ConfigHelperProgramOptions(QWidget *parent) + : ConfigHelperProgramOptionsBase(parent) +{ + WidgetNotifyHelper h; + h.setupChangedAction(this); + dialogModified=false; +} + + +ConfigHelperProgramOptions::~ConfigHelperProgramOptions() +{} + +void ConfigHelperProgramOptions::dialogChanged() +{ +// std::cout << "ConfigHelperProgramOptions::dialogChanged()" << std::endl; + dialogModified=true; +} + + diff --git a/src/confighelperprogramoptions.h b/src/confighelperprogramoptions.h new file mode 100644 index 0000000..54f0631 --- /dev/null +++ b/src/confighelperprogramoptions.h @@ -0,0 +1,44 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef CONFIGHELPERPROGRAMOPTIONS_H +#define CONFIGHELPERPROGRAMOPTIONS_H + +#include "confighelperprogramoptionsbase.h" +#include + +/** +@author Christoph Thielecke +*/ +class ConfigHelperProgramOptions : public ConfigHelperProgramOptionsBase +{ +Q_OBJECT +public: + ConfigHelperProgramOptions(QWidget *parent); + ~ConfigHelperProgramOptions(); + bool dialogModified; + +private slots: + void dialogChanged(); + +signals: + void changed(); +}; + +#endif diff --git a/src/confighelperprogramoptionsbase.ui b/src/confighelperprogramoptionsbase.ui new file mode 100644 index 0000000..09d8012 --- /dev/null +++ b/src/confighelperprogramoptionsbase.ui @@ -0,0 +1,1489 @@ + +ConfigHelperProgramOptionsBase + + + ConfigHelperProgramOptionsBase + + + + 0 + 0 + 552 + 607 + + + + Helper programs + + + Here you can set options for small helper programs (no daemons) + + + + unnamed + + + + layout233 + + + + unnamed + + + + layout232 + + + + unnamed + + + + layout21 + + + + unnamed + + + + textLabel1_4_2_3_4_5 + + + true + + + ifconfig + + + + + spacer72 + + + Horizontal + + + Expanding + + + + 146 + 20 + + + + + + + + IptablesStatePixmapLabel + + + + 22 + 22 + + + + image0 + + + true + + + Program availability (found or not found) + + + + + textLabel1_4_2_4 + + + true + + + <b>Path</b> + + + + + IptablesVersionLineEdit + + + + 3 + 0 + 0 + 0 + + + + + 32767 + 32767 + + + + true + + + Version information for the program + + + + + PingPathInput + + + true + + + + 250 + 0 + + + + Program path + + + + + KillStatePixmapLabel + + + + 22 + 22 + + + + image0 + + + true + + + Program availability (found or not found) + + + + + OpensslVersionLineEdit + + + + 3 + 0 + 0 + 0 + + + + + 32767 + 32767 + + + + true + + + Version information for the program + + + + + IpStatePixmapLabel + + + + 22 + 22 + + + + image0 + + + true + + + Program availability (found or not found) + + + + + CiscoCertMgrVersionLineEdit + + + + 3 + 0 + 0 + 0 + + + + + 32767 + 32767 + + + + true + + + Version information for the program + + + + + layout23 + + + + unnamed + + + + textLabel1_4_2_3_4_6_2 + + + true + + + pkcs11-tool + + + + + spacer73_2 + + + Horizontal + + + Expanding + + + + 146 + 16 + + + + + + + + Pkcs11ToolPathInput + + + true + + + + 250 + 0 + + + + Program path + + + + + OpensslStatePixmapLabel + + + + 22 + 22 + + + + image0 + + + true + + + Program availability (found or not found) + + + + + layout24 + + + + unnamed + + + + textLabel1_4_2_3_4_6_2_2 + + + true + + + cisco_cert_mgr + + + + + spacer73_2_2 + + + Horizontal + + + Expanding + + + + 146 + 16 + + + + + + + + IpVersionLineEdit + + + + 3 + 0 + 0 + 0 + + + + + 32767 + 32767 + + + + true + + + Version information for the program + + + + + GnomeaskpassVersionLineEdit + + + + 3 + 0 + 0 + 0 + + + + + 32767 + 32767 + + + + true + + + Version information for the program + + + + + layout19 + + + + unnamed + + + + textLabel1_4_2_3_4_2 + + + true + + + ping + + + + + spacer70_2 + + + Horizontal + + + Expanding + + + + 146 + 20 + + + + + + + + IfconfigPathInput + + + true + + + + 250 + 0 + + + + Program path + + + + + Pkcs11ToolStatePixmapLabel + + + + 22 + 22 + + + + image0 + + + true + + + Program availability (found or not found) + + + + + layout24_2_2 + + + + unnamed + + + + textLabel1_4_2_3_4_6_2_2_2_2 + + + true + + + ksshaskpass + + + + + spacer73_2_2_2_2 + + + Horizontal + + + Expanding + + + + 146 + 16 + + + + + + + + layout24_2_3 + + + + unnamed + + + + textLabel1_4_2_3_4_6_2_2_2_3 + + + true + + + ssh-askpass-gnome + + + + + spacer73_2_2_2_3 + + + Horizontal + + + Expanding + + + + 146 + 16 + + + + + + + + KsshaskpassPathInput + + + true + + + + 250 + 0 + + + + Program path + + + + + OpenSSLPathInput + + + true + + + + 250 + 0 + + + + Program path + + + + + layout15 + + + + unnamed + + + + textLabel1_4_2 + + + true + + + openssl + + + + + spacer67 + + + Horizontal + + + Expanding + + + + 146 + 20 + + + + + + + + KsshaskpassStatePixmapLabel + + + + 22 + 22 + + + + image0 + + + true + + + Program availability (found or not found) + + + + + TailVersionLineEdit + + + + 3 + 0 + 0 + 0 + + + + + 32767 + 32767 + + + + true + + + Version information for the program + + + + + PingVersionLineEdit + + + + 3 + 0 + 0 + 0 + + + + + 32767 + 32767 + + + + true + + + Version information for the program + + + + + layout18 + + + + unnamed + + + + textLabel1_4_2_3_4 + + + true + + + killall + + + + + spacer70 + + + Horizontal + + + Expanding + + + + 146 + 20 + + + + + + + + CiscoCertMgrStatePixmapLabel + + + + 22 + 22 + + + + image0 + + + true + + + Program availability (found or not found) + + + + + KillallVersionLineEdit + + + + 3 + 0 + 0 + 0 + + + + + 32767 + 32767 + + + + true + + + Version information for the program + + + + + GnomeaskpassStatePixmapLabel + + + + 22 + 22 + + + + image0 + + + true + + + Program availability (found or not found) + + + + + layout22 + + + + unnamed + + + + textLabel1_4_2_3_4_6 + + + true + + + route + + + + + spacer73 + + + Horizontal + + + Expanding + + + + 146 + 16 + + + + + + + + RoutePathInput + + + true + + + + 250 + 0 + + + + Program path + + + + + IfconfigStatePixmapLabel + + + + 22 + 22 + + + + image0 + + + true + + + Program availability (found or not found) + + + + + layout25 + + + + unnamed + + + + textLabel1_4_2_2 + + + true + + + <b>Tool</b> + + + + + spacer67_2 + + + Horizontal + + + Expanding + + + + 146 + 20 + + + + + + + + layout20 + + + + unnamed + + + + textLabel1_4_2_3_4_4 + + + true + + + ip + + + + + spacer71 + + + Horizontal + + + Expanding + + + + 146 + 20 + + + + + + + + IpPathInput + + + true + + + + 250 + 0 + + + + Program path + + + + + TailPathInput + + + true + + + + 250 + 0 + + + + Program path + + + + + layout16 + + + + unnamed + + + + textLabel1_4_2_3_5 + + + true + + + iptables + + + + + spacer68 + + + Horizontal + + + Expanding + + + + 146 + 20 + + + + + + + + KillPathInput + + + true + + + + 250 + 0 + + + + Program path + + + + + KillVersionLineEdit + + + + 3 + 0 + 0 + 0 + + + + + 32767 + 32767 + + + + true + + + Version information for the program + + + + + KillallPathInput + + + true + + + + 250 + 0 + + + + Program path + + + + + textLabel1_4_2_3 + + + true + + + <b>Version</b> + + + + + KsshaskpassVersionLineEdit + + + + 3 + 0 + 0 + 0 + + + + + 32767 + 32767 + + + + true + + + Version information for the program + + + + + RouteVersionLineEdit + + + + 3 + 0 + 0 + 0 + + + + + 32767 + 32767 + + + + true + + + Version information for the program + + + + + TailStatePixmapLabel + + + + 22 + 22 + + + + image0 + + + true + + + Program availability (found or not found) + + + + + KillallStatePixmapLabel + + + + 22 + 22 + + + + image0 + + + true + + + Program availability (found or not found) + + + + + PingStatePixmapLabel + + + + 22 + 22 + + + + image0 + + + true + + + Program availability (found or not found) + + + + + Pkcs11ToolVersionLineEdit + + + + 3 + 0 + 0 + 0 + + + + + 32767 + 32767 + + + + true + + + Version information for the program + + + + + RouteStatePixmapLabel + + + + 22 + 22 + + + + image0 + + + true + + + Program availability (found or not found) + + + + + GnomeaskpassPathInput + + + true + + + + 250 + 0 + + + + Program path + + + + + IfconfigVersionLineEdit + + + + 3 + 0 + 0 + 0 + + + + + 32767 + 32767 + + + + true + + + Version information for the program + + + + + IptablesPathInput + + + true + + + + 250 + 0 + + + + Program path + + + + + CiscoCertMgrPathInput + + + true + + + + 250 + 0 + + + + Program path + + + + + layout17 + + + + unnamed + + + + textLabel1_4_2_3_3 + + + true + + + kill + + + + + spacer69 + + + Horizontal + + + Expanding + + + + 146 + 20 + + + + + + + + layout24_2 + + + + unnamed + + + + textLabel1_4_2_3_4_6_2_2_2 + + + true + + + tail + + + + + spacer73_2_2_2 + + + Horizontal + + + Expanding + + + + 146 + 16 + + + + + + + + + + spacer1 + + + Vertical + + + Expanding + + + + 31 + 130 + + + + + + + + + + 789c7dd0b96e83401006e09ea740d059516cce80a214d8d8ae22a58c14a558aee1345e0c3610e5dde33d9da430a2f9e6df19865d2ed4f7b75775b1544e3dea8b588d73d4a98b64689ae9e3f3e54bd10c57bdbe96a31ada83a2811aabfa8a3e84b9a4479871da2c2d24697ae6f4585a517a06efdd121a2b831f1e283d93732234578281a041474594bee5b1341664e94c68198223a18d1c9f712d497b1167c2d296d03105778caec3585322978f3a48d25117c227cbe3bd9d244d1b42cff239434664b0c389244d4f9c0ea34e198974c3c9d39ed0b723938dc292344d09911df3742f49d392d36537f928c80e1f2559faefb95bd35114a3e4772d451900e4054a4b594350d54d72a8a03d8a9a9e557a59e2ee5465baa821a8cbb21fce971a46518ba029f100136e604e792d8604070001a9c9defcd09da700863520f98da2da74f8da0d59287719afbb84e11a608b6f3bb76467c8b6d9eef66f477d9ce736c4bbfd9f3b48efdc4ba97d3f2b3fcf12c742 + + + + OpensslVersionLineEdit + OpenSSLPathInput + IptablesVersionLineEdit + IptablesPathInput + KillVersionLineEdit + KillPathInput + KillallVersionLineEdit + KillallPathInput + PingVersionLineEdit + PingPathInput + IpVersionLineEdit + IpPathInput + IfconfigVersionLineEdit + IfconfigPathInput + RouteVersionLineEdit + RoutePathInput + + + + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + + diff --git a/src/configlogoptions.cpp b/src/configlogoptions.cpp new file mode 100644 index 0000000..276f292 --- /dev/null +++ b/src/configlogoptions.cpp @@ -0,0 +1,98 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "configlogoptions.h" +#include +#include +#include +#include +#include +#include "widgetnotifyhelper.h" + +#include + +ConfigLogOptions::ConfigLogOptions(QWidget *parent) + : ConfigLogOptionsBase(parent) +{ + WidgetNotifyHelper h; + h.setupChangedAction(this); + dialogModified=false; +} + + +ConfigLogOptions::~ConfigLogOptions() +{} + +void ConfigLogOptions::errorLogColorClicked() +{ + int result = KColorDialog::getColor( ErrorLogColor ); + if ( result == KColorDialog::Accepted ) + ErrorLogLabel->setPaletteBackgroundColor (ErrorLogColor); +} + +void ConfigLogOptions::debugLogColorClicked() +{ + int result = KColorDialog::getColor( DebugLogColor ); + if ( result == KColorDialog::Accepted ) + DebugLogLabel->setPaletteBackgroundColor (DebugLogColor); +} + + +void ConfigLogOptions::infoLogColorClicked() +{ + int result = KColorDialog::getColor( InfoLogColor ); + if ( result == KColorDialog::Accepted ) + InfoLogLabel->setPaletteBackgroundColor (InfoLogColor); +} + +void ConfigLogOptions::remoteLogColorClicked() +{ + int result = KColorDialog::getColor( RemoteLogColor ); + if ( result == KColorDialog::Accepted ) + RemoteLogLabel->setPaletteBackgroundColor (RemoteLogColor); +} + +void ConfigLogOptions::successLogColorClicked() +{ + int result = KColorDialog::getColor( SuccessLogColor ); + if ( result == KColorDialog::Accepted ) + SuccessLogLabel->setPaletteBackgroundColor (SuccessLogColor); +} + +void ConfigLogOptions::useColorizedLogOutputToggled(bool) +{ + if (UseColorizedLogOutputcheckBox->isChecked() ) + ColorGroupBox->setEnabled(true); + else + ColorGroupBox->setEnabled(false); +} + +void ConfigLogOptions::backgroundLogColorClicked() +{ + int result = KColorDialog::getColor( BackgroundLogColor ); + if ( result == KColorDialog::Accepted ) + BackgroundLogLabel->setPaletteBackgroundColor (BackgroundLogColor); +} + +void ConfigLogOptions::dialogChanged() +{ +// std::cout << "ConfigLogOptions::dialogChanged()" << std::endl; + dialogModified=true; +} + diff --git a/src/configlogoptions.h b/src/configlogoptions.h new file mode 100644 index 0000000..9797ddf --- /dev/null +++ b/src/configlogoptions.h @@ -0,0 +1,63 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef CONFIGLOGOPTIONS_H +#define CONFIGLOGOPTIONS_H + +#include "configlogoptionsbase.h" +#include +#include + +/** +@author Christoph Thielecke +*/ +class ConfigLogOptions : public ConfigLogOptionsBase +{ + Q_OBJECT +public: + ConfigLogOptions(QWidget *parent); + ~ConfigLogOptions(); + bool dialogModified; + +public slots: + void debugLogColorClicked(); + void infoLogColorClicked(); + void remoteLogColorClicked(); + void successLogColorClicked(); + void errorLogColorClicked(); + void useColorizedLogOutputToggled(bool); + void backgroundLogColorClicked(); + +protected: + QColor InfoLogColor; + QColor RemoteLogColor; + QColor ErrorLogColor; + QColor SuccessLogColor; + QColor DebugLogColor; + QColor BackgroundLogColor; + +private slots: + void dialogChanged(); + +signals: + void changed(); + +}; + +#endif diff --git a/src/configlogoptionsbase.ui b/src/configlogoptionsbase.ui new file mode 100644 index 0000000..a4d4387 --- /dev/null +++ b/src/configlogoptionsbase.ui @@ -0,0 +1,624 @@ + +ConfigLogOptionsBase + + + ConfigLogOptionsBase + + + + 0 + 0 + 340 + 317 + + + + Debug + + + + unnamed + + + + layout3 + + + + unnamed + + + + layout57_3 + + + + unnamed + + + + LogFontSizeSpinBox + + + true + + + 4 + + + -4 + + + 0 + + + Font size in the debug console + + + + + LogFontSizetextLabel + + + Font size: + + + Font size in the debug console + + + + + spacer28_2_2_2 + + + Horizontal + + + Expanding + + + + 16 + 20 + + + + + + + + layout211 + + + + unnamed + + + + UseColorizedLogOutputcheckBox + + + Enable colori&zed log output + + + Alt+Z + + + Enable color messages in the debug console (recommend) + + + + + spacer100 + + + Horizontal + + + Expanding + + + + 61 + 20 + + + + + + + + ColorGroupBox + + + Color settings + + + + unnamed + + + + textLabel2_2 + + + Error message + + + Message type + + + + + RemoteLogLabel + + + + 25 + 25 + + + + + 85 + 0 + 255 + + + + Box + + + Sunken + + + + + InfoLogLabel + + + + 25 + 25 + + + + + 0 + 0 + 0 + + + + Box + + + Sunken + + + 1 + + + + + ErrorLogLabel + + + + 25 + 25 + + + + + 255 + 0 + 0 + + + + Box + + + Sunken + + + + + spacer28_3_2 + + + Horizontal + + + Expanding + + + + 173 + 20 + + + + + + spacer28_3_3 + + + Horizontal + + + Expanding + + + + 173 + 20 + + + + + + RemoteLogFontPushButton + + + C&hange... + + + Change color of this message type + + + + + textLabel2_3 + + + Success message + + + Message type + + + + + spacer28_3 + + + Horizontal + + + Expanding + + + + 173 + 20 + + + + + + spacer28_3_3_2_2 + + + Horizontal + + + Expanding + + + + 173 + 20 + + + + + + textLabel2_3_2_2 + + + Remote message + + + Message type + + + + + ErrorLogFontPushButton + + + Ch&ange... + + + Change color of this message type + + + + + SuccessLogFontPushButton + + + Cha&nge... + + + Change color of this message type + + + + + InfoLogFontPushButton + + + Chan&ge... + + + Alt+G + + + Change color of this message type + + + + + SuccessLogLabel + + + + 25 + 25 + + + + + 0 + 170 + 0 + + + + Box + + + Sunken + + + + + textLabel2_3_2 + + + Debug message + + + Message type + + + + + spacer28_3_3_2 + + + Horizontal + + + Expanding + + + + 173 + 20 + + + + + + DebugLogFontPushButton + + + &Change... + + + Alt+C + + + Change color of this message type + + + + + DebugLogLabel + + + + 25 + 25 + + + + + 255 + 170 + 0 + + + + Box + + + Sunken + + + + + textLabel2_3_2_3 + + + Background color + + + Message type + + + + + spacer28_3_3_2_3 + + + Horizontal + + + Expanding + + + + 43 + 20 + + + + + + BackgroundLogFontPushButton + + + &Change... + + + Alt+C + + + Change color of this message type + + + + + BackgroundLogLabel + + + + 25 + 25 + + + + + 255 + 255 + 255 + + + + Box + + + Sunken + + + + + textLabel2 + + + Informal message + + + Message type + + + + + + + spacer8 + + + Vertical + + + Expanding + + + + 21 + 20 + + + + + + + + + + DebugLogFontPushButton + clicked() + ConfigLogOptionsBase + debugLogColorClicked() + + + ErrorLogFontPushButton + clicked() + ConfigLogOptionsBase + errorLogColorClicked() + + + InfoLogFontPushButton + clicked() + ConfigLogOptionsBase + infoLogColorClicked() + + + RemoteLogFontPushButton + clicked() + ConfigLogOptionsBase + remoteLogColorClicked() + + + SuccessLogFontPushButton + clicked() + ConfigLogOptionsBase + successLogColorClicked() + + + UseColorizedLogOutputcheckBox + toggled(bool) + ConfigLogOptionsBase + useColorizedLogOutputToggled(bool) + + + BackgroundLogFontPushButton + clicked() + ConfigLogOptionsBase + backgroundLogColorClicked() + + + + LogFontSizeSpinBox + UseColorizedLogOutputcheckBox + InfoLogFontPushButton + RemoteLogFontPushButton + ErrorLogFontPushButton + SuccessLogFontPushButton + DebugLogFontPushButton + + + debugLogColorClicked() + errorLogColorClicked() + successLogColorClicked() + infoLogColorClicked() + remoteLogColorClicked() + useColorizedLogOutputToggled(bool) + backgroundLogColorClicked() + + + + kpushbutton.h + kpushbutton.h + kpushbutton.h + kpushbutton.h + kpushbutton.h + kpushbutton.h + + diff --git a/src/debugoutputtextedit.cpp b/src/debugoutputtextedit.cpp new file mode 100644 index 0000000..b81a94c --- /dev/null +++ b/src/debugoutputtextedit.cpp @@ -0,0 +1,55 @@ +/*************************************************************************** + * Copyright (C) 2005 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "debugoutputtextedit.h" + +#include +#include +#include +#include + +DebugOutputTextEdit::DebugOutputTextEdit( QWidget* parent, const char* name) + : KTextBrowser( parent, name) +{ + + +} + +DebugOutputTextEdit::~DebugOutputTextEdit() +{ + if (popup != 0) + delete popup; +} + +QPopupMenu* DebugOutputTextEdit::createPopupMenu(const QPoint &) +{ + popup = new QPopupMenu(this); + popup->insertItem(i18n("Cut Content"), this, SLOT(cut() ) ); + popup->insertItem(i18n("Copy Content"), this, SLOT(copy() ) ); + popup->insertSeparator(); + popup->insertItem(i18n("Clear Log Window"), this, SLOT(clear() ) ); + popup->insertSeparator(); + + return popup; +} + +void DebugOutputTextEdit::append ( const QString & text ) +{ + KTextBrowser::append(text); +} diff --git a/src/debugoutputtextedit.h b/src/debugoutputtextedit.h new file mode 100644 index 0000000..09bfc08 --- /dev/null +++ b/src/debugoutputtextedit.h @@ -0,0 +1,48 @@ +/*************************************************************************** + * Copyright (C) 2005 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef DEBUGOUTPUTTEXTEDIT_H +#define DEBUGOUTPUTTEXTEDIT_H + +#include +#include +#include + +/** +This class is used for showing log content + +@author Christoph Thielecke +*/ +class DebugOutputTextEdit : public KTextBrowser +{ + Q_OBJECT + +public: + DebugOutputTextEdit( QWidget* parent=0, const char* name=0); + ~DebugOutputTextEdit(); +public slots: + QPopupMenu* createPopupMenu(const QPoint & pos); + void append ( const QString & text ); + +private: + QPopupMenu *popup; + +}; + +#endif diff --git a/src/displaycertdialog.cpp b/src/displaycertdialog.cpp new file mode 100644 index 0000000..4264f68 --- /dev/null +++ b/src/displaycertdialog.cpp @@ -0,0 +1,76 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "displaycertdialog.h" +#include "klocale.h" +#include +#include +#include + +DisplayCertDialog::DisplayCertDialog(QWidget *parent, const char* caption, KVpncConfig *GlobalConfig) + : KDialogBase ( parent, i18n ( "Certificate data" ).ascii(), true, caption, + KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, true ) +{ + main = new DisplayCertDialogBase ( this ); + setMainWidget ( main ); + main->setMinimumSize ( main->sizeHint() ); + this->GlobalConfig = GlobalConfig; +} + + +DisplayCertDialog::~DisplayCertDialog() +{ + delete main; +} + +void DisplayCertDialog::parseCertData() +{ + std::cout << "certdatalist" << CertDataList.join (" ") << std::endl; + for ( QStringList::Iterator it = CertDataList.begin(); it != CertDataList.end(); ++it ) { + if (GlobalConfig->KvpncDebugLevel > 2) + GlobalConfig->appendLogEntry("[cert data]: "+*it,GlobalConfig->debug); + if ((*it).contains("Common Name:")) + main->NameLineEdit->setText((*it).section(':',1,-1).stripWhiteSpace()); + else if((*it).contains("Department:")) + main->DepartmentLineEdit->setText((*it).section(':',1,-1).stripWhiteSpace()); + else if((*it).contains("Company:")) + main->CompanyLineEdit->setText((*it).section(':',1,-1).stripWhiteSpace()); + else if((*it).contains("State:")) + main->StateLineEdit->setText((*it).section(':',1,-1).stripWhiteSpace()); + else if((*it).contains("Country:")) + main->CountryLineEdit->setText((*it).section(':',1,-1).stripWhiteSpace()); + else if((*it).contains("Email:")) + main->EmailLineEdit->setText((*it).section(':',1,-1).stripWhiteSpace()); +// else if((*it).contains("Thumb Print:")) +// main->ThumbPrintLineEdit->setText((*it).section(':',1,-1).stripWhiteSpace()); + else if((*it).contains("Key Size:")) + main->KeySizeLineEdit->setText((*it).section(':',1,-1).stripWhiteSpace()); + else if((*it).contains("Subject:")) + main->SubjectLineEdit->setText((*it).section(':',1,-1).stripWhiteSpace()); + else if((*it).contains("Serial #:")) + main->SerialLineEdit->setText((*it).section(':',1,-1).stripWhiteSpace()); + else if((*it).contains("Issuer:")) + main->IssuerLineEdit->setText((*it).section(':',1,-1).stripWhiteSpace()); + else if((*it).contains("Not before:")) + main->ValidFromLineEdit->setText((*it).section(':',1,-1).stripWhiteSpace()); + else if((*it).contains("Not after:")) + main->ValidToLineEdit->setText((*it).section(':',1,-1).stripWhiteSpace()); + } +} + diff --git a/src/displaycertdialog.h b/src/displaycertdialog.h new file mode 100644 index 0000000..a70a1d6 --- /dev/null +++ b/src/displaycertdialog.h @@ -0,0 +1,50 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef DISPLAYCERTDIALOG_H +#define DISPLAYCERTDIALOG_H + +#include +#include "kvpncconfig.h" +#include "displaycertdialogbase.h" + +#include + + +/** + @author Christoph Thielecke +*/ +class DisplayCertDialog : public KDialogBase +{ + public: + DisplayCertDialog ( QWidget *parent, const char* caption, KVpncConfig *GlobalConfig ); + + ~DisplayCertDialog(); + + public: + DisplayCertDialogBase *main; + + public: + KVpncConfig *GlobalConfig; + void parseCertData(); + QStringList CertDataList; + +}; + +#endif diff --git a/src/displaycertdialogbase.ui b/src/displaycertdialogbase.ui new file mode 100644 index 0000000..b69b99c --- /dev/null +++ b/src/displaycertdialogbase.ui @@ -0,0 +1,875 @@ + +DisplayCertDialogBase + + + DisplayCertDialogBase + + + + 0 + 0 + 616 + 554 + + + + Certificate data + + + + unnamed + + + + layout131 + + + + unnamed + + + + layout130 + + + + unnamed + + + + CertNameTextLabel + + + + + + + + layout62 + + + + unnamed + + + + textLabel9 + + + Name (CN): + + + + + spacer50 + + + Horizontal + + + Expanding + + + + 31 + 21 + + + + + + + + layout64_2_3 + + + + unnamed + + + + textLabel1_3 + + + Valid to: + + + + + spacer57_2_3 + + + Horizontal + + + Expanding + + + + 40 + 20 + + + + + + + + SerialLineEdit + + + + 350 + 0 + + + + true + + + + + KeySizeLineEdit + + + + 350 + 0 + + + + true + + + + + DomainLineEdit + + + + 350 + 0 + + + + true + + + + + layout64_2_3_2 + + + + unnamed + + + + textLabel1_3_2 + + + Key size: + + + + + spacer57_2_3_2 + + + Horizontal + + + Expanding + + + + 40 + 20 + + + + + + + + EmailLineEdit + + + + 350 + 0 + + + + true + + + + + layout64_2 + + + + unnamed + + + + textLabel1 + + + Issuer: + + + + + spacer57_2 + + + Horizontal + + + Expanding + + + + 40 + 20 + + + + + + + + SubjectLineEdit + + + + 350 + 0 + + + + true + + + + + layout64_2_3_3_2 + + + + unnamed + + + + textLabel1_3_3_2 + + + Subject: + + + + + spacer57_2_3_3_2 + + + Horizontal + + + Expanding + + + + 40 + 20 + + + + + + + + layout109 + + + + unnamed + + + + textLabel18 + + + + 150 + 0 + + + + <b>Data of certificate:</b> + + + AlignVCenter + + + + + spacer89 + + + Horizontal + + + Expanding + + + + 51 + 21 + + + + + + + + ValidToLineEdit + + + + 350 + 0 + + + + true + + + + + layout63 + + + + unnamed + + + + textLabel10 + + + Department (OU): + + + + + spacer51 + + + Horizontal + + + Expanding + + + + 31 + 21 + + + + + + + + layout67 + + + + unnamed + + + + textLabel14 + + + Email (E): + + + + + spacer55 + + + Horizontal + + + Expanding + + + + 40 + 20 + + + + + + + + layout64 + + + + unnamed + + + + textLabel16 + + + Domain: + + + + + spacer57 + + + Horizontal + + + Expanding + + + + 40 + 20 + + + + + + + + layout65 + + + + unnamed + + + + textLabel15 + + + IP address: + + + + + spacer56 + + + Horizontal + + + Expanding + + + + 40 + 20 + + + + + + + + NameLineEdit + + + + 350 + 0 + + + + true + + + + + CompanyLineEdit + + + + 350 + 0 + + + + true + + + + + layout64_2_3_3 + + + + unnamed + + + + textLabel1_3_3 + + + Serial: + + + + + spacer57_2_3_3 + + + Horizontal + + + Expanding + + + + 40 + 20 + + + + + + + + ValidFromLineEdit + + + + 350 + 0 + + + + true + + + + + layout68 + + + + unnamed + + + + textLabel11 + + + Country (C): + + + + + spacer54 + + + Horizontal + + + Expanding + + + + 40 + 20 + + + + + + + + IssuerLineEdit + + + + 350 + 0 + + + + true + + + + + DepartmentLineEdit + + + + 350 + 0 + + + + true + + + + + CountryLineEdit + + + + 350 + 0 + + + + true + + + + + CertTypeTextLabel + + + + + + + + IpLineEdit + + + + 350 + 0 + + + + true + + + + + layout64_2_2 + + + + unnamed + + + + textLabel1_2 + + + Valid from: + + + + + spacer57_2_2 + + + Horizontal + + + Expanding + + + + 40 + 20 + + + + + + + + StateLineEdit + + + + 350 + 0 + + + + true + + + + + layout69 + + + + unnamed + + + + textLabel12 + + + State (ST): + + + + + spacer53 + + + Horizontal + + + Expanding + + + + 51 + 21 + + + + + + + + layout62_2 + + + + unnamed + + + + textLabel9_2 + + + Type: + + + + + spacer50_2 + + + Horizontal + + + Expanding + + + + 31 + 21 + + + + + + + + layout70 + + + + unnamed + + + + textLabel13 + + + Company: + + + + + spacer52 + + + Horizontal + + + Expanding + + + + 40 + 20 + + + + + + + + + + spacer84 + + + Vertical + + + Expanding + + + + 20 + 30 + + + + + + + + + NameLineEdit + DepartmentLineEdit + CompanyLineEdit + StateLineEdit + CountryLineEdit + EmailLineEdit + IpLineEdit + DomainLineEdit + IssuerLineEdit + ValidFromLineEdit + ValidToLineEdit + KeySizeLineEdit + SerialLineEdit + SubjectLineEdit + + + + klineedit.h + klineedit.h + klineedit.h + klineedit.h + klineedit.h + klineedit.h + klineedit.h + klineedit.h + klineedit.h + klineedit.h + klineedit.h + klineedit.h + klineedit.h + klineedit.h + + diff --git a/src/enterpassworddialog.cpp b/src/enterpassworddialog.cpp new file mode 100644 index 0000000..59f74a9 --- /dev/null +++ b/src/enterpassworddialog.cpp @@ -0,0 +1,94 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "enterpassworddialog.h" +#include +#include +#include +#include +#include +#include +#include + +EnterUsernamePasswordDialog::EnterUsernamePasswordDialog(QWidget *parent, const QString& caption,bool askForGrouppassword, bool askForUsername) : KDialogBase( parent, "Enter_account_data", true, caption, + KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, true ) +{ + + this->askForGrouppassword = askForGrouppassword; + this->askForUsername = askForUsername; + + main = new EnterUsernamePasswordDialogBase(this); + setMainWidget(main); + main->setMinimumSize(main->sizeHint()); + + if (!askForGrouppassword) + { + main->PSKLineEdit->hide(); + main->LabelGroupPassword->hide(); + } + + if (!askForUsername) + { + main->UsernameEdit->hide(); + main->LabelUsername->hide(); + } + + if (!askForGrouppassword) + main->SavePskCheckBox->hide(); + if (!askForUsername) + main->SaveUsernameCheckBox->hide(); + + main->textLabel2->setText( QString(""+i18n( "Enter account data:")+"" )); +} + +EnterUsernamePasswordDialog::~ EnterUsernamePasswordDialog() +{ + delete main; +} + + +void EnterUsernamePasswordDialog::accept() +{ + bool ok=true; + + QString msg=""; + if (askForGrouppassword){ + if( main->PSKLineEdit->text().isEmpty()) + msg+="\n- "+i18n("PSK"); + } + + if (askForUsername){ + if(main->UsernameEdit->text().isEmpty()) + msg+="\n- "+i18n("Username"); + + if (main->PasswordEdit->text().isEmpty()) + msg+="\n- "+i18n("Password"); + } + if (!msg.isEmpty()) + { + KMessageBox::sorry( 0, i18n( "All fields must be filled in. Please check:\n%1").arg(msg)); + ok=false; + } + + if (ok) + QDialog::accept(); + + +} diff --git a/src/enterpassworddialog.h b/src/enterpassworddialog.h new file mode 100644 index 0000000..cf94567 --- /dev/null +++ b/src/enterpassworddialog.h @@ -0,0 +1,41 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef __EnterUsernamePasswordDialog__ +#define __EnterUsernamePasswordDialog__ + +#include "enterpassworddialogbase.h" +#include + +class EnterUsernamePasswordDialog : public KDialogBase { + Q_OBJECT +public: + EnterUsernamePasswordDialog(QWidget *parent, const QString& caption,bool askForGrouppassword, bool askForUsername); + ~EnterUsernamePasswordDialog(); + +public slots: + void accept(); + +public: + bool askForGrouppassword; + bool askForUsername; + EnterUsernamePasswordDialogBase *main; +}; + +#endif diff --git a/src/enterpassworddialogbase.ui b/src/enterpassworddialogbase.ui new file mode 100644 index 0000000..516d409 --- /dev/null +++ b/src/enterpassworddialogbase.ui @@ -0,0 +1,335 @@ + +EnterUsernamePasswordDialogBase + + + EnterUsernamePasswordDialogBase + + + + 0 + 0 + 340 + 260 + + + + Enter Account Data + + + + unnamed + + + + layout12 + + + + unnamed + + + + textLabel2 + + + + + + + + layout7 + + + + unnamed + + + + layout6 + + + + unnamed + + + + layout5 + + + + unnamed + + + + layout4 + + + + unnamed + + + + LabelUsername + + + Username: + + + Username for authentication + + + + + LabelGroupPassword + + + Pre-shared key (PSK): + + + re-shared key for authenticat (shared secret) + + + + + spacer13 + + + Horizontal + + + Expanding + + + + 156 + 20 + + + + + + PasswordEdit + + + Password + + + Password for authentication + + + + + IDEdit + + + false + + + Normal + + + IPsec ID + + + + + + + + spacer12 + + + Horizontal + + + Expanding + + + + 88 + 20 + + + + + + LabelPassword + + + Password: + + + Password for authentication + + + + + spacer13_2_2 + + + Horizontal + + + Expanding + + + + 156 + 20 + + + + + + LabelID + + + false + + + ID: + + + Username for authentication + + + + + UsernameEdit + + + Normal + + + Username for authentication + + + + + + + + PSKLineEdit + + + Password + + + Pre-shared key for authenticat (shared secret) + + + Enter here the group password + + + + + spacer13_2 + + + Horizontal + + + Expanding + + + + 156 + 20 + + + + + + + + SaveUsernameCheckBox + + + Save &username + + + Alt+U + + + Save username, shared secret and password <br>in config file or in KWallet + + + + + SavePskCheckBox + + + Save PSK + + + + + + Save username, shared secret and password <br>in config file or in KWallet + + + + + SavePasswordCheckBox + + + Save password + + + + + + Save username, shared secret and password <br>in config file or in KWallet + + + + + + + spacer23 + + + Vertical + + + Expanding + + + + 20 + 16 + + + + + + + + spacer22 + + + Horizontal + + + Expanding + + + + 16 + 21 + + + + + + + + + + + UsernameEdit + PSKLineEdit + PasswordEdit + + + diff --git a/src/enterxauthinteractivepasscodedialog.cpp b/src/enterxauthinteractivepasscodedialog.cpp new file mode 100644 index 0000000..9ea8562 --- /dev/null +++ b/src/enterxauthinteractivepasscodedialog.cpp @@ -0,0 +1,53 @@ +/*************************************************************************** +* Copyright (C) 2006 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ + +#include "enterxauthinteractivepasscodedialog.h" +#include +#include +#include +#include +#include +#include + +EnterXauthInteractivePasscodeDialog::EnterXauthInteractivePasscodeDialog( QWidget *parent, bool allowEmptyPassword ) : KDialogBase( parent, "Enter Xauth interactive passcode", true, "Enter Xauth interactive passcode", KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, true ) { + Password = ""; + this->allowEmptyPassword = allowEmptyPassword; + main = new EnterXauthInteractivePasscodeDialogBase( this ); + setMainWidget( main ); + main->setMinimumSize( main->sizeHint() ); +} + +EnterXauthInteractivePasscodeDialog::~ EnterXauthInteractivePasscodeDialog() { + delete main; +} + + +void EnterXauthInteractivePasscodeDialog::accept() { + bool ok = true; + if ( main->PasswordEdit->text().isEmpty() && !allowEmptyPassword ) { + KMessageBox::sorry( 0, i18n( "Passcode must be filled in!" ) ); + ok = false; + } + + if ( ok ) { + Password = main->PasswordEdit->text(); + QDialog::accept(); + } +} diff --git a/src/enterxauthinteractivepasscodedialog.h b/src/enterxauthinteractivepasscodedialog.h new file mode 100644 index 0000000..e11bf35 --- /dev/null +++ b/src/enterxauthinteractivepasscodedialog.h @@ -0,0 +1,41 @@ +/*************************************************************************** + * Copyright (C) 2006 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef __EnterXauthInteractivePasscodeDialog__ +#define __EnterXauthInteractivePasscodeDialog__ + +#include "enterxauthinteractivepasscodedialogbase.h" +#include + +class EnterXauthInteractivePasscodeDialog : public KDialogBase { + Q_OBJECT +public: + EnterXauthInteractivePasscodeDialog(QWidget *parent, bool allowEmptyPassword=false); + ~EnterXauthInteractivePasscodeDialog(); + +public slots: + void accept(); + +public: + QString Password; + bool allowEmptyPassword; + EnterXauthInteractivePasscodeDialogBase *main; +}; + +#endif diff --git a/src/enterxauthinteractivepasscodedialogbase.ui b/src/enterxauthinteractivepasscodedialogbase.ui new file mode 100644 index 0000000..55ffcd9 --- /dev/null +++ b/src/enterxauthinteractivepasscodedialogbase.ui @@ -0,0 +1,158 @@ + +EnterXauthInteractivePasscodeDialogBase + + + EnterXauthInteractivePasscodeDialogBase + + + + 0 + 0 + 579 + 156 + + + + Enter Xauth interactive passcode + + + + unnamed + + + + layout138 + + + + unnamed + + + + layout137 + + + + unnamed + + + + SavePasswordCheckBox + + + Save pass&word + + + Alt+W + + + + + layout136 + + + + unnamed + + + + DescriptionLabel + + + Enter the Xauth interactive passcode + + + + + spacer110 + + + Horizontal + + + Expanding + + + + 151 + 21 + + + + + + + + layout5 + + + + unnamed + + + + spacer13 + + + Horizontal + + + Expanding + + + + 83 + 20 + + + + + + PasswordEdit + + + Password + + + Xauth passcode for authentication + + + + + LabelPassword + + + Passcode: + + + + + + + + + spacer109 + + + Vertical + + + Expanding + + + + 21 + 45 + + + + + + + + + PasswordEdit + SavePasswordCheckBox + + + diff --git a/src/eventsrc b/src/eventsrc new file mode 100644 index 0000000..14c5b53 --- /dev/null +++ b/src/eventsrc @@ -0,0 +1,120 @@ +[!Global!] +Name=KVpnc +Name[xx]=xxKVpncxx +IconName=kvpnc +Comment=KVpnc +Comment[xx]=xxKVpncxx + +[connection established] +Name=Connection established +Name[da]=Forbindelse etableret +Name[de]=Verbindung aufgebaut +Name[es]=Conexión establecida +Name[ga]=Nasc déanta +Name[pt]=Ligação estabelecida +Name[sv]=Anslutning upprättad +Name[xx]=xxConnection establishedxx +Comment=The connection has now established +Comment[da]=Forbindelsen er nu oprettet +Comment[de]=Die Verbindung wurde aufgebaut +Comment[es]=La conexión está establecida +Comment[pt]=A ligação foi estabelecida +Comment[sv]=Anslutningen har nu upprättats +Comment[xx]=xxThe connection has now establishedxx +default_sound= +default_presentation=16 +nopresentation=0 +level=1 + +[connection finished] +Name=Connection finished +Name[da]=Forbindelse afsluttet +Name[de]=Verbindung beendet +Name[es]=Conexión finalizada +Name[pt]=Ligação terminada +Name[sv]=Anslutning avslutad +Name[xx]=xxConnection finishedxx +Comment=The connection has now finished +Comment[da]=Forbindelsen er nu afsluttet +Comment[de]=Die Verbindung wurde beendet +Comment[es]=La conexión ha finalizado +Comment[pt]=A ligação terminou +Comment[sv]=Anslutningen har nu avslutats +Comment[xx]=xxThe connection has now finishedxx +default_sound= +default_presentation=16 +nopresentation=0 +level=1 + +[connection lost] +Name=Connection lost +Name[da]=Forbindelse gÃ¥et tabt +Name[de]=Verbindung verloren +Name[es]=Conexión perdida +Name[pt]=Ligação perdida +Name[sv]=Anslutning förlorad +Name[xx]=xxConnection lostxx +Comment=The connection has now lost +Comment[da]=Forbindelsen er afsluttet +Comment[de]=Die Verbindung wurde verloren +Comment[es]=La conexión ha finalizado +Comment[pt]=A ligação terminou de forma abrupta +Comment[sv]=Anslutningen har nu avslutats +Comment[xx]=xxThe connection has now finishedxx +default_sound= +default_presentation=16 +nopresentation=0 +level=1 + +[connect try canceled] +Name=Connection try canceled +Name[de]=Verbindungsaufbau abgebrochen +Name[xx]=xxConnection try canceledtxx +Comment=The connection try was canceled +Comment[de]=Verbindungsaufbau wurde abgebrochen +Comment[xx]=xxThe connection try was canceledxx +default_sound= +default_presentation=16 +nopresentation=0 +level=1 + +[ping success] +Name=Ping sucess +Name[da]=Ping lykkedes +Name[de]=Ping erfolgreich +Name[es]=Ping correcto +Name[pt]=Sucesso no 'ping' +Name[sv]=Ping lyckades +Name[xx]=xxPing sucessxx +Comment=Ping was successful +Comment[da]=Ping lykkedes +Comment[de]=Pingtest war erfolgreich +Comment[es]=Ping correcto +Comment[pt]=O 'ping' foi bem sucedido +Comment[sv]=Ping lyckades +Comment[xx]=xxPing was successfulxx +default_sound= +default_presentation=16 +nopresentation=0 +level=1 + +[ping failed] +Name=Ping failed +Name[da]=Ping mislykkedes +Name[de]=Ping fehlgeschlagen +Name[es]=Falló el Ping +Name[pt]=Erro no 'ping' +Name[sv]=Ping misslyckades +Name[xx]=xxPing failedxx +Comment=The ping was not sucessful +Comment[da]=Ping lykkedes ikke +Comment[de]=Pingtest ist fehlgeschlagen +Comment[es]=El ping no tuvo éxito +Comment[pt]=A operação de 'ping' não correu bem +Comment[sv]=Ping lyckades inte +Comment[xx]=xxThe ping was not sucessfulxx +default_sound= +default_presentation=16 +nopresentation=0 +level=1 + diff --git a/src/generateopenvpnkeydialog.cpp b/src/generateopenvpnkeydialog.cpp new file mode 100644 index 0000000..4315668 --- /dev/null +++ b/src/generateopenvpnkeydialog.cpp @@ -0,0 +1,134 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "generateopenvpnkeydialog.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +// +GenerateOpenvpnKeyDialog::GenerateOpenvpnKeyDialog(KVpncConfig *GlobalConfig,QWidget *parent, const QString& caption) + : KDialogBase( parent, "Import_Cisco_PCF_profile", true, caption, + KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, true ) +{ + this->GlobalConfig=GlobalConfig; + filename = ""; + genOk = false; + main = new GenerateOpenvpnKeyDialogBase(this); + setMainWidget(main); + //main->setMinimumSize(main->sizeHint()); + + main->FilenameUrlrequester->setFilter( "*.key" ); + +} + +GenerateOpenvpnKeyDialog::~GenerateOpenvpnKeyDialog() +{ +// delete generateOpenvpnKeyProcess; + delete main; +} + +void GenerateOpenvpnKeyDialog::accept() +{ + + //filename="/etc/CiscoSystemsVPNClient/Profiles/hs_harz.pcf"; + filename = main->FilenameUrlrequester->url(); + if ( !filename.isEmpty() ) + { + canAccept(); + } + + else + { + GlobalConfig->appendLogEntry( i18n("GenerateOpenvpnKeyDialog: empty file name"), GlobalConfig->error); + KMessageBox::sorry( 0, i18n( "File name can not be empty!" ), i18n( "Empty File Name" ) ); + } +} + + +void GenerateOpenvpnKeyDialog::canAccept() +{ + + /* + QFile f( filename ); + if ( !f.exists() ) + { + KMessageBox::information( 0, i18n( "File not found." ), i18n( "No fFile" ) ); + + // emit progress( 100 ); + return ; + }*/ + generateOpenvpnKeyProcess = new QProcess(this); + generateOpenvpnKeyProcess->addArgument(GlobalConfig->pathToOpenvpn); + generateOpenvpnKeyProcess->addArgument("--genkey"); + generateOpenvpnKeyProcess->addArgument("--secret"); + generateOpenvpnKeyProcess->addArgument(filename); + + connect( generateOpenvpnKeyProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErr() ) ); + connect( generateOpenvpnKeyProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdErr() ) ); + if ( !generateOpenvpnKeyProcess->start(env) ) + { + KMessageBox::sorry( this, i18n( "Generating of %1 key failed!" ).arg( "openvpn" ) ); + GlobalConfig->appendLogEntry(i18n( "\"%1\" start failed!" ).arg( "openvpn" ),GlobalConfig->error); + } + else + { + GlobalConfig->appendLogEntry( i18n("Generating of %1 key was successful.").arg("openvpn"), GlobalConfig->info); + genOk = true; + } + + while (generateOpenvpnKeyProcess->isRunning()) + { + sleep(1); + } + disconnect( generateOpenvpnKeyProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErr() ) ); + disconnect( generateOpenvpnKeyProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdErr() ) ); + delete generateOpenvpnKeyProcess; + generateOpenvpnKeyProcess = 0L; + if (genOk) + KMessageBox::information( this, i18n( "Generating the key in \"%1\" was successful." ).arg( filename ) ); + else + KMessageBox::sorry( this, i18n( "Generating the key in \"%1\" failed!" ).arg( filename ) ); + //std::cout << "accept" << std::endl; + QDialog::accept(); +} + +void GenerateOpenvpnKeyDialog::readStdErr() +{ + // while ( generateOpenvpnKeyProcess->canReadLineStderr() ) { + // ProcessMsg_connect = generateOpenvpnKeyProcess->readLineStderr(); + QString ProcessMsg_connect = QString( generateOpenvpnKeyProcess->readStderr() ); + if (ProcessMsg_connect.isEmpty()) + ProcessMsg_connect = QString( generateOpenvpnKeyProcess->readStdout() ); + + if ( ProcessMsg_connect.find( "Permission denied", 0 , FALSE ) > -1 ) + { + if (GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry( "[openvpn genkey err] " + ProcessMsg_connect, GlobalConfig->error ); + genOk = false; + //} + } +} diff --git a/src/generateopenvpnkeydialog.h b/src/generateopenvpnkeydialog.h new file mode 100644 index 0000000..919ad9f --- /dev/null +++ b/src/generateopenvpnkeydialog.h @@ -0,0 +1,54 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef GENERATEOPENVPNKEYDIALOG_H +#define GENERATEOPENVPNKEYDIALOG_H + +#include +#include "generateopenvpnkeydialogbase.h" +#include +#include "kvpncconfig.h" +#include + +/** +@author Christoph Thielecke +*/ +class GenerateOpenvpnKeyDialog : public KDialogBase +{ +Q_OBJECT +public: + GenerateOpenvpnKeyDialog(KVpncConfig *GlobalConfig,QWidget *parent, const QString& caption); + + ~GenerateOpenvpnKeyDialog(); + void canAccept(); + QString filename; + bool genOk; + GenerateOpenvpnKeyDialogBase *main; + +public slots: + void accept(); + void readStdErr(); + +private: + QProcess *generateOpenvpnKeyProcess; + KVpncConfig *GlobalConfig; + QStringList *env; +}; + +#endif diff --git a/src/generateopenvpnkeydialogbase.ui b/src/generateopenvpnkeydialogbase.ui new file mode 100644 index 0000000..438c55a --- /dev/null +++ b/src/generateopenvpnkeydialogbase.ui @@ -0,0 +1,73 @@ + +GenerateOpenvpnKeyDialogBase +Christoph Thielecke + + + GenerateOpenvpnKeyDialogBase + + + + 0 + 0 + 416 + 59 + + + + Generate Key + + + + unnamed + + + + layout3 + + + + unnamed + + + + layout2 + + + + unnamed + + + + textLabel1 + + + File name: + + + + + FilenameUrlrequester + + + Filename to store key + + + This is a file where the key should be stored. <br>This file must be used on the remote side too. + + + + + + + + + + canAccept() + + + + kurlrequester.h + klineedit.h + kpushbutton.h + + diff --git a/src/helpdialog.cpp b/src/helpdialog.cpp new file mode 100644 index 0000000..a94e960 --- /dev/null +++ b/src/helpdialog.cpp @@ -0,0 +1,28 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "helpdialog.h" + +HelpDialog::HelpDialog() + : HelpDialogBase() {} + + +HelpDialog::~HelpDialog() {} + + diff --git a/src/helpdialog.h b/src/helpdialog.h new file mode 100644 index 0000000..1105b0a --- /dev/null +++ b/src/helpdialog.h @@ -0,0 +1,36 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef HELPDIALOG_H +#define HELPDIALOG_H + +#include "helpdialogbase.h" + +/** +@author Christoph Thielecke +*/ +class HelpDialog : public HelpDialogBase { +public: + HelpDialog(); + + ~HelpDialog(); + +}; + +#endif diff --git a/src/helpdialogbase.ui b/src/helpdialogbase.ui new file mode 100644 index 0000000..3471810 --- /dev/null +++ b/src/helpdialogbase.ui @@ -0,0 +1,124 @@ + +HelpDialogBase + + + HelpDialogBase + + + + 0 + 0 + 800 + 604 + + + + + 800 + 600 + + + + Help + + + true + + + + unnamed + + + + kTextEdit1 + + + <html><head><meta name="qrichtext" content="1" /></head><body style="font-size:12pt;font-family:helvetica"> +<p style="margin-top:18px"><a name="topic"><span style="font-size:24pt;font-weight:600">Topics</span></a></p> +<p style="margin-top:16px"><a href="#usage"><span style="font-size:18pt;font-weight:600">1. Usage</span></a></p> +<p style="margin-top:14px"><a href="#connect"><span style="font-size:14pt;font-weight:600">1.1 Connect</span></a></p> +<p style="margin-top:14px"><a href="#disconnect"><span style="font-size:14pt;font-weight:600">1.2 Disconnect</span></a></p> +<p style="margin-top:16px"><a href="#external_help"><span style="font-size:18pt;font-weight:600">2. Getting external help</span></a></p> +<p style="margin-top:14px"><a href="#homepage"><span style="font-size:14pt;font-weight:600">2.1 Homepage</span></a></p> +<p style="margin-top:14px"><a href="#submitting_bugs"><span style="font-size:14pt;font-weight:600">2.2 Submitting bugs</span></a></p> +<p style="margin-top:14px"><a href="#author"><span style="font-size:14pt;font-weight:600">2.3 Author</span></a></p> +<p style="margin-top:16px"><a name="usage"><span style="font-size:18pt;font-weight:600">1. Usage</span></a></p> +<p style="margin-top:14px"><a name="connect"><span style="font-size:14pt;font-weight:600">1.1 Connect</span></a></p> +<p>Start kvpnc and if vpnc-connect/vpnc-disconnect is not installed in /usr/sbin change it in settings. Click on &quot;New profile...&quot; to add a new profile. Enter the new Name in the upcoming dialog, fill in the empty fields and save profile by clicking on &quot;Save profile...&quot;. After enter your VPN data, click on &quot;connect&quot; to connect to your VPN server. By default, kvpnc minimizes into kicker dock after sucessfull connect. <a href="#topic">back to top</a> </p> +<p style="margin-top:14px"><a name="disconnect"><span style="font-size:14pt;font-weight:600">1.2 Disconnect</span></a></p> +<p>To disconnect, click on kicker dock and kvpnc main window will be restored. Then click on &quot;disconnect&quot;. You can also use toolbar icons or menu entries in kicker dock context menu. <a href="#topic">back to top</a> </p> +<p style="margin-top:16px"><a name="external_help"><span style="font-size:18pt;font-weight:600">2. Getting external help</span></a></p> +<p style="margin-top:14px"><a name="homepage"><span style="font-size:14pt;font-weight:600">2.1 Homepage</span></a></p> +<p>Go to <a href="http://home.gna.org/kvpnc/">http://home.gna.org/kvpnc/</a> for new releases, contacts, etc. <a href="#topic">back to top</a> </p> +<p style="margin-top:14px"><a name="sumbitting_bugs"><span style="font-size:14pt;font-weight:600">2.2 Submitting bugs</span></a></p> +<p>Go to <a href="https://gna.org/bugs/?group=kvpnc">https://gna.org/bugs/?group=kvpnc</a> for submitting new bugs or look for open bugs. <a href="#topic">back to top</a> </p> +<p style="margin-top:14px"><a name="author"><span style="font-size:14pt;font-weight:600">2.3 Author</span></a></p> +<p>Send a mail to Christoph Thielecke (<a href="u15119@hs-harz.de">u15119@hs-harz.de</a>) if you have questions, suggestions or wishes. <a href="#topic">back to top</a></p> +</body></html> + + + + + Layout1 + + + + unnamed + + + 0 + + + 6 + + + + Horizontal Spacing2 + + + Horizontal + + + Expanding + + + + 20 + 20 + + + + + + buttonClose + + + &Close + + + true + + + true + + + Close dialog + + + + + + + + + buttonClose + clicked() + HelpDialogBase + accept() + + + + closeClicked() + + + diff --git a/src/icons/Makefile.am b/src/icons/Makefile.am new file mode 100644 index 0000000..2dadc2c --- /dev/null +++ b/src/icons/Makefile.am @@ -0,0 +1,5 @@ +KDE_ICON = kvpnc +appicondir = $(kde_datadir)/kvpnc/icons +appicon_ICON = AUTO +appicon_KDEICON = hi16-action-fritzboximport.png hi32-action-fritzboximport.png \ + lo16-action-fritzboximport.png lo32-action-fritzboximport.png diff --git a/src/icons/hi16-action-cert.png b/src/icons/hi16-action-cert.png new file mode 100644 index 0000000..7ba0714 Binary files /dev/null and b/src/icons/hi16-action-cert.png differ diff --git a/src/icons/hi16-action-certimport.png b/src/icons/hi16-action-certimport.png new file mode 100644 index 0000000..62bc03e Binary files /dev/null and b/src/icons/hi16-action-certimport.png differ diff --git a/src/icons/hi16-action-cisco.png b/src/icons/hi16-action-cisco.png new file mode 100644 index 0000000..efb99fd Binary files /dev/null and b/src/icons/hi16-action-cisco.png differ diff --git a/src/icons/hi16-action-connected.png b/src/icons/hi16-action-connected.png new file mode 100644 index 0000000..2f45810 Binary files /dev/null and b/src/icons/hi16-action-connected.png differ diff --git a/src/icons/hi16-action-connecting.png b/src/icons/hi16-action-connecting.png new file mode 100644 index 0000000..38f39bb Binary files /dev/null and b/src/icons/hi16-action-connecting.png differ diff --git a/src/icons/hi16-action-disconnected.png b/src/icons/hi16-action-disconnected.png new file mode 100644 index 0000000..36ecf52 Binary files /dev/null and b/src/icons/hi16-action-disconnected.png differ diff --git a/src/icons/hi16-action-donate.png b/src/icons/hi16-action-donate.png new file mode 100644 index 0000000..ffb9ace Binary files /dev/null and b/src/icons/hi16-action-donate.png differ diff --git a/src/icons/hi16-action-fritzboximport.png b/src/icons/hi16-action-fritzboximport.png new file mode 100644 index 0000000..9dc3b8b Binary files /dev/null and b/src/icons/hi16-action-fritzboximport.png differ diff --git a/src/icons/hi16-action-kame.png b/src/icons/hi16-action-kame.png new file mode 100644 index 0000000..5b28b0f Binary files /dev/null and b/src/icons/hi16-action-kame.png differ diff --git a/src/icons/hi16-action-openssh.png b/src/icons/hi16-action-openssh.png new file mode 100644 index 0000000..c226930 Binary files /dev/null and b/src/icons/hi16-action-openssh.png differ diff --git a/src/icons/hi16-action-openswan.png b/src/icons/hi16-action-openswan.png new file mode 100644 index 0000000..56582cc Binary files /dev/null and b/src/icons/hi16-action-openswan.png differ diff --git a/src/icons/hi16-action-openvpn.png b/src/icons/hi16-action-openvpn.png new file mode 100644 index 0000000..d0eb69f Binary files /dev/null and b/src/icons/hi16-action-openvpn.png differ diff --git a/src/icons/hi16-action-openvpnimport.png b/src/icons/hi16-action-openvpnimport.png new file mode 100644 index 0000000..61d4e2c Binary files /dev/null and b/src/icons/hi16-action-openvpnimport.png differ diff --git a/src/icons/hi16-action-pcfimport.png b/src/icons/hi16-action-pcfimport.png new file mode 100644 index 0000000..6f4eb32 Binary files /dev/null and b/src/icons/hi16-action-pcfimport.png differ diff --git a/src/icons/hi16-action-profilenew.png b/src/icons/hi16-action-profilenew.png new file mode 100644 index 0000000..d3fe552 Binary files /dev/null and b/src/icons/hi16-action-profilenew.png differ diff --git a/src/icons/hi16-action-route.png b/src/icons/hi16-action-route.png new file mode 100644 index 0000000..b694497 Binary files /dev/null and b/src/icons/hi16-action-route.png differ diff --git a/src/icons/hi16-action-smartcard.png b/src/icons/hi16-action-smartcard.png new file mode 100644 index 0000000..b65f183 Binary files /dev/null and b/src/icons/hi16-action-smartcard.png differ diff --git a/src/icons/hi16-action-user.png b/src/icons/hi16-action-user.png new file mode 100644 index 0000000..83e5b31 Binary files /dev/null and b/src/icons/hi16-action-user.png differ diff --git a/src/icons/hi16-app-kvpnc.png b/src/icons/hi16-app-kvpnc.png new file mode 100644 index 0000000..5512627 Binary files /dev/null and b/src/icons/hi16-app-kvpnc.png differ diff --git a/src/icons/hi22-action-certimport.png b/src/icons/hi22-action-certimport.png new file mode 100644 index 0000000..44fc739 Binary files /dev/null and b/src/icons/hi22-action-certimport.png differ diff --git a/src/icons/hi22-action-cisco.png b/src/icons/hi22-action-cisco.png new file mode 100644 index 0000000..55aab86 Binary files /dev/null and b/src/icons/hi22-action-cisco.png differ diff --git a/src/icons/hi22-action-connected.png b/src/icons/hi22-action-connected.png new file mode 100644 index 0000000..45940ed Binary files /dev/null and b/src/icons/hi22-action-connected.png differ diff --git a/src/icons/hi22-action-connecting.png b/src/icons/hi22-action-connecting.png new file mode 100644 index 0000000..a229e02 Binary files /dev/null and b/src/icons/hi22-action-connecting.png differ diff --git a/src/icons/hi22-action-disconnected.png b/src/icons/hi22-action-disconnected.png new file mode 100644 index 0000000..a2ebbe3 Binary files /dev/null and b/src/icons/hi22-action-disconnected.png differ diff --git a/src/icons/hi22-action-donate.png b/src/icons/hi22-action-donate.png new file mode 100644 index 0000000..e43e574 Binary files /dev/null and b/src/icons/hi22-action-donate.png differ diff --git a/src/icons/hi22-action-kame.png b/src/icons/hi22-action-kame.png new file mode 100644 index 0000000..5b28b0f Binary files /dev/null and b/src/icons/hi22-action-kame.png differ diff --git a/src/icons/hi22-action-openssh.png b/src/icons/hi22-action-openssh.png new file mode 100644 index 0000000..5084a58 Binary files /dev/null and b/src/icons/hi22-action-openssh.png differ diff --git a/src/icons/hi22-action-openswan.png b/src/icons/hi22-action-openswan.png new file mode 100644 index 0000000..4b7c2e7 Binary files /dev/null and b/src/icons/hi22-action-openswan.png differ diff --git a/src/icons/hi22-action-openvpn.png b/src/icons/hi22-action-openvpn.png new file mode 100644 index 0000000..3380991 Binary files /dev/null and b/src/icons/hi22-action-openvpn.png differ diff --git a/src/icons/hi22-action-openvpnimport.png b/src/icons/hi22-action-openvpnimport.png new file mode 100644 index 0000000..9b2204e Binary files /dev/null and b/src/icons/hi22-action-openvpnimport.png differ diff --git a/src/icons/hi22-action-pcfimport.png b/src/icons/hi22-action-pcfimport.png new file mode 100644 index 0000000..925a6f0 Binary files /dev/null and b/src/icons/hi22-action-pcfimport.png differ diff --git a/src/icons/hi22-action-profilenew.png b/src/icons/hi22-action-profilenew.png new file mode 100644 index 0000000..cc82876 Binary files /dev/null and b/src/icons/hi22-action-profilenew.png differ diff --git a/src/icons/hi22-action-route.png b/src/icons/hi22-action-route.png new file mode 100644 index 0000000..3641052 Binary files /dev/null and b/src/icons/hi22-action-route.png differ diff --git a/src/icons/hi22-action-smartcard.png b/src/icons/hi22-action-smartcard.png new file mode 100644 index 0000000..f965807 Binary files /dev/null and b/src/icons/hi22-action-smartcard.png differ diff --git a/src/icons/hi22-action-user.png b/src/icons/hi22-action-user.png new file mode 100644 index 0000000..6b71537 Binary files /dev/null and b/src/icons/hi22-action-user.png differ diff --git a/src/icons/hi22-app-kvpnc.png b/src/icons/hi22-app-kvpnc.png new file mode 100644 index 0000000..ee064a0 Binary files /dev/null and b/src/icons/hi22-app-kvpnc.png differ diff --git a/src/icons/hi32-action-connected.png b/src/icons/hi32-action-connected.png new file mode 100644 index 0000000..7e157e1 Binary files /dev/null and b/src/icons/hi32-action-connected.png differ diff --git a/src/icons/hi32-action-connecting.png b/src/icons/hi32-action-connecting.png new file mode 100644 index 0000000..0b721c7 Binary files /dev/null and b/src/icons/hi32-action-connecting.png differ diff --git a/src/icons/hi32-action-disconnected.png b/src/icons/hi32-action-disconnected.png new file mode 100644 index 0000000..84faa9d Binary files /dev/null and b/src/icons/hi32-action-disconnected.png differ diff --git a/src/icons/hi32-action-fritzboximport.png b/src/icons/hi32-action-fritzboximport.png new file mode 100644 index 0000000..0b3b902 Binary files /dev/null and b/src/icons/hi32-action-fritzboximport.png differ diff --git a/src/icons/hi32-action-openssh.png b/src/icons/hi32-action-openssh.png new file mode 100644 index 0000000..6a2323e Binary files /dev/null and b/src/icons/hi32-action-openssh.png differ diff --git a/src/icons/hi32-action-openswan.png b/src/icons/hi32-action-openswan.png new file mode 100644 index 0000000..d865611 Binary files /dev/null and b/src/icons/hi32-action-openswan.png differ diff --git a/src/icons/hi32-action-openvpn.png b/src/icons/hi32-action-openvpn.png new file mode 100644 index 0000000..7685341 Binary files /dev/null and b/src/icons/hi32-action-openvpn.png differ diff --git a/src/icons/hi32-action-smartcard.png b/src/icons/hi32-action-smartcard.png new file mode 100644 index 0000000..cf05b70 Binary files /dev/null and b/src/icons/hi32-action-smartcard.png differ diff --git a/src/icons/hi32-app-kvpnc.png b/src/icons/hi32-app-kvpnc.png new file mode 100644 index 0000000..c96d6d7 Binary files /dev/null and b/src/icons/hi32-app-kvpnc.png differ diff --git a/src/icons/hi48-action-openvpn.png b/src/icons/hi48-action-openvpn.png new file mode 100644 index 0000000..3f21951 Binary files /dev/null and b/src/icons/hi48-action-openvpn.png differ diff --git a/src/icons/hi64-action-openswan.png b/src/icons/hi64-action-openswan.png new file mode 100644 index 0000000..598f2f2 Binary files /dev/null and b/src/icons/hi64-action-openswan.png differ diff --git a/src/icons/hi64-action-smartcard.png b/src/icons/hi64-action-smartcard.png new file mode 100644 index 0000000..6ecc5f3 Binary files /dev/null and b/src/icons/hi64-action-smartcard.png differ diff --git a/src/icons/lo16-action-certimport.png b/src/icons/lo16-action-certimport.png new file mode 100644 index 0000000..8139c1f Binary files /dev/null and b/src/icons/lo16-action-certimport.png differ diff --git a/src/icons/lo16-action-cisco.png b/src/icons/lo16-action-cisco.png new file mode 100644 index 0000000..efb99fd Binary files /dev/null and b/src/icons/lo16-action-cisco.png differ diff --git a/src/icons/lo16-action-connected.png b/src/icons/lo16-action-connected.png new file mode 100644 index 0000000..2f45810 Binary files /dev/null and b/src/icons/lo16-action-connected.png differ diff --git a/src/icons/lo16-action-connecting.png b/src/icons/lo16-action-connecting.png new file mode 100644 index 0000000..38f39bb Binary files /dev/null and b/src/icons/lo16-action-connecting.png differ diff --git a/src/icons/lo16-action-disconnected.png b/src/icons/lo16-action-disconnected.png new file mode 100644 index 0000000..36ecf52 Binary files /dev/null and b/src/icons/lo16-action-disconnected.png differ diff --git a/src/icons/lo16-action-donate.png b/src/icons/lo16-action-donate.png new file mode 100644 index 0000000..ffb9ace Binary files /dev/null and b/src/icons/lo16-action-donate.png differ diff --git a/src/icons/lo16-action-fritzboximport.png b/src/icons/lo16-action-fritzboximport.png new file mode 100644 index 0000000..952f62d Binary files /dev/null and b/src/icons/lo16-action-fritzboximport.png differ diff --git a/src/icons/lo16-action-kame.png b/src/icons/lo16-action-kame.png new file mode 100644 index 0000000..5b28b0f Binary files /dev/null and b/src/icons/lo16-action-kame.png differ diff --git a/src/icons/lo16-action-openssh.png b/src/icons/lo16-action-openssh.png new file mode 100644 index 0000000..c226930 Binary files /dev/null and b/src/icons/lo16-action-openssh.png differ diff --git a/src/icons/lo16-action-openswan.png b/src/icons/lo16-action-openswan.png new file mode 100644 index 0000000..56582cc Binary files /dev/null and b/src/icons/lo16-action-openswan.png differ diff --git a/src/icons/lo16-action-openvpn.png b/src/icons/lo16-action-openvpn.png new file mode 100644 index 0000000..d0eb69f Binary files /dev/null and b/src/icons/lo16-action-openvpn.png differ diff --git a/src/icons/lo16-action-openvpnimport.png b/src/icons/lo16-action-openvpnimport.png new file mode 100644 index 0000000..61d4e2c Binary files /dev/null and b/src/icons/lo16-action-openvpnimport.png differ diff --git a/src/icons/lo16-action-pcfimport.png b/src/icons/lo16-action-pcfimport.png new file mode 100644 index 0000000..6f4eb32 Binary files /dev/null and b/src/icons/lo16-action-pcfimport.png differ diff --git a/src/icons/lo16-action-profilenew.png b/src/icons/lo16-action-profilenew.png new file mode 100644 index 0000000..d3fe552 Binary files /dev/null and b/src/icons/lo16-action-profilenew.png differ diff --git a/src/icons/lo16-action-route.png b/src/icons/lo16-action-route.png new file mode 100644 index 0000000..b694497 Binary files /dev/null and b/src/icons/lo16-action-route.png differ diff --git a/src/icons/lo16-action-smartcard.png b/src/icons/lo16-action-smartcard.png new file mode 100644 index 0000000..b65f183 Binary files /dev/null and b/src/icons/lo16-action-smartcard.png differ diff --git a/src/icons/lo16-action-user.png b/src/icons/lo16-action-user.png new file mode 100644 index 0000000..83e5b31 Binary files /dev/null and b/src/icons/lo16-action-user.png differ diff --git a/src/icons/lo16-app-kvpnc.png b/src/icons/lo16-app-kvpnc.png new file mode 100644 index 0000000..5512627 Binary files /dev/null and b/src/icons/lo16-app-kvpnc.png differ diff --git a/src/icons/lo22-action-certimport.png b/src/icons/lo22-action-certimport.png new file mode 100644 index 0000000..8c76180 Binary files /dev/null and b/src/icons/lo22-action-certimport.png differ diff --git a/src/icons/lo22-action-cisco.png b/src/icons/lo22-action-cisco.png new file mode 100644 index 0000000..55aab86 Binary files /dev/null and b/src/icons/lo22-action-cisco.png differ diff --git a/src/icons/lo22-action-connected.png b/src/icons/lo22-action-connected.png new file mode 100644 index 0000000..45940ed Binary files /dev/null and b/src/icons/lo22-action-connected.png differ diff --git a/src/icons/lo22-action-connecting.png b/src/icons/lo22-action-connecting.png new file mode 100644 index 0000000..7c0c023 Binary files /dev/null and b/src/icons/lo22-action-connecting.png differ diff --git a/src/icons/lo22-action-disconnected.png b/src/icons/lo22-action-disconnected.png new file mode 100644 index 0000000..a2ebbe3 Binary files /dev/null and b/src/icons/lo22-action-disconnected.png differ diff --git a/src/icons/lo22-action-donate.png b/src/icons/lo22-action-donate.png new file mode 100644 index 0000000..e43e574 Binary files /dev/null and b/src/icons/lo22-action-donate.png differ diff --git a/src/icons/lo22-action-kame.png b/src/icons/lo22-action-kame.png new file mode 100644 index 0000000..5b28b0f Binary files /dev/null and b/src/icons/lo22-action-kame.png differ diff --git a/src/icons/lo22-action-openssh.png b/src/icons/lo22-action-openssh.png new file mode 100644 index 0000000..5084a58 Binary files /dev/null and b/src/icons/lo22-action-openssh.png differ diff --git a/src/icons/lo22-action-openswan.png b/src/icons/lo22-action-openswan.png new file mode 100644 index 0000000..4b7c2e7 Binary files /dev/null and b/src/icons/lo22-action-openswan.png differ diff --git a/src/icons/lo22-action-openvpn.png b/src/icons/lo22-action-openvpn.png new file mode 100644 index 0000000..3380991 Binary files /dev/null and b/src/icons/lo22-action-openvpn.png differ diff --git a/src/icons/lo22-action-openvpnimport.png b/src/icons/lo22-action-openvpnimport.png new file mode 100644 index 0000000..9b2204e Binary files /dev/null and b/src/icons/lo22-action-openvpnimport.png differ diff --git a/src/icons/lo22-action-pcfimport.png b/src/icons/lo22-action-pcfimport.png new file mode 100644 index 0000000..925a6f0 Binary files /dev/null and b/src/icons/lo22-action-pcfimport.png differ diff --git a/src/icons/lo22-action-profilenew.png b/src/icons/lo22-action-profilenew.png new file mode 100644 index 0000000..cc82876 Binary files /dev/null and b/src/icons/lo22-action-profilenew.png differ diff --git a/src/icons/lo22-action-route.png b/src/icons/lo22-action-route.png new file mode 100644 index 0000000..3641052 Binary files /dev/null and b/src/icons/lo22-action-route.png differ diff --git a/src/icons/lo22-action-smartcard.png b/src/icons/lo22-action-smartcard.png new file mode 100644 index 0000000..f965807 Binary files /dev/null and b/src/icons/lo22-action-smartcard.png differ diff --git a/src/icons/lo22-action-user.png b/src/icons/lo22-action-user.png new file mode 100644 index 0000000..6b71537 Binary files /dev/null and b/src/icons/lo22-action-user.png differ diff --git a/src/icons/lo22-app-kvpnc.png b/src/icons/lo22-app-kvpnc.png new file mode 100644 index 0000000..ee064a0 Binary files /dev/null and b/src/icons/lo22-app-kvpnc.png differ diff --git a/src/icons/lo32-action-connected.png b/src/icons/lo32-action-connected.png new file mode 100644 index 0000000..16481b4 Binary files /dev/null and b/src/icons/lo32-action-connected.png differ diff --git a/src/icons/lo32-action-connecting.png b/src/icons/lo32-action-connecting.png new file mode 100644 index 0000000..a229e02 Binary files /dev/null and b/src/icons/lo32-action-connecting.png differ diff --git a/src/icons/lo32-action-disconnected.png b/src/icons/lo32-action-disconnected.png new file mode 100644 index 0000000..84faa9d Binary files /dev/null and b/src/icons/lo32-action-disconnected.png differ diff --git a/src/icons/lo32-action-fritzboximport.png b/src/icons/lo32-action-fritzboximport.png new file mode 100644 index 0000000..d51d639 Binary files /dev/null and b/src/icons/lo32-action-fritzboximport.png differ diff --git a/src/icons/lo32-action-openssh.png b/src/icons/lo32-action-openssh.png new file mode 100644 index 0000000..6a2323e Binary files /dev/null and b/src/icons/lo32-action-openssh.png differ diff --git a/src/icons/lo32-action-openswan.png b/src/icons/lo32-action-openswan.png new file mode 100644 index 0000000..d865611 Binary files /dev/null and b/src/icons/lo32-action-openswan.png differ diff --git a/src/icons/lo32-action-openvpn.png b/src/icons/lo32-action-openvpn.png new file mode 100644 index 0000000..7685341 Binary files /dev/null and b/src/icons/lo32-action-openvpn.png differ diff --git a/src/icons/lo32-action-smartcard.png b/src/icons/lo32-action-smartcard.png new file mode 100644 index 0000000..cf05b70 Binary files /dev/null and b/src/icons/lo32-action-smartcard.png differ diff --git a/src/icons/lo32-app-kvpnc.png b/src/icons/lo32-app-kvpnc.png new file mode 100644 index 0000000..c96d6d7 Binary files /dev/null and b/src/icons/lo32-app-kvpnc.png differ diff --git a/src/icons/lo48-action-openvpn.png b/src/icons/lo48-action-openvpn.png new file mode 100644 index 0000000..3f21951 Binary files /dev/null and b/src/icons/lo48-action-openvpn.png differ diff --git a/src/icons/lo64-action-openswan.png b/src/icons/lo64-action-openswan.png new file mode 100644 index 0000000..598f2f2 Binary files /dev/null and b/src/icons/lo64-action-openswan.png differ diff --git a/src/icons/lo64-action-smartcard.png b/src/icons/lo64-action-smartcard.png new file mode 100644 index 0000000..6ecc5f3 Binary files /dev/null and b/src/icons/lo64-action-smartcard.png differ diff --git a/src/importcertificatedialog.cpp b/src/importcertificatedialog.cpp new file mode 100644 index 0000000..2fbc281 --- /dev/null +++ b/src/importcertificatedialog.cpp @@ -0,0 +1,1362 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* @description This class imports a certificate * +* * +* @author Christoph Thielecke * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +//BEGIN includes +#include "importcertificatedialog.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "kvpncconfig.h" +#include "utils.h" +//END includes + +ImportCertificateDialog::ImportCertificateDialog ( QWidget *parent, const char* caption, KVpncConfig *GlobalConfig ) + : KDialogBase ( parent, i18n ( "Import Certificate" ).ascii(), true, caption, + KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, true ) +{ + main = new ImportCertificateDialogBase ( this ); + setMainWidget ( main ); + main->setMinimumSize ( main->sizeHint() ); + + this->GlobalConfig = GlobalConfig; + filename = ""; + certHash = ""; + CertFullPath=""; + CaCertFullPath=""; + importOk = false; + importSuccess = true; + doHash = false; + doExit=true; + error_found=false; + certName = ""; + certpath = "/etc/racoon/certs/"; + pathToOpenSSL = GlobalConfig->pathToOpenssl; + main->RacoonCertificatePathUrlrequester->setMode ( 2 ); // directory + main->FilenameUrlrequester->setFilter ( "*" ); + askpasscount=0; + + env = new QStringList(); + *env << "LC_ALL=C" << "LANG=C" << "PATH=/bin:/usr/bin:/usr/sbin:/sbin"; + + connect ( main->ImporttypeComboBox, SIGNAL ( activated ( int ) ), this, SLOT ( typeToggeled ( int ) ) ); + typeToggeled ( main->ImporttypeComboBox->currentItem() ); + + connect (main->UsePrivateKeyPasswordCheckBox, SIGNAL( toggled(bool)), this, SLOT(usePrivateKeyPassToggled(bool))); + usePrivateKeyPassToggled(main->UsePrivateKeyPasswordCheckBox->isChecked()); + + // TMP + /* + main->FilenameUrlrequester->setURL( "/home/crissi/thielecke.p12" ); + //main->RacoonCertificatePathUrlrequester->setURL( "/etc/racoon/certs/" ); + main->ImporttypeComboBox->setCurrentItem( 1 ); + main->PrivateKeyPasswordEdit->setText( "12345678" ); + main->PrivateKeyAgainPasswordEdit->setText( "12345678" ); + */ + //main->ImportPasswordEdit->setText( "blah99" ); + + +} + +ImportCertificateDialog::~ImportCertificateDialog() +{ + delete main; +} + +void ImportCertificateDialog::accept() +{ + + importOk = true; + done=false; + error_found=false; + + filename = main->FilenameUrlrequester->url(); + importpassword = main->ImportPasswordEdit->text(); + certpath = main->RacoonCertificatePathUrlrequester->url(); + + if ( filename.isEmpty() ) + { + KMessageBox::sorry ( 0, i18n ( "File name cannot be empty!" ), i18n ( "Empty File Name" ) ); + importOk = false; + importSuccess=false; + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } + + // if ( filename.right( 3 ) != "p12" || filename.right (3) != "der" || filename.right (3) != "crt" ) { + // KMessageBox::sorry( 0, i18n( "File name isnt ended by \'p12\', 'der' or \'crt\'!" ), i18n( "Wrong File Name" ) ); + // importOk = false; + // return; + // } + + GlobalConfig->appPointer->setOverrideCursor ( QCursor ( Qt::WaitCursor ) ); + + QFile f ( filename ); + if ( f.exists() ) + { + if ( f.open ( IO_ReadOnly ) ) + { + f.close(); + } + else + { + KMessageBox::sorry ( 0, i18n ( "File does not exist!" ), i18n ( "No File" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: file \"%1\" does not exist." ).arg ( filename ),GlobalConfig->error ); + + importOk = false; + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } + } + else + { + KMessageBox::sorry ( 0, i18n ( "File not readable!" ), i18n ( "Insufficient Rights" ) ); + + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: file \"%1\" is not readable." ).arg ( filename ),GlobalConfig->error ); + importOk = false; + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } + + if ( main->ImporttypeComboBox->currentItem() == pkcs12_freeswan ) + { + certpath="/etc/ipsec.d"; + if ( !QDir ( certpath ).exists() ) + { + if ( !QDir().mkdir ( certpath ) ) + { + KMessageBox::error ( this, i18n ( "\"%1\" could not be created!" ).arg ( "/etc/ipsec.d" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: directory \"%1\" does not exist and could not be created." ).arg ( "/etc/ipsec.d" ),GlobalConfig->error ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: directory \"%1\" does not exist but was successful created." ).arg ( "/etc/ipsec.d" ),GlobalConfig->debug ); + if ( !QDir ( "/etc/ipsec.d/certs" ).exists() ) + { + if ( !QDir().mkdir ( "/etc/ipsec.d/certs" ) ) + { + KMessageBox::error ( this, i18n ( "\"%1\" could not be created!" ).arg ( "/etc/ipsec.d/certs" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: directory \"%1\" does not exist and could not be created." ).arg ( "/etc/ipsec.d/certs" ),GlobalConfig->error ); + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: directory \"%1\" does not exist but was successful created." ).arg ( "/etc/ipsec.d/certs" ),GlobalConfig->debug ); + if ( !QDir ( "/etc/ipsec.d/cacerts" ).exists() ) + if ( !QDir().mkdir ( "/etc/ipsec.d/cacerts" ) ) + { + KMessageBox::error ( this, i18n ( "\"%1\" could not be created!" ).arg ( "/etc/ipsec.d/cacerts" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: directory \"%1\" does not exist and could not be created." ).arg ( "/etc/ipsec.d/cacerts" ),GlobalConfig->error ); + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: directory \"%1\" does not exist but was successful created." ).arg ( "/etc/ipsec.d/cacerts" ),GlobalConfig->debug ); + } + } + } + } + } + } + else if ( main->ImporttypeComboBox->currentItem() == pkcs12_racoon || main->ImporttypeComboBox->currentItem() == ca_der ) + { + certpath="/etc/racoon/certs"; + if ( !QDir ( certpath ).exists() ) + if ( !QDir().mkdir ( certpath ) ) + { + KMessageBox::error ( this, i18n ( "\"%1\" could not be created!" ).arg ( certpath ) ); + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: directory \"%1\" does not exist." ).arg ( certpath ),GlobalConfig->error ); + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: directory \"%1\" does not exist but was successful created." ).arg ( certpath ),GlobalConfig->debug ); + } + } + else if ( main->ImporttypeComboBox->currentItem() == pkcs12_openvpn ) + { + certpath = main->RacoonCertificatePathUrlrequester->url(); + if ( !QDir ( certpath ).exists() ) + if ( !QDir().mkdir ( certpath ) ) + { + KMessageBox::error ( this, i18n ( "\"%1\" could not be created!" ).arg ( certpath ) ); + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: directory \"%1\" does not exist." ).arg ( certpath ),GlobalConfig->error ); + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: directory \"%1\" does not exist but was successful created." ).arg ( certpath ),GlobalConfig->debug ); + } + } + +// if ( (main->ImporttypeComboBox->currentItem() == pkcs12_freeswan || +// main->ImporttypeComboBox->currentItem() == pkcs12_racoon || +// main->ImporttypeComboBox->currentItem() == pkcs12_racoon +// ) && +// importpassword.isEmpty() ) +// { +// importOk = false; +// KMessageBox::sorry( 0, i18n( "Password can't be empty!" ), i18n( "Empty Password" ) ); +// return; +// } + + if ( main->ImporttypeComboBox->currentItem() == pkcs12_freeswan || main->ImporttypeComboBox->currentItem() == pkcs12_openvpn ) + { + + if ( main->UsePrivateKeyPasswordCheckBox->isChecked() && (main->PrivateKeyPasswordEdit->text().isEmpty() || main->PrivateKeyPasswordEdit->text().length() < 4) ) + { + importOk = false; + KMessageBox::sorry ( 0, i18n ( "Private key password field can not be empty or less than 4 characters!" ), i18n ( "Password Empty or Too Short" ) ); + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } + + if ( main->UsePrivateKeyPasswordCheckBox->isChecked() && (main->PrivateKeyAgainPasswordEdit->text().isEmpty() || main->PrivateKeyAgainPasswordEdit->text().length() < 4 )) + { + importOk = false; + KMessageBox::sorry ( 0, i18n ( "Private key password (again) field can not be empty!" ), i18n ( "Password Empty or Too Short" ) ); + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } + if ( importOk ) + { + if ( QString ( main->PrivateKeyPasswordEdit->password() ) != QString ( main->PrivateKeyAgainPasswordEdit->password() ) ) + { + importOk = false; + KMessageBox::sorry ( 0, i18n ( "Private key passwords does not match!" ), i18n ( "Passwords Do Not Match" ) ); + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } + else + { + privatekeypassword= QString ( main->PrivateKeyAgainPasswordEdit->password() ); + } + } + } + if ( main->ImporttypeComboBox->currentItem() == cisco || main->ImporttypeComboBox->currentItem() == ciscoca || main->ImporttypeComboBox->currentItem() == ciscouserca ) + { + if (main->UsePrivateKeyPasswordCheckBox->isChecked() && ( main->PrivateKeyPasswordEdit->text().isEmpty() || main->PrivateKeyPasswordEdit->text().length() < 4 )) + { + importOk = false; + KMessageBox::sorry ( 0, i18n ( "Certificate password field can not be empty or less than 4 characters!" ), i18n ( "Password Empty or Too Short" ) ); + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } + + if (main->UsePrivateKeyPasswordCheckBox->isChecked() && ( main->PrivateKeyAgainPasswordEdit->text().isEmpty() || main->PrivateKeyAgainPasswordEdit->text().length() < 4 )) + { + importOk = false; + KMessageBox::sorry ( 0, i18n ( "Certificate password (again) field can not be empty!" ), i18n ( "Password Empty or Too Short" ) ); + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } + if ( importOk ) + { + if ( main->UsePrivateKeyPasswordCheckBox->isChecked() && (QString ( main->PrivateKeyPasswordEdit->password() ) != QString ( main->PrivateKeyAgainPasswordEdit->password() ) )) + { + importOk = false; + KMessageBox::sorry ( 0, i18n ( "Certificate passwords does not match!" ), i18n ( "Passwords Do Not Match" ) ); + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } + else + { + if (main->UsePrivateKeyPasswordCheckBox->isChecked() ) + privatekeypassword= QString ( main->PrivateKeyAgainPasswordEdit->password() ); + } + } + } + if ( GlobalConfig->KvpncDebugLevel > 3 ) + kdDebug() << "file: " << filename << ", type: " << main->ImporttypeComboBox->currentItem() << endl; + + bool found=true; + if ( main->ImporttypeComboBox->currentItem() == pkcs12_freeswan || main->ImporttypeComboBox->currentItem() == pkcs12_openvpn || main->ImporttypeComboBox->currentItem() == pkcs12_racoon || main->ImporttypeComboBox->currentItem() == ca_der ) + { + // looking for openssl + + QString bin="openssl"; + ToolInfo *tool = Utils ( GlobalConfig ).getToolInfo ( "openssl" ); + //std::cout << "Tool (bin): " << bin << std::endl; + + if ( tool->PathToExec.section ( '/',-1 ) != bin ) + { + // program is NOT installed + KMessageBox::error ( this, i18n ( "The required tool (%1) is not installed, please install it first and restart kvpnc." ).arg ( bin ), i18n ( "Tool missing" ) ); + found=false; + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } + + if ( !found ) + { + KMessageBox::error ( this, i18n ( "Unable to find \"%1\"!" ).arg ( "openssl" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Unable to find \"%1\"!" ).arg ( "openssl" ) ,GlobalConfig->error ); + importOk = false; + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } + + + QString file = Utils ( this->GlobalConfig ).removeSpecialCharsForFilename ( QUrl ( filename ).fileName() ); + certName = file.left ( file.length() - 4 ); // peter_pan.p12 -> peter_pan + + if ( main->ImporttypeComboBox->currentItem() == pkcs12_racoon || main->ImporttypeComboBox->currentItem() == pkcs12_openvpn ) + { + QString type=""; + if ( main->ImporttypeComboBox->currentItem() == pkcs12_racoon ) + type="racoon"; + else + type="OpenVPN"; + QFile certpathtest ( certpath + "/." ); + + if ( !certpathtest.exists() ) + { + KMessageBox::error ( this, i18n ( "%1 certificate path (%2) does not exist!" ).arg ( type ).arg ( certpath ) ); + GlobalConfig->appendLogEntry ( i18n ( "%1 certificate path (%2) does not exist!" ).arg ( type ).arg ( certpath ) ,GlobalConfig->error ); + importOk=false; + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } + else + { + QFile testfile ( QString ( certpath + "/test" ) ); + if ( !testfile.open ( IO_WriteOnly ) ) + { + KMessageBox::error ( this, i18n ( "%1 certificate path (%2) is not writeable!" ).arg ( type ).arg ( certpath ) ); + GlobalConfig->appendLogEntry ( i18n ( "%1 certificate path (%2) is not writeable!" ).arg ( type ).arg ( certpath ) ,GlobalConfig->error ); + importOk = false; + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } + else + { + testfile.remove(); + } + } + } + } + + // here we go + if ( importOk ) + { + + /* + FreeSWAN/Racoon: + openssl pkcs12 -in cert.p12 -clcerts -out /etc/racoon/certs/mykeys_company.pem -nodes + + DER: + openssl x509 -in cert.crt -out ca_company.pem -inform DER + + */ + // std::cout << "[std]:" << "settings ok." << std::endl; + + ImportProcess = new QProcess ( this ); + + + if ( main->ImporttypeComboBox->currentItem() == pkcs12_freeswan || main->ImporttypeComboBox->currentItem() == pkcs12_openvpn || main->ImporttypeComboBox->currentItem() == pkcs12_racoon || main->ImporttypeComboBox->currentItem() == ca_der ) + { + ImportProcess->addArgument ( pathToOpenSSL ); + } + if ( main->ImporttypeComboBox->currentItem() == cisco || main->ImporttypeComboBox->currentItem() == ciscoca || main->ImporttypeComboBox->currentItem() == ciscouserca ) + { + ImportProcess->addArgument ( GlobalConfig->pathToCiscoCertMgr ); + } + + if ( main->ImporttypeComboBox->currentItem() == pkcs12_freeswan || + main->ImporttypeComboBox->currentItem() == pkcs12_racoon || + main->ImporttypeComboBox->currentItem() == pkcs12_openvpn + ) + { + ImportProcess->addArgument ( "pkcs12" ); + ImportProcess->addArgument ( "-in" ); + ImportProcess->addArgument ( filename ); + ImportProcess->addArgument ( "-nodes" ); + ImportProcess->addArgument ( "-clcerts" ); + ImportProcess->addArgument ( "-out" ); + } + else if ( main->ImporttypeComboBox->currentItem() == ca_der ) + { + + ImportProcess->addArgument ( "x509" ); + ImportProcess->addArgument ( "-in" ); + ImportProcess->addArgument ( filename ); + ImportProcess->addArgument ( "-out" ); + ImportProcess->addArgument ( certpath + "/ca_" + certName + ".pem" ); + ImportProcess->addArgument ( "-inform" ); + ImportProcess->addArgument ( "DER" ); + } + if ( main->ImporttypeComboBox->currentItem() == pkcs12_freeswan ) + { + ImportProcess->addArgument ( "/etc/ipsec.d/certs/mykeys_" + certName + ".pem" ); // warning: static + } + else if ( main->ImporttypeComboBox->currentItem() == pkcs12_racoon || main->ImporttypeComboBox->currentItem() == pkcs12_openvpn ) + { + ImportProcess->addArgument ( certpath + "/mykeys_" + certName + ".pem" ); + } + else if ( main->ImporttypeComboBox->currentItem() == cisco || main->ImporttypeComboBox->currentItem() == ciscoca || main->ImporttypeComboBox->currentItem() == ciscouserca ) + { + if (main->ImporttypeComboBox->currentItem() == cisco) + ImportProcess->addArgument ( "-U" ); + if (main->ImporttypeComboBox->currentItem() == ciscoca) + ImportProcess->addArgument ( "-R" ); + if (main->ImporttypeComboBox->currentItem() == ciscouserca) + { + ImportProcess->addArgument ( "-U" ); + ImportProcess->addArgument ( "-R" ); + } + ImportProcess->addArgument ( "-op" ); + ImportProcess->addArgument ( "import" ); + ImportProcess->addArgument ( "-f" ); + ImportProcess->addArgument ( filename ); + + } + + + connect ( ImportProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_import() ) ); + connect ( ImportProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_import() ) ); + if ( main->ImporttypeComboBox->currentItem() == pkcs12_freeswan || + main->ImporttypeComboBox->currentItem() == pkcs12_racoon || + main->ImporttypeComboBox->currentItem() == pkcs12_openvpn + ) + { + connect ( ImportProcess, SIGNAL ( processExited () ), this, SLOT ( doCacert() ) ); + } + if ( main->ImporttypeComboBox->currentItem() == ca_der ) + { + connect ( ImportProcess, SIGNAL ( processExited () ), this, SLOT ( doCreateHash() ) ); + } + + if ( main->ImporttypeComboBox->currentItem() == cisco || main->ImporttypeComboBox->currentItem() == ciscoca) + { + connect ( ImportProcess, SIGNAL ( processExited () ), this, SLOT ( ciscoCertMgrExited() ) ); + } + + if ( !ImportProcess->start ( env ) ) + { + if ( main->ImporttypeComboBox->currentItem() == pkcs12_freeswan || main->ImporttypeComboBox->currentItem() == pkcs12_openvpn || main->ImporttypeComboBox->currentItem() == pkcs12_racoon || main->ImporttypeComboBox->currentItem() == ca_der ) + KMessageBox::sorry ( this, i18n ( "Unable to start process (%1)!" ).arg ( "openssl" ) ); + if ( main->ImporttypeComboBox->currentItem() == cisco ) + KMessageBox::sorry ( this, i18n ( "Unable to start process (%1)!" ).arg ( "cisco_cert_mgr" ) ); + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } + else + { + doExit=true; + + QString processname = ""; + + if ( main->ImporttypeComboBox->currentItem() == pkcs12_freeswan || main->ImporttypeComboBox->currentItem() == pkcs12_openvpn || main->ImporttypeComboBox->currentItem() == pkcs12_racoon || main->ImporttypeComboBox->currentItem() == ca_der ) + { + processname="openssl"; + + if ( GlobalConfig->KvpncDebugLevel >3 ) + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: %1: send %2" ).arg("accept()").arg ( i18n ( " import password" ) ),GlobalConfig->debug ); + + if ( main->ImportPasswordEdit->text().isEmpty() ) + ImportProcess->writeToStdin ( "\n" ); + else + ImportProcess->writeToStdin ( main->ImportPasswordEdit->text() + "\n" ); + + } + if ( main->ImporttypeComboBox->currentItem() == cisco ) + processname="cisco_cert_mgr"; + + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Process (%1) started." ).arg (processname ),GlobalConfig->debug ); + + if ( main->ImporttypeComboBox->currentItem() == cisco /*|| main->ImporttypeComboBox->currentItem() == ciscoca*/ ) + { + ImportProcess->writeToStdin ( main->ImportPasswordEdit->text() +"\n"); + if (main->UsePrivateKeyPasswordCheckBox->isChecked() ) + { + ImportProcess->writeToStdin ( QString ( main->PrivateKeyPasswordEdit->password() ) + "\n" ); + ImportProcess->writeToStdin ( QString ( main->PrivateKeyPasswordEdit->password() ) + "\n" ); + } + } + } + } +} + +void ImportCertificateDialog::canAccept() +{ + if ( importSuccess ) + { + KMessageBox::information ( 0, i18n ( "Certificate was sucessfully imported." ), i18n ( "Import Successful" ) ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: certificate was successfully imported." ),GlobalConfig->debug ); + } + else + { + KMessageBox::sorry ( 0, i18n ( "Certificate import failed." ), i18n ( "Import Failed" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: certificate could not be imported." ),GlobalConfig->error ); + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } + + if ( main->ImporttypeComboBox->currentItem() == pkcs12_freeswan ) + { + QString bin="ipsec"; + ToolInfo *tool; + //std::cout << "Tool (bin): " << bin << std::endl; + if ( !GlobalConfig->ToolList->isEmpty() ) + { + for ( tool = GlobalConfig->ToolList->first(); tool; tool = GlobalConfig->ToolList->next() ) + { + if ( bin == tool->Name ) + { + if ( tool->PathToExec.section ( '/',-1 ) != bin ) + { + // program is NOT installed + KMessageBox::information ( this, i18n ( "The required tool (%1) is not installed, please install it before you are connecting and restart kvpnc." ).arg ( bin ), i18n ( "Tool Missing" ) ); + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } + break; + } + } + } + } + else if ( main->ImporttypeComboBox->currentItem() == pkcs12_racoon ) + { + QString bin="racoon"; + ToolInfo *tool; + //std::cout << "Tool (bin): " << bin << std::endl; + if ( !GlobalConfig->ToolList->isEmpty() ) + { + for ( tool = GlobalConfig->ToolList->first(); tool; tool = GlobalConfig->ToolList->next() ) + { + if ( bin == tool->Name ) + { + if ( tool->PathToExec.section ( '/',-1 ) != bin ) + { + // program is NOT installed + KMessageBox::information ( this, i18n ( "The required tool (%1) is not installed, please install it before you are connecting and restart kvpnc." ).arg ( bin ), i18n ( "Tool Missing" ) ); + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } + break; + } + } + } + } + else if ( main->ImporttypeComboBox->currentItem() == pkcs12_openvpn ) + { + QString bin="openvpn"; + ToolInfo *tool; + //std::cout << "Tool (bin): " << bin << std::endl; + if ( !GlobalConfig->ToolList->isEmpty() ) + { + for ( tool = GlobalConfig->ToolList->first(); tool; tool = GlobalConfig->ToolList->next() ) + { + if ( bin == tool->Name ) + { + if ( tool->PathToExec.section ( '/',-1 ) != bin ) + { + // program is NOT installed + KMessageBox::information ( this, i18n ( "The required tool (%1) is not installed, please install it before you are connecting and restart kvpnc." ).arg ( bin ), i18n ( "Tool Missing" ) ); + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } + break; + } + } + } + } + else if ( main->ImporttypeComboBox->currentItem() == cisco || main->ImporttypeComboBox->currentItem() == ciscoca || main->ImporttypeComboBox->currentItem() == ciscouserca ) + { + QString bin="cisco_cert_mgr"; + ToolInfo *tool; + //std::cout << "Tool (bin): " << bin << std::endl; + if ( !GlobalConfig->ToolList->isEmpty() ) + { + for ( tool = GlobalConfig->ToolList->first(); tool; tool = GlobalConfig->ToolList->next() ) + { + if ( bin == tool->Name ) + { + if ( tool->PathToExec.section ( '/',-1 ) != bin ) + { + // program is NOT installed + KMessageBox::information ( this, i18n ( "The required tool (%1) is not installed, please install it before you are connecting and restart kvpnc." ).arg ( bin ), i18n ( "Tool Missing" ) ); + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } + break; + } + } + } + } + GlobalConfig->appPointer->restoreOverrideCursor(); + + if ( doExit ) + QDialog::accept(); +} + +void ImportCertificateDialog::reject() +{ + importOk=false; + importSuccess=false; + QDialog::reject(); +} + +void ImportCertificateDialog::doCacert() +{ + disconnect ( ImportProcess, SIGNAL ( processExited () ), this, SLOT ( doCacert() ) ); + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: %1" ).arg("doCacert()"),GlobalConfig->debug ); + + if ( ImportProcess->normalExit () ) + { + + if ( main->ImporttypeComboBox->currentItem() == pkcs12_freeswan ) + { + Utils ( GlobalConfig,this ).doChmod ( "/etc/ipsec.d/certs/mykeys_" + certName + ".pem","go-rwx" ); + } + else if ( main->ImporttypeComboBox->currentItem() == pkcs12_racoon || main->ImporttypeComboBox->currentItem() == pkcs12_openvpn ) + { + Utils ( GlobalConfig,this ).doChmod ( certpath + "/mykeys_" + certName + ".pem","go-rwx" ); + } + + /* + openssl pkcs12 -in cert.p12 -nokeys -cacerts -out /etc/racoon/certs/ca_company.pem -nodes + */ + ImportProcess->clearArguments(); + ImportProcess->addArgument ( pathToOpenSSL ); + ImportProcess->addArgument ( "pkcs12" ); + ImportProcess->addArgument ( "-in" ); + ImportProcess->addArgument ( filename ); + ImportProcess->addArgument ( "-nokeys" ); + ImportProcess->addArgument ( "-cacerts" ); + ImportProcess->addArgument ( "-out" ); + + if ( main->ImporttypeComboBox->currentItem() == pkcs12_freeswan ) + { + ImportProcess->addArgument ( "/etc/ipsec.d/cacerts/ca_" + certName + ".pem" ); // warning: static + CaCertFullPath="/etc/ipsec.d/cacerts/ca_" + certName + ".pem"; + } + else + { + ImportProcess->addArgument ( certpath + "/ca_" + certName + ".pem" ); + CaCertFullPath=certpath + "/ca_" + certName + ".pem"; + } + + ImportProcess->addArgument ( "-nodes" ); + + connect ( ImportProcess, SIGNAL ( processExited () ), this, SLOT ( doCreateHash() ) ); + + if ( ! ImportProcess->start ( env ) ) + { + KMessageBox::error ( this, i18n ( "Unable to extract CA certificate!" ), i18n ( "Extract Failed" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: CA certificate could not be extracted." ),GlobalConfig->error ); + importSuccess=false; + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } + else + { + + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: %1: send %2" ).arg("doCacert()").arg ( i18n ( " import password" ) ),GlobalConfig->debug ); + + if ( main->ImportPasswordEdit->text().isEmpty() ) + ImportProcess->writeToStdin ( "\n" ); + else + ImportProcess->writeToStdin ( main->ImportPasswordEdit->text() + "\n" ); + + doExit=true; + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: CA certificate successful extracted." ),GlobalConfig->debug ); + } + } + else + { + importSuccess=false; + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: import process from accept() failed." ),GlobalConfig->error ); + } +} + +void ImportCertificateDialog::doPrivateKey() +{ + + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( "[dbg]: doPrivateKey()",GlobalConfig->debug ); + disconnect ( ImportProcess, SIGNAL ( processExited () ), this, SLOT ( doPrivateKey() ) ); + + if ( ImportProcess->normalExit () ) + { + + /* + openssl pkcs12 -in cert.p12 -nocerts -out /etc/racoon/certs/ca_company.pem + */ + ImportProcess->clearArguments(); + ImportProcess->addArgument ( pathToOpenSSL ); + ImportProcess->addArgument ( "pkcs12" ); + ImportProcess->addArgument ( "-nocerts" ); + ImportProcess->addArgument ( "-in" ); + ImportProcess->addArgument ( filename ); + ImportProcess->addArgument ( "-out" ); + + + if ( main->ImporttypeComboBox->currentItem() == pkcs12_freeswan ) + ImportProcess->addArgument ( certpath+"/private/" + certName + ".pem" ); // warning: static + else if ( main->ImporttypeComboBox->currentItem() == pkcs12_openvpn ) + ImportProcess->addArgument ( certpath+"/" + certName + ".pem" ); // warning: static + + if ( !certpath.isEmpty() ) + if ( main->ImporttypeComboBox->currentItem() == pkcs12_freeswan ) + CertFullPath=certpath+"/private/" + certName + ".pem"; + if ( main->ImporttypeComboBox->currentItem() == pkcs12_openvpn ) + CertFullPath=certpath+"/" + certName + ".pem"; + + if ( main->UsePrivateKeyPasswordCheckBox->isChecked() ) + connect ( ImportProcess, SIGNAL ( processExited () ), this, SLOT ( exit() ) ); + else + connect ( ImportProcess, SIGNAL ( processExited () ), this, SLOT ( removePrivateKey() ) ); + + //LogOutput->append( "priv key: we starting..." ); + if ( !ImportProcess->start( ) ) + { + KMessageBox::sorry ( this, i18n ( "Unable to start process (private key)!" ) ); + + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: private key could not extracted." ),GlobalConfig->error ); + importSuccess=false; + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } + else + { + + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: %1: send %2" ).arg("doPrivateKey()").arg ( i18n ( " import password" ) ),GlobalConfig->debug ); + +// if ( main->ImportPasswordEdit->text().isEmpty() ) +// ImportProcess->writeToStdin ( "\n" ); +// else + ImportProcess->writeToStdin ( main->ImportPasswordEdit->text() + "\n" ); + + + if ( main->UsePrivateKeyPasswordCheckBox->isChecked() ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: %1: send %2..." ).arg("doPrivateKey").arg ( i18n ( " private key password" ) ),GlobalConfig->debug ); + + ImportProcess->writeToStdin ( main->PrivateKeyPasswordEdit->text() + "\n" ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: %1: send %2..." ).arg("doPrivateKey").arg ( i18n ( " private key password dummy" ) ),GlobalConfig->debug ); + + // we need 4 chars here + ImportProcess->writeToStdin ( "abcd\n" ); + + } + + if ( main->UsePrivateKeyPasswordCheckBox->isChecked() ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: %1: send %2..." ).arg("doPrivateKey").arg ( i18n ( " private key password" ) ),GlobalConfig->debug ); + + ImportProcess->writeToStdin ( main->PrivateKeyPasswordEdit->text() + "\n" ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: %1: send %2..." ).arg("doPrivateKey").arg ( i18n ( " private key password dummy" ) ),GlobalConfig->debug ); + + // we need 4 chars here + ImportProcess->writeToStdin ( "abcd\n" ); + + } + + } + + } + else + { + importSuccess=false; + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: import process from doLink() failed." ),GlobalConfig->error ); + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } +} + +void ImportCertificateDialog::doCreateHash() +{ + + disconnect ( ImportProcess, SIGNAL ( processExited () ), this, SLOT ( doCreateHash() ) ); + + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: %1" ).arg("doCreateHash()"),GlobalConfig->debug ); + + if ( ImportProcess->normalExit () ) + { + + if ( main->ImporttypeComboBox->currentItem() == pkcs12_freeswan ) + Utils ( GlobalConfig,this ).doChmod ( certpath+"/cacerts/ca_" + certName + ".pem","go-rwx" ); + else + Utils ( GlobalConfig,this ).doChmod ( certpath + "/ca_" + certName + ".pem","go-rwx" ); + + /* + openssl x509 -noout -hash < /etc/racoon/certs/ca_company.pem + */ + ImportProcess->clearArguments(); + ImportProcess->addArgument ( pathToOpenSSL ); + ImportProcess->addArgument ( "x509" ); + ImportProcess->addArgument ( "-noout" ); + ImportProcess->addArgument ( "-hash" ); + ImportProcess->addArgument ( "-in" ); + if ( main->ImporttypeComboBox->currentItem() == pkcs12_freeswan ) + ImportProcess->addArgument ( certpath+"/cacerts/ca_" + certName + ".pem" ); // warning: static + else + ImportProcess->addArgument ( certpath + "/ca_" + certName + ".pem" ); + + connect ( ImportProcess, SIGNAL ( processExited () ), this, SLOT ( doLink() ) ); + + + // LogOutput->append( "hash: we starting..." ); + if ( !ImportProcess->start( ) ) + { + KMessageBox::sorry ( this, i18n ( "Unable to start process (%1)!" ).arg ( "hash" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: hash could not created." ),GlobalConfig->error ); + importSuccess=false; + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } + else + { + + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: %1: send %2" ).arg("doCreateHash()").arg ( i18n ( " import password" ) ),GlobalConfig->debug ); + + if ( main->ImportPasswordEdit->text().isEmpty() ) + ImportProcess->writeToStdin ( "\n" ); + else + ImportProcess->writeToStdin ( main->ImportPasswordEdit->text() + "\n" ); + while (ImportProcess->isRunning()) + { + sleep (1); + } + + doExit=true; + doHash = true; + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: hash successful created." ),GlobalConfig->debug ); + } + } + else + { + importSuccess=false; + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: import process from doCert() failed." ),GlobalConfig->error ); + } +} + +void ImportCertificateDialog::doLink() +{ + disconnect ( ImportProcess, SIGNAL ( processExited () ), this, SLOT ( doLink() ) ); + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: %1" ).arg("doLink()"),GlobalConfig->debug ); + + if ( ImportProcess->normalExit () ) + { + + doHash = false; + ImportProcess->clearArguments(); + /* + ln -s /etc/racoon/certs/ca_company.pem /etc/racoon/certs/.0 + */ + ImportProcess->addArgument ( "ln" ); + ImportProcess->addArgument ( "-sf" ); + if ( main->ImporttypeComboBox->currentItem() == pkcs12_freeswan ) + { + ImportProcess->addArgument ( certpath+"/cacerts/ca_" + certName + ".pem" ); + ImportProcess->addArgument ( certpath+"/cacerts/" + certHash + ".0" ); + } + else + { + ImportProcess->addArgument ( certpath + "/ca_" + certName + ".pem" ); + ImportProcess->addArgument ( certpath +"/"+ certHash + ".0" ); + } + + if ( main->ImporttypeComboBox->currentItem() == pkcs12_freeswan || + main->ImporttypeComboBox->currentItem() == pkcs12_openvpn ) + connect ( ImportProcess, SIGNAL ( processExited () ), this, SLOT ( doPrivateKey() ) ); + else + connect ( ImportProcess, SIGNAL ( processExited () ), this, SLOT ( exit() ) ); + + + if ( !ImportProcess->start( ) ) + { + KMessageBox::sorry ( this, i18n ( "Unable to start process (%1)!" ).arg ( "ln -s" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: Link could not created." ),GlobalConfig->error ); + importSuccess=false; + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } + else + { + while (ImportProcess->isRunning()) + { + usleep (500); + } + + delete ImportProcess; + GlobalConfig->appPointer->restoreOverrideCursor(); + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: Link creation sucessful." ),GlobalConfig->error ); + ImportProcess =0L; + exit(); + } + } + else + { + importSuccess=false; + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: Skipping link creation." ),GlobalConfig->error ); + } +} + +void ImportCertificateDialog::exit() +{ + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: %1" ).arg("exit()"),GlobalConfig->debug ); + + + if ( (ImportProcess != 0L && ImportProcess->normalExit() ) || ImportProcess == 0L ) + { + doExit=true; + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: Link successful created." ),GlobalConfig->debug ); + + // if ( ImportProcess->normalExit() ) + // importOk=true; + if ( main->ImporttypeComboBox->currentItem() == pkcs12_freeswan ) + Utils ( GlobalConfig,this ).doChmod ( certpath+"/private/" + certName + ".pem","go-rwx" ); + + if ( main->ImporttypeComboBox->currentItem() == pkcs12_openvpn ) + Utils ( GlobalConfig,this ).doChmod ( certpath+"/" + certName + ".pem","go-rwx" ); + done=true; + canAccept(); + } + else + { + GlobalConfig->appPointer->restoreOverrideCursor(); + importSuccess=false; + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: import process from doPrivateKey() failed." ),GlobalConfig->error ); + } +} + +void ImportCertificateDialog::readFromStdout_import() +{ + +// QString line = QString( ImportProcess->readStdout() ); + while ( ImportProcess->canReadLineStdout() ) + { + QString line = QString ( ImportProcess->readLineStdout() ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Certificate import stdout: %1" ).arg ( line ),GlobalConfig->debug ); + if ( doHash ) + { + certHash = line.left ( line.length() - 1 ); + doHash = false; + // LogOutput->append( "[std]: hash" + line + "" ); + } + + if ( line.find ( "Enter Import Password" , 0, FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: %1 was requested, send it..." ).arg ( i18n ( " import password" ) ),GlobalConfig->debug ); + + if ( main->ImportPasswordEdit->text().isEmpty() ) + ImportProcess->writeToStdin ( "\n" ); + else + ImportProcess->writeToStdin ( main->ImportPasswordEdit->text() + "\n" ); + } + + else if ( line.find ( "Enter PEM pass phrase" , 0, FALSE ) > -1 ) + { + + if ( askpasscount < 10 ) + { + + if ( main->UsePrivateKeyPasswordCheckBox->isChecked() ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: %1: send %2..." ).arg("doPrivateKey").arg ( i18n ( " private key password" ) ),GlobalConfig->debug ); + + ImportProcess->writeToStdin ( main->PrivateKeyPasswordEdit->text() + "\n" ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: %1: send %2..." ).arg("doPrivateKey").arg ( i18n ( " private key password dummy" ) ),GlobalConfig->debug ); + + // we need 4 chars here + ImportProcess->writeToStdin ( "abcd\n" ); + + } + askpasscount+=1; + } + else + { + // whats happen??? + // doExit=true; + } + } + + + if ( main->ImporttypeComboBox->currentItem() == cisco ) + { + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ("[cisco_cert_mgr raw] "+line,GlobalConfig->debug); + + if ( line.find ( "Password:" , 0, FALSE ) > -1 || line.find ( "Confirm Password:" , 0, FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: %1 was requested, send it..." ).arg ( i18n ( "certificate password" ) ),GlobalConfig->debug ); + ImportProcess->writeToStdin ( QString ( main->PrivateKeyPasswordEdit->password() ) + "\n" ); + + } + if ( line.find ( "Success: certificate imported from path:", 0, FALSE ) > -1 ) + { + + GlobalConfig->appendLogEntry ( i18n ( "Certificate import was successful." ) ,GlobalConfig->info ); + importOk=true; + importSuccess=true; + doExit=true; + done=true; + } + + } + } +} + +void ImportCertificateDialog::readFromStderr_import() +{ +// QString line = QString ( ImportProcess->readStderr() ); + while ( ImportProcess->canReadLineStderr() ) + { + QString line = QString ( ImportProcess->readLineStderr() ); + if ( GlobalConfig->KvpncDebugLevel > 3 ) + { + if ( line.find ( "Enter Import Pass", 0, FALSE ) > -1 || line.find ( "Enter PEM pass phrase", 0, FALSE ) > -1 || line.find ( "MAC verified OK", 0, FALSE ) > -1 || line.find ( "Enter pass phrase for", 0, FALSE ) > -1 || line.find ( "writing RSA key", 0, FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: %1" ).arg ( line ),GlobalConfig->info ); + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "Certificate import stderr: %1" ).arg ( line ),GlobalConfig->error ); + } + } + if ( line.find ( "Error",9, FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: %1" ).arg ( line ),GlobalConfig->error ); + importSuccess=false; + importOk = false; + doExit=false; +// error_found=true; + } + + else if ( line.find ( "invalid password" , 0, FALSE ) > -1 || line.find ( "Mac verify error: invalid password?", 0, FALSE ) > -1 ) + { + if (error_found==false) + KMessageBox::sorry ( this , i18n ( "Wrong password." ), i18n ( "Password Failed" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: password was invalid" ),GlobalConfig->error ); + importSuccess=false; + importOk = false; + doExit=false; + error_found=true; + GlobalConfig->appPointer->restoreOverrideCursor(); + } + + else if ( line.find ( "unable to load certificate", 0, FALSE ) > -1 ) + { + if (error_found==false) + KMessageBox::error ( this, i18n ( "Unable to load certificate!" ), i18n ( "Load Failed" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Unable to load certificate!" ) ,GlobalConfig->error ); + importOk=false; + importSuccess=false; + doExit=false; + error_found=true; +// if ( ImportProcess != 0L && ImportProcess->isRunning() ) +// { +// disconnect ( ImportProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_import() ) ); +// disconnect ( ImportProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_import() ) ); +// ImportProcess->kill(); +// ImportProcess = 0L; +// } + GlobalConfig->appPointer->restoreOverrideCursor(); + done=true; + return; + } + else if ( line.find ( "unable to load Private Key", 0, FALSE ) > -1 ) + { + if (error_found==false) + KMessageBox::error ( this, i18n ( "unable to load Private Key!" ), i18n ( "Load Failed" ) ); + GlobalConfig->appendLogEntry ( i18n ( "unable to load Private Key!" ) ,GlobalConfig->error ); + importOk=false; + importSuccess=false; + doExit=false; + error_found=true; + GlobalConfig->appPointer->restoreOverrideCursor(); + if ( ImportProcess->isRunning() ) + { + ImportProcess->kill(); + } + done=true; + } + + else if ( line.find ( "Error opening output file", 0, FALSE ) > -1 ) + { + if (error_found==false) + KMessageBox::error ( this, i18n ( "Error opening output file." ), i18n ( "File open failed" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Error opening output file!" ) ,GlobalConfig->error ); + importOk=false; + importSuccess=false; + doExit=true; + error_found=true; + GlobalConfig->appPointer->restoreOverrideCursor(); + done=true; + } + else if ( line.find ( "Verify failure", 0, FALSE ) > -1 ) + { + if (error_found==false) + KMessageBox::error ( this, i18n ( "Verify failure at private key password." ), i18n ( "Verify failure" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Verify failure at private key password." ) ,GlobalConfig->error ); + importOk=false; + importSuccess=false; + doExit=true; + error_found=true; + GlobalConfig->appPointer->restoreOverrideCursor(); + done=true; + } + + else if ( line.find ( "MAC verified OK", 0, FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( i18n ( "Import password was ok." ) ,GlobalConfig->debug ); + importSuccess=true; + } + + else if ( main->ImporttypeComboBox->currentItem() == cisco ) + { + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ("[cisco_cert_mgr raw err] "+line,GlobalConfig->debug); + + if ( line.find ( "error: unable to import certificate from path:", 0, FALSE ) > -1 ) + { + if (error_found==false) + KMessageBox::error ( this, i18n ( "Unable to load certificate!" ), i18n ( "Load Failed" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Unable to load certificate!" ) ,GlobalConfig->error ); + importOk=false; + importSuccess=false; + doExit=false; + error_found=true; + GlobalConfig->appPointer->restoreOverrideCursor(); + if ( ImportProcess->isRunning() ) + { + ImportProcess->kill(); + } + done=true; + } + + else if ( line.find ( "Success: certificate imported from path:", 0, FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( i18n ( "Certificate imported from path." ) ,GlobalConfig->error ); + importOk=true; + importSuccess=true; + doExit=false; + done=true; + } + } + } +} + +void ImportCertificateDialog::typeToggeled ( int type ) +{ + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( QString ( "type: "+QString().setNum ( type ) ),GlobalConfig->debug ); + if ( type == pkcs12_freeswan ) + { + certpath = "/etc/ipsec.d/certs"; +// main->PrivateKeyPasswordEdit->setEnabled ( true ); +// main->PrivateKeyAgainPasswordEdit->setEnabled ( true ); + main->RacoonCertificatePathUrlrequester->setEnabled ( false ); + main->ImportPasswordEdit->setEnabled ( true ); + main->P12GroupBox->setEnabled ( true ); +// main->PrivateKeyPassGroupBox->setEnabled ( true ); + main->FilenameUrlrequester->setFilter ( "*.p12" ); + } + else if ( type == pkcs12_racoon ) + { + certpath = "/etc/racoon/certs/"; +// main->PrivateKeyPasswordEdit->setEnabled ( false ); +// main->PrivateKeyAgainPasswordEdit->setEnabled ( false ); + main->RacoonCertificatePathUrlrequester->setEnabled ( true ); + main->ImportPasswordEdit->setEnabled ( true ); + main->P12GroupBox->setEnabled ( true ); +// main->PrivateKeyPassGroupBox->setEnabled ( false ); + main->FilenameUrlrequester->setFilter ( "*.p12" ); + } + else if ( type == ca_der ) + { + certpath = "/etc/certs/"; +// main->PrivateKeyPasswordEdit->setEnabled ( false ); +// main->PrivateKeyAgainPasswordEdit->setEnabled ( false ); + main->RacoonCertificatePathUrlrequester->setEnabled ( true ); + main->ImportPasswordEdit->setEnabled ( false ); + main->P12GroupBox->setEnabled ( false ); +// main->PrivateKeyPassGroupBox->setEnabled ( false ); + main->FilenameUrlrequester->setFilter ( "*.der *.crt" ); + } + else if ( type == pkcs12_openvpn ) + { + certpath = "/etc/openvpn"; + main->PrivateKeyPasswordEdit->setEnabled ( true ); + main->PrivateKeyAgainPasswordEdit->setEnabled ( true ); + main->RacoonCertificatePathUrlrequester->setEnabled ( true ); + main->RacoonCertificatePathUrlrequester->setURL( certpath ); + main->ImportPasswordEdit->setEnabled ( true ); + main->P12GroupBox->setEnabled ( true ); + main->PrivateKeyPassGroupBox->setEnabled ( true ); + main->FilenameUrlrequester->setFilter ( "*.p12" ); + } + else if ( type == cisco ) + { + main->P12GroupBox->setTitle ( i18n ( "Import" ) ); + main->CertPathTextLabel->hide(); + main->RacoonCertificatePathUrlrequester->hide(); + main->PrivateKeyPassGroupBox->setTitle ( i18n ( "Certificate protection" ) ); + main->PrivateKeyPassTextLabel->setText(i18n ("Certificate password:")); + main->PrivateKeyPassAgainTextLabel->setText(i18n ("Certificate password again:")); + main->FilenameUrlrequester->setFilter ( "*" ); + } + + else + { + main->P12GroupBox->setTitle ( i18n ( "P12" ) ); + main->CertPathTextLabel->hide(); + main->RacoonCertificatePathUrlrequester->hide(); + main->PrivateKeyPassGroupBox->setTitle ( i18n ( "FreeS/WAN (Openswan)" ) ); + main->PrivateKeyPassTextLabel->setText(i18n ("Private key passphrase:")); + main->PrivateKeyPassAgainTextLabel->setText(i18n ("Passphrase again:")); + main->FilenameUrlrequester->setFilter ( "*" ); + } + + main->RacoonCertificatePathUrlrequester->setURL ( certpath ); +} + +void ImportCertificateDialog::ciscoCertMgrExited() +{ + doExit=true; + importOk=true; + importSuccess=true; + done=true; + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: certificate successful imported." ),GlobalConfig->debug ); + canAccept(); +} + +void ImportCertificateDialog::usePrivateKeyPassToggled(bool) +{ + if (main->UsePrivateKeyPasswordCheckBox->isChecked()) + { + main->PrivateKeyPassGroupBox->setEnabled(true); + } + else + { + main->PrivateKeyPassGroupBox->setEnabled(false); + } +} + +void ImportCertificateDialog::removePrivateKey() +{ + disconnect ( ImportProcess, SIGNAL ( processExited () ), this, SLOT ( removePrivateKey() ) ); + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: %1" ).arg("removePrivateKey()"),GlobalConfig->debug ); + + if ( ImportProcess->normalExit () ) + { + ImportProcess->clearArguments(); + ImportProcess->addArgument ( pathToOpenSSL ); + ImportProcess->addArgument ( "rsa" ); + ImportProcess->addArgument ( "-in" ); + + if ( main->ImporttypeComboBox->currentItem() == pkcs12_freeswan ) + ImportProcess->addArgument ( certpath+"/private/" + certName + ".pem" ); // warning: static + else if ( main->ImporttypeComboBox->currentItem() == pkcs12_openvpn ) + ImportProcess->addArgument ( certpath+"/" + certName + ".pem" ); // warning: static + + ImportProcess->addArgument ( "-out" ); + + if ( main->ImporttypeComboBox->currentItem() == pkcs12_freeswan ) + ImportProcess->addArgument ( certpath+"/private/" + certName + ".pem" ); // warning: static + else if ( main->ImporttypeComboBox->currentItem() == pkcs12_openvpn ) + ImportProcess->addArgument ( certpath+"/" + certName + ".pem" ); // warning: static + + connect ( ImportProcess, SIGNAL ( processExited () ), this, SLOT ( exit() ) ); + + + if ( !ImportProcess->start( ) ) + { + KMessageBox::sorry ( this, i18n ( "Unable to start process (%1)!" ).arg ( "ln -s" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: passphrase could not removed." ),GlobalConfig->error ); + importSuccess=false; + GlobalConfig->appPointer->restoreOverrideCursor(); + return; + } + else + { + + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Certificate import: %1: send %2..." ).arg("removePrivateKey()").arg ( i18n ( " private key password dummy" ) ),GlobalConfig->debug ); + + // we need 4 chars here + ImportProcess->writeToStdin ( "abcd\n" ); + } + } + else + { + importSuccess=false; + } +} diff --git a/src/importcertificatedialog.h b/src/importcertificatedialog.h new file mode 100644 index 0000000..b1a05e5 --- /dev/null +++ b/src/importcertificatedialog.h @@ -0,0 +1,87 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef IMPORTCERTIFICATEDIALOG_H +#define IMPORTCERTIFICATEDIALOG_H + +#include "importcertificatedialogbase.h" +#include +#include +#include +#include +#include "kvpncconfig.h" + +/** +@author Christoph Thielecke +*/ +class ImportCertificateDialog : public KDialogBase { + Q_OBJECT + public: + ImportCertificateDialog(QWidget *parent, const char* caption, KVpncConfig *GlobalConfig); + + ~ImportCertificateDialog(); + void canAccept(); + QString filename; + QString certpath; + QString importpassword; + QString privatekeypassword; + QString privatekeyagainpassword; + QString pathToOpenSSL; + QString certHash; + QString certName; + QString CertFullPath; + QString CaCertFullPath; + bool importOk; + bool doHash; + bool importSuccess; + bool doExit; + + enum ImportType {pkcs12_freeswan=0,pkcs12_racoon=1,ca_der=2,pkcs12_openvpn=3,cisco=4, ciscoca=5, ciscouserca=6}; + +protected: + QProcess *ImportProcess; + KVpncConfig *GlobalConfig; + bool done; + bool error_found; + int askpasscount; + QStringList *env; + + public slots: + void accept(); + void reject(); + void exit(); + void typeToggeled(int); + void usePrivateKeyPassToggled(bool); + void removePrivateKey(); + + private slots: + void readFromStdout_import(); + void readFromStderr_import(); + void doLink(); + void doCacert(); + void doPrivateKey(); + void doCreateHash(); + void ciscoCertMgrExited(); + + + public: + ImportCertificateDialogBase *main; +}; + +#endif diff --git a/src/importcertificatedialogbase.ui b/src/importcertificatedialogbase.ui new file mode 100644 index 0000000..6cf55ed --- /dev/null +++ b/src/importcertificatedialogbase.ui @@ -0,0 +1,349 @@ + +ImportCertificateDialogBase + + + ImportCertificateDialogBase + + + + 0 + 0 + 428 + 328 + + + + Import Certificate + + + + unnamed + + + + layout19 + + + + unnamed + + + + GeneralGroupBox + + + General + + + + unnamed + + + + textLabel1 + + + File name: + + + + + ImporttypeTextLabel + + + Import type: + + + + + CertPathTextLabel + + + Certificate path: + + + + + RacoonCertificatePathUrlrequester + + + true + + + /etc/racoon/certs + + + Path to certificates directory for IPSec + + + + + FilenameUrlrequester + + + + 250 + 0 + + + + Path to the certificate file in P12 format + + + + + spacer32 + + + Horizontal + + + Expanding + + + + 100 + 20 + + + + + + + P12: IPsec + + + + + P12: racoon + + + + + DER CA + + + + + P12: OpenVPN + + + + + Cisco (propritary) + + + + + Cisco CA (propritary) + + + + + Cisco User+CA (propritary) + + + + ImporttypeComboBox + + + Type of connection for which this certificate should be used + + + <h1>The following types are available:</h1> +<table> +<tr><td>P12: IPsec</td><td>import certificate in PKCS12 format for IPSec use</td></tr> +<tr><td>P12: racoon</td><td>import certificate in PKCS12 format for ipsectools (racoon) use</td></tr> +<tr><td>DER CA</td><td>import CA certificate in DER format</td></tr> +<tr><td>P12: OpenVPN</td><td>import certificate in PKCS12 format for OpenVPN use</td></tr> +<tr><td>Cisco (propritary)</td><td>import user certificate for propritary cisco client use</td></tr> +<tr><td>Cisco CA (propritary)</td><td>import CA certificate for propritary cisco client use</td></tr> +<tr><td>Cisco User+CA (propritary)</td><td>import user and CA certificate for propritary cisco client use</td></tr> +</table> + + + + + ImporttypeSpacer + + + Horizontal + + + Expanding + + + + 80 + 20 + + + + + + CertPathSpacer + + + Horizontal + + + Expanding + + + + 60 + 20 + + + + + + + + P12GroupBox + + + P12 + + + + unnamed + + + + textLabel1_2 + + + Import password: + + + + + ImportPasswordEdit + + + Password + + + Import password for P12 certificate (got from administrator) + + + + + + + UsePrivateKeyPasswordCheckBox + + + Protect private key &with passphrase + + + Alt+W + + + true + + + + + PrivateKeyPassGroupBox + + + true + + + Passphrase + + + + unnamed + + + + PrivateKeyPasswordEdit + + + Passphrase to protect private key. Feel free to choose what you want (don't forget it!). + + + + + PrivateKeyPassTextLabel + + + Private key passphrase: + + + + + PrivateKeyPassAgainTextLabel + + + Passphrase again: + + + + + PrivateKeyAgainPasswordEdit + + + Passphrase to protect private key (again) + + + + + + + spacer4 + + + Vertical + + + Expanding + + + + 21 + 20 + + + + + + + + + + UsePrivateKeyPasswordCheckBox + toggled(bool) + ImportCertificateDialogBase + usePrivateKeyPassToggled(bool) + + + + ImporttypeComboBox + FilenameUrlrequester + RacoonCertificatePathUrlrequester + ImportPasswordEdit + UsePrivateKeyPasswordCheckBox + PrivateKeyPasswordEdit + PrivateKeyAgainPasswordEdit + + + usePrivateKeyPassToggled(bool) + + + + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + kcombobox.h + klineedit.h + kpassdlg.h + kpassdlg.h + + diff --git a/src/importipsecprofiledialog.cpp b/src/importipsecprofiledialog.cpp new file mode 100644 index 0000000..82de933 --- /dev/null +++ b/src/importipsecprofiledialog.cpp @@ -0,0 +1,1100 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* @description This class imports a openvpn configuration file * +* * +* @author Christoph Thielecke * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +//BEGIN INCLUDES +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "importipsecprofiledialog.h" +#include "utils.h" +#include "importcertificatedialog.h" +#include +#include "kvpncimportprofileselectiondialogbase.h" + + +//END INCLUDES + +ImportIpsecProfileDialog::ImportIpsecProfileDialog ( KVpncConfig *GlobalConfig, QWidget *parent, const QString& caption, QString file ) + : KDialogBase ( parent, "Import_Ipsec_profile", true, caption, KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, true ) +{ + if ( !file.isEmpty() ) + filename = file; + else + filename = ""; + Pkcs12CertFile = ""; + CertPath="/etc/ipsec/certs"; + importOk = false; + this->GlobalConfig = GlobalConfig; + + main = new ImportOpenvpnProfileDialogBase ( this ); + setMainWidget ( main ); + //main->setMinimumSize(main->sizeHint()); + + main->FilenameUrlrequester->setFilter ( "*.conf" ); + main->FilenameUrlrequester->setURL ( filename ); + main->OpenProfileManagerCheckBox->hide(); + main->TextLabel->setText ( i18n ( "Select IPSec config file:" ) ); + +} + +ImportIpsecProfileDialog::~ImportIpsecProfileDialog() +{ + delete main; +} + +void ImportIpsecProfileDialog::accept() +{ + filename = main->FilenameUrlrequester->url(); + if ( !filename.isEmpty() ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "IPSec import: file: %1" ).arg ( filename ), GlobalConfig->debug ); + canAccept(); + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "IPSec import: file name empty" ), GlobalConfig->error ); + KMessageBox::sorry ( 0, i18n ( "File name can not be empty!" ), i18n ( "Empty File Name" ) ); + } +} + +void ImportIpsecProfileDialog::reject() +{ + importOk=false; +} + +void ImportIpsecProfileDialog::canAccept() +{ + + QFile f ( filename ); + if ( !f.exists() ) + { + KMessageBox::sorry ( 0, i18n ( "File not found." ), i18n ( "No File" ) ); + + // emit progress( 100 ); + return ; + } + + + QFile IpsecConfigFile ( filename ); + QString importprefix = QFileInfo ( filename ).dirPath(); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "IPSec import: import prefix: %1" ).arg ( importprefix ), GlobalConfig->debug ); + + QString certprefix = locateLocal ( "data", "kvpnc" ); + + if ( IpsecConfigFile.open ( IO_ReadOnly ) ) + { + + QPtrList *ImportedAccountList = new QPtrList(); + ImportedAccountList->setAutoDelete ( TRUE ); // the list owns the objects + QPtrList *IpsecImportSectionList = new QPtrList(); + + bool isIpsecGlobalSection=false; + bool firstSectionFound=false; + bool defaultSectionFound=false; + bool useNat=false; + bool disableOpportunisticEncryption=true; + QStringList InterfaceList; + int IpsecVersion=1; +// bool pskIsInFile=true; + QString PskFile="/etc/ipsec.secrets"; + QString CertPath="/etc/ipsec.d/certs"; + + QString IpsecConfigSection=""; + bool validLineFound=false; + + QString line = NULL; + QString IpsecConfigSectionName=""; + QString IpsecConfigData=""; + bool sectionEndFound=false; + +// std::cout << "pass1: collecting sections" << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: pass1: collecting sections" ),GlobalConfig->debug ); + QTextStream stream ( &IpsecConfigFile ); + while ( !stream.atEnd() ) + { + line = stream.readLine().replace ( "\"","" ); + +// std::cout << "line: \"" << line << "\"" << std::endl; + + if ( IpsecConfigSectionName!="" && ( line=="\n" || GlobalConfig->removeWhiteSpaceAtBegin ( line ) =="\n" || line == NULL || line.startsWith ( "include" ) || line.startsWith ( "conn" ) ) ) + { + // end of section found +// std::cout << "end of section " << IpsecConfigSectionName << " found." << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: end of section %1 found." ).arg ( IpsecConfigSectionName ),GlobalConfig->debug ); + sectionEndFound=true; + + IpsecImportSection *section = new IpsecImportSection(); + section->SectionName = IpsecConfigSectionName; + section->SectionData = IpsecConfigData; + IpsecImportSectionList->append ( section ); + IpsecConfigData=""; + IpsecConfigSectionName=""; + +// std::cout << "Section:"<< std::endl; +// std::cout << section->SectionName << std::endl; +// std::cout << section->SectionData.join("\n"); +// std::cout << "-------------------"<< std::endl; + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + { + GlobalConfig->appendLogEntry ( "import ipsec config: Section:",GlobalConfig->debug ); + GlobalConfig->appendLogEntry ( section->SectionName ,GlobalConfig->debug ); + GlobalConfig->appendLogEntry ( section->SectionData.join ( "\n" ),GlobalConfig->debug ); + GlobalConfig->appendLogEntry ( "-------------------",GlobalConfig->debug ); + } + } + + if ( line.startsWith ( "conn" ) ) + { + // section found + IpsecConfigSectionName=line.simplifyWhiteSpace().section ( '#',0,0 ).section ( " ",1,1 ); +// std::cout << "normal section found: " << IpsecConfigSectionName << std::endl; + + isIpsecGlobalSection=false; + + if ( IpsecConfigSectionName == "%default" ) + { + defaultSectionFound=true; + sectionEndFound=false; + firstSectionFound=true; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: default section found." ),GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: normal section found: " ) + IpsecConfigSectionName ,GlobalConfig->debug ); + sectionEndFound=false; + firstSectionFound=true; + } + } + if ( line.startsWith ( "version" ) ) + { + IpsecVersion=QString ( line.simplifyWhiteSpace().section ( '#',0,0 ).section ( " ",1,1 ).stripWhiteSpace() ).toFloat(); + validLineFound=true; +// std::cout << "ipsec version found: " << IpsecVersion << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: ipsec version found: " ) + QString().setNum ( IpsecVersion ) ,GlobalConfig->debug ); + } + if ( line.startsWith ( "config setup" ) ) + { + // config section found + isIpsecGlobalSection=true; + validLineFound=true; +// std::cout << "global section found." << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: global section found." ),GlobalConfig->debug ); + } + + if ( isIpsecGlobalSection==true ) + { + QString line2 = GlobalConfig->removeWhiteSpaceAtBegin ( line ); +// std::cout << "global section line: " << line2 << std::endl; + if ( line2.startsWith ( "plutodebug" ) ) + { + validLineFound=true; + // FIXME not implemented yet + } + if ( line2.startsWith ( "nat_traversal=" ) ) + { + validLineFound=true; + useNat=false; + if ( line2.section ( '=',1,1 ) == "yes" ) + { + useNat=true; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: use NAT." ),GlobalConfig->debug ); + } + else + { + useNat=false; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: use no NAT." ),GlobalConfig->debug ); + } + } + + if ( line2.startsWith ( "interfaces=" ) ) + { + validLineFound=true; + if ( line2.section ( '=',1,1 ) == "%defaultroute" ) + { + InterfaceList.append ( "default" ); + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: use interface where default route points" ),GlobalConfig->debug ); + } + else + { + InterfaceList = QStringList::split ( ' ',line2.replace ( "interfaces=","" ).replace ( QRegExp ( "ipsec[0-9]=" ),"" ) ); +// std::cout << "interface list: " << InterfaceList << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: use interface from list:" ) + " "+InterfaceList.join ( ", " ),GlobalConfig->debug ); + } + } + } + + if ( line.startsWith ( "include /etc/ipsec.d/examples/no_oe.conf" ) ) + { + validLineFound=true; + isIpsecGlobalSection=false; +// std::cout << "opportunistic enncrytion disabled found." << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: opportunistic encrytion disabled found" ),GlobalConfig->debug ); + + disableOpportunisticEncryption=true; + } + + if ( !sectionEndFound && firstSectionFound==true ) + { + // collecting data + QString cleanLine = GlobalConfig->removeWhiteSpaceAtBegin ( line ) +"\n"; +// std:: cout << "clean line: \"" << cleanLine << "\"" << std::endl; + if ( !cleanLine.startsWith ( "#" ) && !cleanLine.startsWith ( "include" ) && cleanLine != "" && !line.startsWith ( "conn" ) && cleanLine != "\n" ) + { +// std:: cout << "appending line: \"" << line << "\"" << std::endl; + IpsecConfigData.append ( line+"\n" ); + } + else + { +// std:: cout << "skipping line: \"" << line << "\"" << std::endl; + } + } + } + if ( IpsecConfigSectionName!="" ) + { + // end of section found +// std::cout << "end of section " << IpsecConfigSectionName << " found." << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( "end of section " + IpsecConfigSectionName +" found.",GlobalConfig->debug ); + sectionEndFound=true; + + IpsecImportSection *section = new IpsecImportSection(); + section->SectionName = IpsecConfigSectionName; + section->SectionData = IpsecConfigData; + IpsecImportSectionList->append ( section ); + IpsecConfigData=""; + IpsecConfigSectionName=""; + } + + IpsecConfigFile.close(); + + +// std::cout << "pass2: modifiy sections" << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: pass2: modifiy sections" ),GlobalConfig->debug ); + +// std::cout << "sections: IpsecImportSectionList: " << IpsecImportSectionList->count() << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: sections: " ) + QString().setNum ( IpsecImportSectionList->count() ),GlobalConfig->debug ); + + if ( !IpsecImportSectionList->isEmpty() ) + { + for ( int i=0; i< ( int ) IpsecImportSectionList->count();i++ ) + { + IpsecImportSection *section = IpsecImportSectionList->at ( i ); + QString Name= section->SectionName; + QStringList data = QStringList::split ( '\n',section->SectionData.join ( "\n" ) ); + +// std::cout << " => processing section: \"" << Name << "\"" << std::endl; + + if ( Name != "%default" ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: => processing section: " ) +"\"" + Name + "\"",GlobalConfig->debug ); + + for ( QStringList::Iterator it2 = data.begin(); it2 != data.end(); ++it2 ) + { + QString dataline = *it2; + // std::cout << "dataline found: \"" << dataline.remove("\n") << "\"" << std::endl; + if ( GlobalConfig->removeWhiteSpaceAtBegin ( dataline ).startsWith ( "also=" ) ) + { + // std::cout << "also= found, looking for other section..." << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: also= found, looking for other section..." ),GlobalConfig->debug ); + + QString newdata = QString ( section->SectionData.join ( "\n" ) ); + newdata.replace ( QRegExp ( "^.*also=.*$" ),"" ); + section->SectionData= newdata; + + QString OtherSection=dataline.simplifyWhiteSpace().section ( '#',0,0 ).section ( "=",1,1 ); + // we have to find the other section and replace this line by the config data of the other section (after the =) + bool section_found=false; + for ( IpsecImportSection * it3 = IpsecImportSectionList->first(); it3; it3 = IpsecImportSectionList->next() ) + { + if ( it3->SectionName == OtherSection ) + { + // std::cout << "section " << OtherSection << " found, appending:" << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: section %1 found, appending:" ).arg ( OtherSection ),GlobalConfig->debug ); + // std::cout << "other data:" << std::endl << it3->SectionData.join("\n") << "--------" << std::endl; + // std::cout << "section data:" << std::endl << section->SectionData.join("\n") << "--------" << std::endl; + section_found=true; + // data.remove(dataline); + dataline=""; + // QStringList otherdata = QStringList::split("\n",QString(it3->SectionData.join("\n"))); + QString OtherData = QString ( it3->SectionData.join ( "\n" ) ); + + QStringList newdata; + + for ( QStringList::Iterator it6 = data.begin(); it6 != data.end(); ++it6 ) + { + // std::cout << " also line: " << *it6 << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: also line: " ) + QString ( *it6 ),GlobalConfig->debug ); + + if ( QString ( *it6 ).find ( "also=" ) < 0 ) + { + // std::cout << " also= found." << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: also= found." ),GlobalConfig->debug ); + newdata.append ( QString ( *it6 ) ); + } + else + { + // std::cout << " also= not found." << std::cout; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: also= not found." ) ,GlobalConfig->debug ); + } + } + // newdata.append(data.join("\n")); + newdata.append ( OtherData ); + section->SectionData= newdata; + + } + } + if ( !section_found ) + { + // std::cout << "section " << OtherSection << " not found, skipping" << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: section %1 not found, skipping" ).arg ( OtherSection ) ,GlobalConfig->debug ); + } + + } + } + + if ( defaultSectionFound==true ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: => default section is set... " ),GlobalConfig->debug ); + + for ( int i=0; i< ( int ) IpsecImportSectionList->count();i++ ) + { + IpsecImportSection *section2 = IpsecImportSectionList->at ( i ); + QString Name= section2->SectionName; + if ( Name == "%default" ) + { + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: => appending %default section: " ) +"\"" + section2->SectionData.join ( "\n" ) ,GlobalConfig->debug ); + + QStringList defaultdata = QStringList::split ( '\n',section2->SectionData.join ( "\n" ) ); + + + for ( QStringList::Iterator defaultit = defaultdata.begin(); defaultit != defaultdata.end(); ++defaultit ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: => appending %default line: " ) +"\"" + *defaultit,GlobalConfig->debug ); + section->SectionData.append ( *defaultit ); + } + break; + } + } + } + } + } + } + +// std::cout << "modified config" << std::endl << "---------------------" << std::endl; +// KVpncConfig->IpsecImportSection *it5=NULL; +// for ( it5 = IpsecImportSectionList->first(); it5; it5 = IpsecImportSectionList->next() ) +// { +// QString SectionName= it5->SectionName; +// QStringList data = it5->SectionData; +// +// std::cout << SectionName << std::endl; +// std::cout << data.join("\n") << std::endl; +// } + + // remove default section + for ( int i=0; i< ( int ) IpsecImportSectionList->count();i++ ) + { + IpsecImportSection *section = IpsecImportSectionList->at ( i ); + QString Name= section->SectionName; + if ( Name == "%default" ) + { + IpsecImportSectionList->remove ( IpsecImportSectionList->at ( i ) ); + break; + } + } + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + { + GlobalConfig->appendLogEntry ( i18n ( "modified config" ) ,GlobalConfig->debug ); + GlobalConfig->appendLogEntry ( "---------------------" ,GlobalConfig->debug ); + IpsecImportSection *it5=NULL; + for ( it5 = IpsecImportSectionList->first(); it5; it5 = IpsecImportSectionList->next() ) + { + QString SectionName= it5->SectionName; + QStringList data = it5->SectionData; + + GlobalConfig->appendLogEntry ( SectionName ,GlobalConfig->debug ); + GlobalConfig->appendLogEntry ( data.join ( "\n" ) ,GlobalConfig->debug ); + } + } + + +// std::cout << "pass3: parse sections" << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: pass3: parse sections" ) ,GlobalConfig->debug ); + + + if ( !IpsecImportSectionList->isEmpty() ) + { + for ( int i=0; i< ( int ) IpsecImportSectionList->count();i++ ) + { + IpsecImportSection *section = IpsecImportSectionList->at ( i ); + + QStringList sectiondata = QStringList::split ( '\n',section->SectionData.join ( "\n" ) ); + +// std::cout << " => processing section: \"" << section->SectionName << "\"" << std::endl; +// std::cout << " => data: \"" << section->SectionData.join("\n") << "\"" << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: => processing section: " ) +"\"" + section->SectionName + "\"" ,GlobalConfig->debug ); + + VpnAccountData *profiledata = new VpnAccountData ( VpnAccountData::freeswan,QString ( section->SectionName ) ) ; + + + for ( QStringList::Iterator it2 = sectiondata.begin(); it2!= sectiondata.end() ; it2++ ) + { + QString dataline = *it2; + + + QString line2 = GlobalConfig->removeWhiteSpaceAtBegin ( dataline ); // line of text excluding '\n' and replace all white chars with one blank +// std::cout << "dataline: \"" << line2 << "\""; + if ( line2.startsWith ( "rightsubnet=" ) ) + { + validLineFound=true; + QString RightSubnet=line2.section ( "rightsubnet=",1,-1 ); +// std::cout << "right subnet (remote) found: " << RightSubnet << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: right subnet (remote) found: " ) + RightSubnet ,GlobalConfig->debug ); + profiledata->setRemoteNetAddr ( RightSubnet.section ( '/',0,0 ) ); + profiledata->setRemoteNetMask ( RightSubnet.section ( '/',1,1 ) ); + + profiledata->setUseRemoteNetwork ( true ); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (GlobalConfig->KvpncDebugLevel > 2) +// GlobalConfig->appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,GlobalConfig->debug); + } + if ( line2.startsWith ( "leftsubnet=" ) ) + { + validLineFound=true; + QString LeftSubnet=line2.section ( "leftsubnet=",1,-1 ); +// std::cout << "left subnet (local) found: " << LeftSubnet << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: left subnet (local) found: " ) + LeftSubnet ,GlobalConfig->debug ); + // local subnet cant be set yet. + // profiledata->setLocalNetAddr(RightSubnet.section('/',0,0)); + // profiledata->setLocalNetMask(RightSubnet.section('/',1,1)); + // std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; + + } + if ( line2.startsWith ( "rightnexthop=" ) ) + { + validLineFound=true; + QString RightNextHop=line2.section ( "rightnexthop=",1,-1 ); +// std::cout << "right next hop (remote) found: " << RightNextHop << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: right next hop (remote) found: " ) +RightNextHop ,GlobalConfig->debug ); + profiledata->setRightNextHop ( RightNextHop ); + profiledata->setUseRightNextHop(true); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (GlobalConfig->KvpncDebugLevel > 2) +// GlobalConfig->appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,GlobalConfig->debug); + } + if ( line2.startsWith ( "leftnexthop=" ) ) + { + validLineFound=true; + QString LeftNextHop=line2.section ( "leftnexthop=",1,-1 ); + std::cout << "left next hop (local) found: " << LeftNextHop << std::endl; + if (GlobalConfig->KvpncDebugLevel > 2) + GlobalConfig->appendLogEntry("import ipsec config: left next hop (local) found: " +LeftNextHop ,GlobalConfig->debug); + profiledata->setLeftNextHop(LeftNextHop); + profiledata->setUseLeftNextHop(true); + std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; + if (GlobalConfig->KvpncDebugLevel > 2) + GlobalConfig->appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,GlobalConfig->debug); + } + if ( line2.startsWith ( "left=" ) ) + { + validLineFound=true; + QString left=line2.section ( "left=",1,-1 ); + // local ip cant be set yet. + // std::cout << "left found: " << left << std::endl; +// if (GlobalConfig->KvpncDebugLevel > 2) +// GlobalConfig->appendLogEntry("import ipsec config: left found: " + left ,GlobalConfig->debug); + // profiledata->setLocal (left); + // std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (GlobalConfig->KvpncDebugLevel > 2) +// GlobalConfig->appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,GlobalConfig->debug); + } + if ( line2.startsWith ( "right=" ) ) + { + validLineFound=true; + QString right=line2.section ( "right=",1,-1 ); +// std::cout << "right (remote gateway) found: " << right << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: right (remote gateway) found: " ) + right ,GlobalConfig->debug ); + profiledata->setGateway ( right ); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (GlobalConfig->KvpncDebugLevel > 2) +// GlobalConfig->appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,GlobalConfig->debug); + } + if ( line2.startsWith ( "leftcert=" ) ) + { + validLineFound=true; + QString LeftCert=line2.section ( "leftcert=",1,-1 ); +// std::cout << "left cert (local) found: " << LeftCert << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: left cert (local) found: " ) + LeftCert ,GlobalConfig->debug ); + profiledata->setX509Certificate ( LeftCert ); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (GlobalConfig->KvpncDebugLevel > 2) +// GlobalConfig->appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,GlobalConfig->debug); + } + if ( line2.startsWith ( "rightcert=" ) ) + { + validLineFound=true; + QString RightCert=line2.section("rightcert=",1,-1); +// std::cout << "right cert (remote) found: " << RightCert << std::endl; + if (GlobalConfig->KvpncDebugLevel > 2) + GlobalConfig->appendLogEntry(i18n ("import ipsec config: right cert (remote) found: ") + RightCert ,GlobalConfig->debug); + profiledata->setUseSpecialServerCertificate(true); + profiledata->setSpecialServerCertificate(RightCert); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (GlobalConfig->KvpncDebugLevel > 2) +// GlobalConfig->appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,GlobalConfig->debug); + } + if ( line2.startsWith ( "rightca=" ) ) + { + validLineFound=true; + QString RightCA=line2.section ( "rightca=",1,-1 ); +// std::cout << "right CA (remote) found: " << RightCA << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: right CA (remote) found: " ) +RightCA ,GlobalConfig->debug ); + profiledata->setCaCertificate ( RightCA ); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (GlobalConfig->KvpncDebugLevel > 2) +// GlobalConfig->appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,GlobalConfig->debug); + } + if ( line2.startsWith ( "rightid=" ) ) + { + validLineFound=true; + QString RightID=line2.section ( "rightid=",1,-1 ); +// std::cout << "right ID (remote) found: " << RightID << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: right ID (remote) found: " ) + RightID ,GlobalConfig->debug ); + profiledata->setUseSpecialRemoteID ( true ); + profiledata->setSpecialRemoteID ( RightID ); + profiledata->setRemoteIDType("keyid"); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (GlobalConfig->KvpncDebugLevel > 2) +// GlobalConfig->appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,GlobalConfig->debug); + } + if ( line2.startsWith ( "leftid=" ) ) + { + validLineFound=true; + QString LeftID=line2.section ( "leftid=",1,-1 ); +// std::cout << "local ID (local) found: " << LeftID << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: local ID (local) found: " ) + LeftID ,GlobalConfig->debug ); + profiledata->setUseSpecialLocalID ( true ); + profiledata->setSpecialLocalID ( LeftID ); + profiledata->setLocalIDType("keyid"); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (GlobalConfig->KvpncDebugLevel > 2) +// GlobalConfig->appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,GlobalConfig->debug); + } + if ( line2.startsWith ( "rightrsasigkey=" ) ) + { + validLineFound=true; + QString RightRsaSigKey=line2.section ( "rightrsasigkey=",1,-1 ); +// std::cout << "right uses (remote) " << RightRsaSigKey << std::endl; + if (RightRsaSigKey=="%cert") + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: right (remote) uses cert" ),GlobalConfig->debug ); + profiledata->setAuthType ( VpnAccountData::cert ); + } + else + { + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: right (remote) uses " ) + RightRsaSigKey ,GlobalConfig->debug ); + profiledata->setAuthType ( VpnAccountData::psk ); + + // ok, we use special server cert here because at psk its unused + profiledata->setSpecialServerCertificate( RightRsaSigKey ); + profiledata->setUseSpecialServerCertificate(true); + } +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (GlobalConfig->KvpncDebugLevel > 2) +// GlobalConfig->appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,GlobalConfig->debug); + } + if ( line2.startsWith ( "leftrsasigkey=" ) ) + { + validLineFound=true; + QString LeftRsaSigKey=line2.section ( "leftrsasigkey=",1,-1 ); +// std::cout << "right uses (remote) " << LeftRsaSigKey << std::endl; + if (LeftRsaSigKey=="%cert") + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: left (local) uses cert" ),GlobalConfig->debug ); + profiledata->setAuthType ( VpnAccountData::cert ); + + } + else + { + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: left (local) uses " ) + LeftRsaSigKey ,GlobalConfig->debug ); + profiledata->setAuthType ( VpnAccountData::psk ); + + profiledata->setPreSharedKeyFile( LeftRsaSigKey ); + profiledata->setPskIsInFile( true ); + } +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (GlobalConfig->KvpncDebugLevel > 2) +// GlobalConfig->appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,GlobalConfig->debug); + } + if ( line2.startsWith ( "authby=" ) ) + { + validLineFound=true; + QString Authby=line2.simplifyWhiteSpace().section ( "authby=",1,1 ); +// std::cout << "left and right use certs " << std::endl; + if ( Authby.find ( "rsasig", 0 , FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: left and right use certs." ) ,GlobalConfig->debug ); + profiledata->setAuthType ( VpnAccountData::cert ); + profiledata->setCertPath ( "/etc/ipsec.d/certs" ); + //profiledata->setPskIsInFile ( true ); + //profiledata->setPrivateKeyFile ( "/etc/ipsec.secrets" ); + } + else if ( Authby.find ( "secret", 0 , FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: left and right use psk." ) ,GlobalConfig->debug ); + profiledata->setAuthType ( VpnAccountData::psk ); + //profiledata->setPskIsInFile ( true ); + //profiledata->setPreSharedKeyFile ( "/etc/ipsec.secrets" ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: left and right use unknown auth, guess psk" ) ,GlobalConfig->debug ); + profiledata->setAuthType ( VpnAccountData::psk ); + } + + +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (GlobalConfig->KvpncDebugLevel > 2) +// GlobalConfig->appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,GlobalConfig->debug); + } + if ( line2.startsWith ( "auto=start" ) ) + { + // validLineFound=true; + // QString Authby=line2.simplifyWhiteSpace().section('#',0,0).section("=",1,1); + // std::cout << "profile should be started" << std::endl; +// if (GlobalConfig->KvpncDebugLevel > 2) +// GlobalConfig->appendLogEntry("import ipsec config: profile should be started" ,GlobalConfig->debug); + // profiledata->setAuthType(VpnAccountData::cert); + // std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (GlobalConfig->KvpncDebugLevel > 2) +// GlobalConfig->appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,GlobalConfig->debug); + } + if ( line2.startsWith ( "leftsourceip=" ) ) + { + validLineFound=true; + QString leftsourceip=line2.section ( "leftsourceip=",1,-1 ); + std::cout << "left (local) have to use IP address " << leftsourceip << std::endl; + if (GlobalConfig->KvpncDebugLevel > 2) + GlobalConfig->appendLogEntry("import ipsec config: left (local) have to use IP address " + leftsourceip ,GlobalConfig->debug); + profiledata->setLocalVirtualIP(leftsourceip); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; + if (GlobalConfig->KvpncDebugLevel > 2) + GlobalConfig->appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,GlobalConfig->debug); + } + if ( line2.startsWith ( "virtual_private=" ) ) + { + validLineFound=true; + QString virtualprivate=line2.section ( "virtual_private=",1,-1 ); + std::cout << "virtual private networks " << virtualprivate << std::endl; + if (GlobalConfig->KvpncDebugLevel > 2) + GlobalConfig->appendLogEntry("import ipsec config: virtual private networks " +virtualprivate ,GlobalConfig->debug); + profiledata->setLocalVirtualIP(virtualprivate); + profiledata->setUseVirtualIP(true); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; + if (GlobalConfig->KvpncDebugLevel > 2) + GlobalConfig->appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,GlobalConfig->debug); + } + if ( line2.startsWith ( "rightsourceip=" ) ) + { + validLineFound=true; + QString rightsourceip=line2.section ( "rightsourceip=",1,-1 ); + std::cout << "right (remote) have to use IP address " << rightsourceip << std::endl; + if (GlobalConfig->KvpncDebugLevel > 2) + GlobalConfig->appendLogEntry("import ipsec config: right (remote) have to use IP address " + rightsourceip ,GlobalConfig->debug); + profiledata->setRightSourceIp(rightsourceip); + profiledata->setUseRightSourceIp(true); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; + if (GlobalConfig->KvpncDebugLevel > 2) + GlobalConfig->appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,GlobalConfig->debug); + } + if ( line2.startsWith ( "esp=" ) ) + { + validLineFound=true; + QString IpsecEsp=line2.section ( "esp=",1,-1 ); +// std::cout << "esp settings found: " << IpsecEsp << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: esp settings found: " ) + IpsecEsp ,GlobalConfig->debug ); + profiledata->setIpsecEsp ( IpsecEsp ); + profiledata->setUseCustomEsp(true); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (GlobalConfig->KvpncDebugLevel > 2) +// GlobalConfig->appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,GlobalConfig->debug); + } + if ( line2.startsWith ( "ike=" ) ) + { + validLineFound=true; + QString IpsecIke=line2.section ( "ike=",1,-1 ); +// std::cout << "ike settings found: " << IpsecIke << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: ike settings found: " ) + IpsecIke ,GlobalConfig->debug ); + profiledata->setIpsecIke ( IpsecIke ); + profiledata->setUseCustomIke(true); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (GlobalConfig->KvpncDebugLevel > 2) +// GlobalConfig->appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,GlobalConfig->debug); + } + if ( line2.startsWith ( "type=" ) ) + { + validLineFound=true; + QString IpsecVpnMode=line2.section ( "type=",1,1 ); +// std::cout << "IpsecType found: " << IpsecType << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: IPsec vpn mode found: " ) + IpsecVpnMode ,GlobalConfig->debug ); + if ( IpsecVpnMode == "tunnel" ) + profiledata->setIpsecVpnMode ( "tunnel" ); + else + profiledata->setIpsecVpnMode ( "transport" ); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (GlobalConfig->KvpncDebugLevel > 2) +// GlobalConfig->appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,GlobalConfig->debug); + } + if ( line2.startsWith ( "leftxauthclient=" ) ) + { + validLineFound=true; + QString useXauth=line2.section ( "leftxauthclient=",1,1 ); + if (useXauth=="yes") + { + //std::cout << "Use XAUTH: " << i18n("yes") << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Use XAUTH (leftxauthclient found):" )+" " + i18n("yes") ,GlobalConfig->debug ); + profiledata->setAuthWithUsernameAndPassword( true ); + } + else + { + //std::cout << "Use XAUTH: " << i18n("no") << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Use XAUTH (leftxauthclient found):" )+" " + i18n("no") ,GlobalConfig->debug ); + profiledata->setAuthWithUsernameAndPassword( false ); + } +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (GlobalConfig->KvpncDebugLevel > 2) +// GlobalConfig->appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,GlobalConfig->debug); + } + if ( line2.startsWith ( "rightxauthserver=" ) ) + { + validLineFound=true; + QString useXauth=line2.section ( "rightxauthserver=",1,-1 ); + if (useXauth == "yes") + { + //std::cout << "Use XAUTH: " << i18n("yes") << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Use XAUTH (rightxauthserver found):" )+" " + i18n("yes") ,GlobalConfig->debug ); + profiledata->setAuthWithUsernameAndPassword( true ); + } + else + { + //std::cout << "Use XAUTH: " << i18n("no") << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Use XAUTH (rightxauthserver found):" )+" " + i18n("no") ,GlobalConfig->debug ); + profiledata->setAuthWithUsernameAndPassword( false ); + } +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (GlobalConfig->KvpncDebugLevel > 2) +// GlobalConfig->appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,GlobalConfig->debug); + } + if ( line2.startsWith ( "keyingtries=" ) ) + { + validLineFound=true; + int MaxConnectTries=QString(line2.section ( "keyingtries=",1,1 )).toInt(); +// std::cout << "keyingtries found: " << MaxConnectTries << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: keyingtries found: " ) + QString().setNum(MaxConnectTries) ,GlobalConfig->debug ); + profiledata->setMaxConnectTries ( MaxConnectTries ); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (GlobalConfig->KvpncDebugLevel > 2) +// GlobalConfig->appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,GlobalConfig->debug); + } + if ( line2.startsWith ( "pfs=" ) ) + { + validLineFound=true; + QString UsePerfectForwardSecrety=line2.section ( "pfs=",1,1 ).remove ( '"' ); + if (UsePerfectForwardSecrety =="yes") + { + //std::cout << "Use PFS: " << i18n("yes") << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Use PFS:" )+" " + i18n("yes") ,GlobalConfig->debug ); + profiledata->setUsePerfectForwardSecrety( true ); + } + else + { + //std::cout << "Use PFS: " << i18n("no") << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Use PFS:" )+" " + i18n("no") ,GlobalConfig->debug ); + profiledata->setUsePerfectForwardSecrety( false ); + } +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (GlobalConfig->KvpncDebugLevel > 2) +// GlobalConfig->appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,GlobalConfig->debug); + } + if ( line2.startsWith ( "pfsgroup=" ) ) + { + validLineFound=true; + QString PerfectForwardSecrety=line2.section ( "pfsgroup=",1,1 ); +// std::cout << "keyingtries found: " << MaxConnectTries << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: PFS group found: " ) + PerfectForwardSecrety ,GlobalConfig->debug ); + profiledata->setPerfectForwardSecrety ( PerfectForwardSecrety ); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (GlobalConfig->KvpncDebugLevel > 2) +// GlobalConfig->appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,GlobalConfig->debug); + } + if ( line2.startsWith ( "aggrmode=" ) ) + { + validLineFound=true; + QString UseAgressiveMode=line2.section ( "aggrmode=",1,1 ).remove ( '"' ); + if (UseAgressiveMode == "yes") + { + //std::cout << "Exchange mode: " << i18n("aggressive") << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Exchange mode:" )+" " + "aggressive" ,GlobalConfig->debug ); + profiledata->setExchangeMode( "aggressive" ); + } + else + { + //std::cout << "Exchange mode: " << i18n("main") << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Exchange mode:" )+" " + "main" ,GlobalConfig->debug ); + profiledata->setExchangeMode( "main" ); + } +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (GlobalConfig->KvpncDebugLevel > 2) +// GlobalConfig->appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,GlobalConfig->debug); + } + + else + { + // std::cout << "comment found." << std::endl; + } + } + + if ( useNat ) + { + profiledata->setUseNat ( true ); +// std::cout << "nat_traversal=yes found, enabling nat." << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: nat_traversal=yes found, enabling nat." ) ,GlobalConfig->debug ); + } + else + { + profiledata->setUseNat ( false ); +// std::cout << "nat_traversal=no found, disabling nat." << std::endl; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "import ipsec config: nat_traversal=no found, disabling nat." ) ,GlobalConfig->debug ); + } + if ( disableOpportunisticEncryption== true ) + { + profiledata->setDisableOpportunisticEncryption ( true ); + } + else + { + profiledata->setDisableOpportunisticEncryption ( false ); + } + + + // FIXME we only use the first in list + QString Interface = InterfaceList.first(); + profiledata->setNetworkDevice ( Interface ); + + profiledata->setName ( "kvpnc_import_"+profiledata->getName() ); + profiledata->setDescription ( QString ( i18n ( "import from " ) +filename ) ); + ImportedAccountList->append ( profiledata ); + } + } + + + KvpncImportProfileSelectionBase selectdlg; + selectdlg.ImportGlobalSettingsCheckBox->hide(); + selectdlg.OpenProfileManagerCheckBox->hide(); + selectdlg.ImportPushButton->setText(i18n("Import selected profile")); + VpnAccountData *it=NULL; + int importCount=0; + + if ( !ImportedAccountList->isEmpty() ) + { + selectdlg.ImportProfileListView->takeItem ( selectdlg.ImportProfileListView->currentItem() ); + selectdlg.ImportProfileListView->addColumn ( i18n ( "Name" ) ); + selectdlg.ImportProfileListView->addColumn ( i18n ( "Type" ) ); + selectdlg.ImportProfileListView->addColumn ( i18n ( "Gateway" ) ); + selectdlg.ImportProfileListView->addColumn ( i18n ( "Authentication" ) ); + selectdlg.ImportProfileListView->addColumn ( i18n ( "Remote network" ) ); + QCheckListItem *item; + for ( it = ImportedAccountList->first(); it; it = ImportedAccountList->next() ) + { + QString name = it->getName(); + QString type=""; + if ( it->getConnectionType() == VpnAccountData::cisco ) + type = "cisco" ; + else if ( it->getConnectionType() == VpnAccountData::ciscoorig ) + type = "ciscoorig" ; + else if ( it->getConnectionType() == VpnAccountData::racoon ) + type = "racoon" ; + else if ( it->getConnectionType() == VpnAccountData::l2tpd_racoon ) + type = "l2tpd (racoon)" ; + else if ( it->getConnectionType() == VpnAccountData::freeswan ) + type = "ipsec" ; + else if ( it->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + type = "l2tpd (ipsec)" ; + else if ( it->getConnectionType() == VpnAccountData::pptp ) + type = "pptp" ; + else if ( it->getConnectionType() == VpnAccountData::openvpn ) + type = "openvpn" ; + else + type = i18n ( "other" ); + +// litem->setSelectable(true); + item = new QCheckListItem ( selectdlg.ImportProfileListView,it->getName(),QCheckListItem::RadioButton ); + item->setText ( 1,type ); + item->setText ( 2,it->getGateway() ); + if ( it->getAuthType() == VpnAccountData::cert ) + item->setText ( 3,i18n ( "certificate" ) ); + else if ( it->getAuthType() == VpnAccountData::psk ) + item->setText ( 3,i18n ( "preshared key" ) ); + else + item->setText ( 3,i18n ( "unknown" ) ); + selectdlg.ImportProfileListView->insertItem ( item ); + QString RemoteNetDiv="/"; + if ( it->getRemoteNetAddr() == "" ) + { + it->setRemoteNetMask ( "" ); + RemoteNetDiv=""; + } + item->setText ( 4,QString ( it->getRemoteNetAddr() +RemoteNetDiv+it->getRemoteNetMask() ) ); + +// std::cout << "insert profile into listview: " << name << std::endl; + } + } + bool ret = selectdlg.exec(); + bool profilefound=false; + + if ( ret == true ) + { + QListViewItemIterator it2 ( selectdlg.ImportProfileListView ); + for ( ; it2.current(); ++it2 ) + { + if ( profilefound==false ) + { + if ( ( ( QCheckListItem* ) it2.current() )->isOn() ) + { + VpnAccountData *data=NULL; + it = 0; + for ( it = ImportedAccountList->first(); it; it = ImportedAccountList->next() ) + { + if ( it->getName() == ( ( QCheckListItem* ) it2.current() )->text() && ( ( QCheckListItem* ) it2.current() )->isOn() ) + { + acc = it; + profilefound=true; + importOk = true; + break; + } + } + } + } + } + } + else + { + KMessageBox::sorry ( 0, i18n ( "IPSec file import canceled." ) ); + return; + } + + +// KMessageBox::information ( 0, msg,i18n("Import success") ); + importOk = true; + } + else + importOk = false; + + //std::cout << "accept" << std::endl; + QDialog::accept(); +} + diff --git a/src/importipsecprofiledialog.h b/src/importipsecprofiledialog.h new file mode 100644 index 0000000..dff2f18 --- /dev/null +++ b/src/importipsecprofiledialog.h @@ -0,0 +1,58 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef __IMPORTIPSECPROFILEDIALOG_H__ +#define __IMPORTIPSECPROFILEDIALOG_H__ + +#include +#include "importopenvpnprofiledialogbase.h" +#include "vpnaccountdata.h" +#include "kvpncconfig.h" +/** + @author Christoph Thielecke +*/ +class ImportIpsecProfileDialog : public KDialogBase +{ + public: + ImportIpsecProfileDialog( KVpncConfig *config, QWidget *parent, const QString& caption, QString file); + ~ImportIpsecProfileDialog(); + + void canAccept(); + QString filename; + bool importOk; + VpnAccountData *acc; + ImportOpenvpnProfileDialogBase *main; + + private: + struct IpsecImportSection { + QString SectionName; + QStringList SectionData; + }; + +public slots: + void accept(); + void reject(); + +private: + KVpncConfig* GlobalConfig; + QString Pkcs12CertFile; + QString CertPath; +}; + +#endif diff --git a/src/importopenvpnprofiledialog.cpp b/src/importopenvpnprofiledialog.cpp new file mode 100644 index 0000000..1a4877e --- /dev/null +++ b/src/importopenvpnprofiledialog.cpp @@ -0,0 +1,1136 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* @description This class imports a openvpn configuration file * +* * +* @author Christoph Thielecke * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +//BEGIN INCLUDES +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "importopenvpnprofiledialog.h" +#include "utils.h" +#include "importcertificatedialog.h" +//END INCLUDES + +ImportOpenvpnProfileDialog::ImportOpenvpnProfileDialog ( KVpncConfig *config, QWidget *parent, const QString& caption, QString file ) + : KDialogBase ( parent, "Import_Cisco_OpenVPN_profile", true, caption, + KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, true ) +{ + if ( !file.isEmpty() ) + filename = file; + else + filename = ""; + Pkcs12CertFile = ""; + // CertPath="/etc/openvpn"; + importOk = false; + this->config = config; + + main = new ImportOpenvpnProfileDialogBase ( this ); + setMainWidget ( main ); + //main->setMinimumSize(main->sizeHint()); + + main->FilenameUrlrequester->setFilter ( "*.ovpn *.conf" ); + + main->FilenameUrlrequester->setURL ( filename ); + + main->OpenProfileManagerCheckBox->hide(); + +} + +ImportOpenvpnProfileDialog::~ImportOpenvpnProfileDialog() +{ + delete main; +} + +void ImportOpenvpnProfileDialog::accept() +{ + + filename = main->FilenameUrlrequester->url(); + if ( !filename.isEmpty() ) + { + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: file: %1" ).arg ( filename ), config->debug ); + canAccept(); + } + else + { + config->appendLogEntry ( i18n ( "OpenVPN import: file name empty" ), config->error ); + KMessageBox::sorry ( 0, i18n ( "File name can not be empty!" ), i18n ( "Empty File Name" ) ); + } +} + +void ImportOpenvpnProfileDialog::canAccept() +{ + + QFile f ( filename ); + if ( !f.exists() ) + { + KMessageBox::sorry ( 0, i18n ( "File not found." ), i18n ( "No File" ) ); + + // emit progress( 100 ); + return ; + } + + //BEGIN Sample + // sample config + + /* + # + # Sample OpenVPN configuration file for + # home using SSL/TLS mode and RSA certificates/keys. + # + # '#' or ';' may be used to delimit comments. + + ####################################################### + # PATS INFORMATION: + # No adaptations necessary in this file, unless you + # give different names to your certificates or you + # place them in different folders + ###################################################### + + + # Use a dynamic tun device. + # For Linux 2.2 or non-Linux OSes, + # you may want to use an explicit + # unit number such as "tun1". + # OpenVPN also supports virtual + # ethernet "tap" devices. + dev tap + + # Our OpenVPN peer is the PATS gateway. + remote 143.129.70.202 + + float + + # In SSL/TLS key exchange, Office will + # assume server role and Home + # will assume client role. + tls-client + + # pull necessary here. This option will + # enable the server to push commands to + # the client + pull + + route 10.0.0.0 255.255.0.0 vpn_gateway + + # Certificate Authority file + ca cacert.pem + + # Our certificate/public key + cert cert.pem + + # Our private key + key key.pem + + # OpenVPN uses UDP port 5000 by default. + port 5000 + + # Downgrade UID and GID to + # "nobody" after initialization + # for extra security. + ; user nobody + ; group nobody + + # If you built OpenVPN with + # LZO compression, uncomment + # out the following line. + # PREFFERED + comp-lzo + + # Uncomment this section for a more reliable detection when a system + # loses its connection. For example, dial-ups or laptops that + # travel to other locations. + # This commands will be pushed through by the server + ; ping 15 + ; ping-restart 45 + ; ping-timer-rem + ; persist-tun + ; persist-key + + # Verbosity level. + # 0 -- quiet except for fatal errors. + # 1 -- mostly quiet, but display non-fatal network errors. PREFERRED + # 3 -- medium output, good for normal operation. + # 9 -- verbose, good for troubleshooting + verb 1 + */ + + /* Example 2 + client + dev tun + + proto udp + remote 10.7.21.1 1194 + + resolv-retry infinite + ns-cert-type server + nobind + user nobody + group nogroup + persist-key + persist-tun + + ca certs/richard-root-ca.crt + cert certs/richard-openvpn-notebook-richard.crt + key certs/richard-openvpn-notebook-richard.key + + cipher AES-128-CBC + ping 15 + ping-restart 45 + ping-timer-rem + persist-tun + persist-key + + comp-lzo + verb 3 + */ + //END Sample + + QFile OpenvpnConfigFile ( filename ); + QTextStream stream ( &OpenvpnConfigFile ); + + QString importprefix = QFileInfo ( filename ).dirPath(); + + if ( config->KvpncDebugLevel > 2 ) + config->appendLogEntry ( i18n ( "OpenVPN import: import prefix: %1" ).arg ( importprefix ), config->debug ); + + QString certprefix = locateLocal ( "data", "kvpnc" ); + + if ( OpenvpnConfigFile.open ( IO_ReadOnly ) ) + { + VpnAccountData::ConnectionType ConnType = VpnAccountData::openvpn; + acc = new VpnAccountData ( ConnType, "" ); + QString profilename = Utils ( config ).removeSpecialCharsForFilename ( filename.section ( '/', -1, -1 ) ).section ( '.', -2, -2 ); + acc->setName ( profilename ); // /home/user/openvpn/CompanyABC.conf -> CompanyABC + acc->setDescription ( i18n ( "Imported from %1" ).arg ( Utils ( config ).removeSpecialCharsForFilename ( filename.section ( '/', -1, -1 ) ) ) ); + acc->setLocalPort ( 1194 ); + acc->setAuthWithUsernameAndPassword ( false ); + acc->setRemoteNetMask ( "24" ); + acc->setAuthenticationAlgorithm ( "MD5" ); + acc->setDisableLzoCompression ( true ); + acc->setRemotePort ( 1194 ); + acc->setUseUdp( false ); + acc->setUseTlsAuth ( false ); + // acc->setUseConnectionStatusCheck( false ); + // acc->setDoReconnectAfterConnectionLost( false ); + + // inline cert settings + QString CaCert=""; + QString Cert=""; + QString PrivateKey=""; + QString StaticKey=""; + bool CaCertStartFound=false; + bool CertStartFound=false; + bool PrivateKeyStartFound=false; + bool StaticKeyStartFound=false; + bool TlsAuthStartFound=false; + + QString line = ""; + while ( !stream.atEnd() ) + { + QString line_raw = stream.readLine(); + line = line_raw.simplifyWhiteSpace(); // line of text excluding '\n' and replace all white chars with one blank + + /* look for inline parts */ + if (CaCertStartFound) + { + if ( line.startsWith ( "") ) + { + if ( config->KvpncDebugLevel > 4 ) + config->appendLogEntry ( i18n ( "OpenVPN import: inlince ca end found." ), config->debug ); + + QString CaFilePath = certprefix+"/"+"openvpn_ca_"+profilename+".pem"; + if ( config->KvpncDebugLevel > 2 ) + config->appendLogEntry ( i18n ( "OpenVPN import: ca file: %1" ).arg ( CaFilePath ), config->debug ); + + QFile CaFileHandle (CaFilePath); + if( CaFileHandle.open(IO_WriteOnly)) + { + QTextStream ExportStream ( &CaFileHandle ); + ExportStream << CaCert; + CaFileHandle.close(); + acc->setCaCertificate ( CaFilePath ); + } + else + { + KMessageBox::error ( 0, i18n ( "Creating of \"%1\" has been failed!" ).arg ( CaFilePath ) ); + } + + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: CA certificate: %1" ).arg ( acc->getCaCertificate() ), config->debug ); + CaCertStartFound = false; + } + else + { + CaCert += line_raw +"\n"; + continue; + } + } + if (CertStartFound) + { + if ( line.startsWith ( "") ) + { + if ( config->KvpncDebugLevel > 4 ) + config->appendLogEntry ( i18n ( "OpenVPN import: inlince cert end found." ), config->debug ); + + QString CertFilePath = certprefix+"/"+"openvpn_cert_"+profilename+".pem"; + if ( config->KvpncDebugLevel > 2 ) + config->appendLogEntry ( i18n ( "OpenVPN import: cert file: %1" ).arg ( CertFilePath ), config->debug ); + + acc->setAuthType ( VpnAccountData::cert ); + acc->setCertPath (certprefix); + + QFile CertFileHandle (CertFilePath); + if( CertFileHandle.open(IO_WriteOnly)) + { + QTextStream ExportStream ( &CertFileHandle ); + ExportStream << Cert; + CertFileHandle.close(); + acc->setX509Certificate ( CertFilePath ); + } + else + { + KMessageBox::error ( 0, i18n ( "Creating of \"%1\" has been failed!" ).arg ( CertFilePath ) ); + } + + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: certificate: %1" ).arg ( acc->getX509Certificate() ), config->debug ); + CertStartFound = false; + } + else + { + Cert += line_raw +"\n"; + continue; + } + } + if (PrivateKeyStartFound) + { + if ( line.startsWith ( "") ) + { + if ( config->KvpncDebugLevel > 4 ) + config->appendLogEntry ( i18n ( "OpenVPN import: inlince private key end found." ), config->debug ); + + QString PrivateKeyFilePath = certprefix+"/"+"openvpn_privatekey_"+profilename+".pem"; + if ( config->KvpncDebugLevel > 2 ) + config->appendLogEntry ( i18n ( "OpenVPN import: private key file: %1" ).arg ( PrivateKeyFilePath ), config->debug ); + + QFile PrivateKeyFileHandle (PrivateKeyFilePath); + if( PrivateKeyFileHandle.open(IO_WriteOnly)) + { + QTextStream ExportStream ( &PrivateKeyFileHandle ); + ExportStream << PrivateKey << "\n"; + PrivateKeyFileHandle.close(); + acc->setPrivateKey ( PrivateKeyFilePath ); + } + else + { + KMessageBox::error ( 0, i18n ( "Creating of \"%1\" has been failed!" ).arg ( PrivateKeyFilePath ) ); + } + + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: private key file: %1" ).arg ( acc->getPrivateKey()), config->debug ); + PrivateKeyStartFound = false; + } + else + { + PrivateKey += line_raw+"\n"; + continue; + } + } + if (TlsAuthStartFound) + { + if ( line.startsWith ( "") ) + { + if ( config->KvpncDebugLevel > 4 ) + config->appendLogEntry ( i18n ( "OpenVPN import: inlince tls-auth end found." ), config->debug ); + + QString StaticKeyFilePath = certprefix+"/"+"openvpn_tlsauth_"+profilename+".pem"; + if ( config->KvpncDebugLevel > 2 ) + config->appendLogEntry ( i18n ( "OpenVPN import: TLS auth file: %1" ).arg ( StaticKeyFilePath ), config->debug ); + + QFile StaticKeyFileHandle (StaticKeyFilePath); + if( StaticKeyFileHandle.open(IO_WriteOnly)) + { + QTextStream ExportStream ( &StaticKeyFileHandle ); + ExportStream << StaticKey << "\n"; + StaticKeyFileHandle.close(); + acc->setTlsAuthFile ( StaticKeyFilePath ); + acc->setUseTlsAuth (true); + } + else + { + KMessageBox::error ( 0, i18n ( "Creating of \"%1\" has been failed!" ).arg ( StaticKeyFilePath ) ); + } + + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: TLS auth file: %1" ).arg ( acc->getTlsAuthFile() ), config->debug ); + StaticKeyStartFound = false; + } + else + { + StaticKey += line_raw +"\n"; + continue; + } + } + + /* special useful information */ + if ( line.startsWith ( "# OVPN_ACCESS_SERVER_USERNAME=" ) ) + { + int equalidx = line.find ( '=' ); + acc->setUserName(line.right (line.length()-equalidx-1)); + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: username found (via special line): %1" ).arg ( acc->getUserName() ), config->debug ); + } + line.remove ( '\"' ); + if ( !line.startsWith ( "#" ) && !line.startsWith ( ";" ) ) + { + int commentidx = line.find ( '#' ); + if ( commentidx > -1 ) + line = line.left ( commentidx - 1 ); + + if ( line.startsWith ( "remote " ) ) + { + acc->setGateway ( line.section ( ' ', 1, 1 ) ); // IP address + if ( !line.section ( ' ', 2, 2 ).isEmpty() ) + { + acc->setUseRemotePort ( true ); + acc->setRemotePort ( line.section ( ' ', 2, 2 ).toInt() ); + + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: use userdefined remote port: %1" ).arg ( acc->getRemotePort() ), config->debug ); + } + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: gateway: %1" ).arg ( acc->getGateway() ), config->debug ); + } + else if ( line.startsWith ( "dev " ) ) + { + QString Type = line.section ( ' ', 1, 1 ); // tun or tap + if ( Type == "tun" || Type == "tap" ) + { + acc->setTunnelDeviceType ( Type ); + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: tunnel device type: %1" ).arg ( acc->getTunnelDeviceType() ), config->debug ); + } + } + else if ( line.startsWith ( "route " ) ) + { + // FIXME no fully supported yet!!! + + // FIXME made it possible to remember what type have to been set! + QString gateway_type = ""; + bool useGateway; + acc->setUseAdditionalNetworkRoutes ( true ); + QStringList AdditionalNetworkRoutes; + // example entry: + // /# + + QString network = line.section ( ' ', 1, 1 ) + "/" + line.section ( ' ', 2, 2 ); // ip and netmask + + QString Part3 = line.section ( ' ', 3, 3 ); // possible gateway + if ( Part3 != "vpn_gateway" && Part3 != "net_gateway" && Part3 != "remote_host" ) + { + network.append ( "#" ); + network.append ( Part3 ); // gateway + gateway_type = line.section ( ' ', 3, 3 ); + useGateway = true; + } + else + { + gateway_type = Part3; + } + + AdditionalNetworkRoutes.append ( network ); + acc->setAdditionalNetworkRoutes ( AdditionalNetworkRoutes ); + + if ( config->KvpncDebugLevel > 0 ) + if ( useGateway ) + config->appendLogEntry ( i18n ( "OpenVPN import: special route found: %1, type: %2" ).arg ( network ).arg ( gateway_type ), config->debug ); + else + config->appendLogEntry ( i18n ( "OpenVPN import: special route found: %1 over %3, type: %2" ).arg ( network ).arg ( gateway_type ).arg ( Part3 ), config->debug ); + } + else if ( line.startsWith ( "port " ) ) + { + acc->setUseLocalPort ( true ); + acc->setLocalPort ( line.section ( ' ', 1, 1 ).toInt() ); + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: local port specified: %1" ).arg ( acc->getLocalPort() ), config->debug ); + } + else if ( line.startsWith ( "comp-lzo" ) ) + { + acc->setDisableLzoCompression ( false ); + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: use LZO compression" ), config->debug ); + } + else if ( line.startsWith ( "cert " ) ) + { + acc->setAuthType ( VpnAccountData::cert ); + QString cert = line.section ( ' ', 1 ).stripWhiteSpace(); + + if ( config->KvpncDebugLevel > 2 ) + config->appendLogEntry ( i18n ( "OpenVPN import: cert file: %1" ).arg ( importprefix+"/"+cert ), config->debug ); + + if ( QFile ( QString ( importprefix+"/"+cert ) ).exists() ) + { + // copy to ~/.kde/share/apps/kvpnc/ and rename it + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: copy %1 to %2" ).arg ( QString ( importprefix+"/"+cert ) ).arg ( QString ( certprefix+"/"+"openvpn_cert_"+profilename+"_"+cert ) ), config->debug ); + QProcess CopyProcess ( this ); + CopyProcess.addArgument ( "cp" ); + CopyProcess.addArgument ( QString ( importprefix+"/"+cert ) ); + CopyProcess.addArgument ( QString ( certprefix+"/"+"openvpn_cert_"+profilename+"_"+cert ) ); + if ( CopyProcess.start() ) + { + while (CopyProcess.isRunning()) + { + sleep(1); + } + acc->setX509Certificate ( QString ( certprefix+"/"+"openvpn_cert_"+profilename+"_"+cert ) ); + } + else + { + config->appendLogEntry ( i18n ( "Could not start %1!" ).arg ( "cp" ), config->error ); + acc->setX509Certificate ( cert ); + } + } + else + { + // we use the given path + acc->setX509Certificate ( cert ); + } + + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: certificate: %1" ).arg ( acc->getX509Certificate() ), config->debug ); + } + else if ( line.startsWith ( "key " ) ) + { + + QString privatekey = line.section ( ' ', 1 ).stripWhiteSpace(); + + if ( config->KvpncDebugLevel > 2 ) + config->appendLogEntry ( i18n ( "OpenVPN import: private key file for certificate: %1" ).arg ( importprefix+"/"+privatekey ), config->debug ); + + if ( QFile ( QString ( importprefix+"/"+privatekey ) ).exists() ) + { + // copy to ~/.kde/share/apps/kvpnc/ and rename it + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: copy %1 to %2" ).arg ( QString ( importprefix+"/"+privatekey ) ).arg ( QString ( certprefix+"/"+"openvpn_privatekey_"+profilename+"_"+privatekey ) ), config->debug ); + QProcess CopyProcess ( this ); + CopyProcess.addArgument ( "cp" ); + CopyProcess.addArgument ( QString ( importprefix+"/"+privatekey ) ); + CopyProcess.addArgument ( QString ( certprefix+"/"+"openvpn_privatekey_"+profilename+"_"+privatekey ) ); + if ( CopyProcess.start() ) + { + while (CopyProcess.isRunning()) + { + sleep(1); + } + acc->setPrivateKey ( QString ( certprefix+"/"+"openvpn_privatekey_"+profilename+"_"+privatekey ) ); + } + else + { + config->appendLogEntry ( i18n ( "Could not start %1!" ).arg ( "cp" ), config->error ); + acc->setPrivateKey ( privatekey ); + } + } + else + { + // we use the given path + acc->setPrivateKey ( privatekey ); + } + + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: private key for certificate in file: %1" ).arg ( acc->getPrivateKey() ), config->debug ); + } + else if ( line.startsWith ( "secret " ) ) + { + acc->setAuthType ( VpnAccountData::psk ); + + QString privatekey = line.section ( ' ', 1 ).stripWhiteSpace(); + + if ( config->KvpncDebugLevel > 2 ) + config->appendLogEntry ( i18n ( "OpenVPN import: private key file: %1" ).arg ( importprefix+"/"+privatekey ), config->debug ); + + if ( QFile ( QString ( importprefix+"/"+privatekey ) ).exists() ) + { + // copy to ~/.kde/share/apps/kvpnc/ and rename it + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: copy %1 to %2" ).arg ( QString ( importprefix+"/"+privatekey ) ).arg ( QString ( certprefix+"/"+"openvpn_privatekey_"+profilename+"_"+privatekey ) ), config->debug ); + QProcess CopyProcess ( this ); + CopyProcess.addArgument ( "cp" ); + CopyProcess.addArgument ( QString ( importprefix+"/"+privatekey ) ); + CopyProcess.addArgument ( QString ( certprefix+"/"+"openvpn_privatekey_"+profilename+"_"+privatekey ) ); + if ( CopyProcess.start() ) + { + while (CopyProcess.isRunning()) + { + sleep(1); + } + acc->setPreSharedKeyFile ( QString ( certprefix+"/"+"openvpn_privatekey_"+profilename+"_"+privatekey ) ); + acc->setSavePsk ( false ); + } + else + { + config->appendLogEntry ( i18n ( "Could not start %1!" ).arg ( "cp" ), config->error ); + } + } + else + { + // we use the given path + acc->setPreSharedKeyFile ( privatekey ); + } + acc->setPskIsInFile ( true ); + + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: PSK in file: %1" ).arg ( acc->getPreSharedKeyFile() ), config->debug ); + } + else if ( line.startsWith ( "ca " ) ) + { + acc->setAuthType ( VpnAccountData::cert ); + + QString ca = line.section ( ' ', 1 ); + + if ( config->KvpncDebugLevel > 2 ) + config->appendLogEntry ( i18n ( "OpenVPN import: ca file: %1" ).arg ( importprefix+"/"+ca ), config->debug ); + + if ( QFile ( QString ( importprefix+"/"+ca ) ).exists() ) + { + // copy to ~/.kde/share/apps/kvpnc/ and rename it + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: copy %1 to %2" ).arg ( QString ( importprefix+"/"+ca ) ).arg ( QString ( certprefix+"/"+"openvpn_privatekey_"+profilename+"_"+ca ) ), config->debug ); + QProcess CopyProcess ( this ); + CopyProcess.addArgument ( "cp" ); + CopyProcess.addArgument ( QString ( importprefix+"/"+ca ) ); + CopyProcess.addArgument ( QString ( certprefix+"/"+"openvpn_privatekey_"+profilename+"_"+ca ) ); + if ( CopyProcess.start() ) + { + while (CopyProcess.isRunning()) + { + sleep(1); + } + acc->setCaCertificate ( QString ( certprefix+"/"+"openvpn_privatekey_"+profilename+"_"+ca ) ); + } + else + { + config->appendLogEntry ( i18n ( "Could not start %1!" ).arg ( "cp" ), config->error ); + acc->setCaCertificate ( ca ); + } + } + else + { + // we use the given path + acc->setCaCertificate ( ca ); + } + + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: CA certificate: %1" ).arg ( acc->getCaCertificate() ), config->debug ); + } + else if ( line.startsWith ( "") ) + { + /* inline ca cert */ + CaCertStartFound=true; + if ( config->KvpncDebugLevel > 4 ) + config->appendLogEntry ( i18n ( "OpenVPN import: inline ca start found" ), config->debug ); + } + else if ( line.startsWith ( "") ) + { + /* inline cert */ + CertStartFound=true; + if ( config->KvpncDebugLevel > 4 ) + config->appendLogEntry ( i18n ( "OpenVPN import: inline cert start found" ), config->debug ); + } + else if ( line.startsWith ( "") ) + { + /* inline private key */ + PrivateKeyStartFound=true; + if ( config->KvpncDebugLevel > 4 ) + config->appendLogEntry ( i18n ( "OpenVPN import: inline private key start found" ), config->debug ); + } + else if ( line.startsWith ( "") ) + { + /* inline tls-auth cert */ + TlsAuthStartFound=true; + if ( config->KvpncDebugLevel > 4 ) + config->appendLogEntry ( i18n ( "OpenVPN import: inline tls-auth start found" ), config->debug ); + } + else if ( line.startsWith ( "proto " ) ) + { + if ( line.section ( ' ', 1, 1 ) == "udp" ) + { + acc->setUseUdp ( true ); + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: use UDP" ), config->debug ); + } + else if ( line.section ( ' ', 1, 1 ) == "tcp-client" ) + { + acc->setUseUdp ( false ); + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: dont use UDP" ), config->debug ); + } + + } + else if ( line.startsWith ( "cipher " ) ) + { + acc->setUseUserdefiniedCipher ( true ); + acc->setUserdefiniedCipher ( line.section ( ' ', 1, 1 ) ); + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: use userdefined cipher" ), config->debug ); + } + else if ( line.startsWith ( "tls-auth " ) ) + { + acc->setUseTlsAuth ( true ); + + QString tlsauth = line.section ( ' ', 1,1 ); + QString tlsauthdirection = line.section ( ' ', 2,2 ); + + if ( config->KvpncDebugLevel > 2 ) + { + config->appendLogEntry ( i18n ( "OpenVPN import: TLS auth file: %1" ).arg ( importprefix+"/"+tlsauth ), config->debug ); + config->appendLogEntry ( i18n ( "OpenVPN import: TLS auth direction: %1" ).arg ( tlsauthdirection ), config->debug ); + } + + if ( QFile ( QString ( importprefix+"/"+tlsauth ) ).exists() ) + { + // copy to ~/.kde/share/apps/kvpnc/ and rename it + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: copy %1 to %2" ).arg ( QString ( importprefix+"/"+tlsauth ) ).arg ( QString ( certprefix+"/"+"openvpn_privatekey_"+profilename+"_"+tlsauth ) ), config->debug ); + QProcess CopyProcess ( this ); + CopyProcess.addArgument ( "cp" ); + CopyProcess.addArgument ( QString ( importprefix+"/"+tlsauth ) ); + CopyProcess.addArgument ( QString ( certprefix+"/"+"openvpn_tlsauth_"+profilename+"_"+tlsauth ) ); + if ( CopyProcess.start() ) + { + while (CopyProcess.isRunning()) + { + sleep(1); + } + acc->setTlsAuthFile ( QString ( certprefix+"/"+"openvpn_tlsauth_"+profilename+"_"+tlsauth ) ); + } + else + { + config->appendLogEntry ( i18n ( "Could not start %1!" ).arg ( "cp" ), config->error ); + acc->setTlsAuthFile ( tlsauth ); + } + } + else + { + // we use the given path + acc->setTlsAuthFile ( tlsauth ); + } + + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: use TLS auth" ), config->debug ); + + if (!tlsauthdirection.isEmpty() && ( tlsauthdirection=="0") || ( tlsauthdirection=="1") || ( tlsauthdirection=="none") ) + { + acc->setAuthenticationDirection(tlsauthdirection); + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: use TLS auth direction: %1" ).arg(tlsauthdirection), config->debug ); + } + } + else if ( line.startsWith ( "redirect-gateway" ) ) + { + acc->setUseRedirectGateway ( true ); + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: use redirect gateway" ), config->debug ); + } + else if ( line.startsWith ( "ns-cert-type " ) ) + { + acc->setUseNsCertType ( true ); + + if ( line.section ( ' ', 1, 1 ) == "client" ) + { + acc->setNsCertType ( "client" ); + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: use NS certificate type: %1" ).arg ( "client" ), config->debug ); + } + if ( line.section ( ' ', 1, 1 ) == "server" ) + { + acc->setNsCertType ( "server" ); + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: use NS certificate type: %1" ).arg ( "server" ), config->debug ); + } + } + else if ( line.startsWith ( "auth-user-pass" ) ) + { + acc->setAuthWithUsernameAndPassword ( true ); + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: authenticate with username and password" ), config->debug ); + } + else if ( line.startsWith ( "http-proxy " ) ) + { + acc->setUseHttpProxy ( true ); + acc->setHttpProxy ( line.section ( ' ', 1, 1 ) ); + acc->setHttpProxyPort ( line.section ( ' ', 2, 2 ).toInt() ); + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: use HTTP proxy: %1, Port: %2" ).arg ( acc->getHttpProxy() ).arg ( QString().setNum ( acc->getHttpProxyPort() ) ), config->debug ); + } + else if ( line.startsWith ( "http-proxy-timeout " ) ) + { + acc->setUseHttpProxy ( true ); + acc->setHttpProxyTimeout ( line.section ( ' ', 1, 1 ).toInt() ); + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: use NS certificate type: %1" ).arg ( QString().setNum ( acc->getHttpProxyTimeout() ) ), config->debug ); + } + else if ( line.startsWith ( "pkcs12 " ) ) + { + acc->setAuthType ( VpnAccountData::cert ); + Pkcs12CertFile = line.section ( ' ', 1 ); + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: pkcs12 file found: %1" ).arg ( Pkcs12CertFile ), config->debug ); + } + else if ( line.startsWith ( "cd " ) ) + { + CertPath = line.section ( ' ', 1 ); + + // + // if (!Pkcs12CertFile.isEmpty() && !acc->getCaCertificate().startsWith(CertPath)) + // Pkcs12CertFile=CertPath+"/"+Pkcs12CertFile; + + + acc->setCertPath ( CertPath ); + + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: certificate prefix found: %1" ).arg ( CertPath ), config->debug ); + } + else if ( line.startsWith ( "tls-remote" ) ) + { + if ( !line.section ( ' ', 1, 1 ).isEmpty() ) + { + acc->setUseTlsRemoteHost ( true ); + acc->setTlsRemoteHost ( line.section ( ' ', 1, 1 ) ); + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: use tls remote host: %1" ).arg ( acc->getTlsRemoteHost() ), config->debug ); + } + else + { + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: tls remote host option was specified but server is empty, disabling TLS remote host." ), config->debug ); + } + } + else if ( line.startsWith ( "float" ) ) + { + acc->setAllowIpAddressChangeOfPeer ( true ); + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: allow IP address change of peer (for DHCP)" ), config->debug ); + } + else if ( line.startsWith ( "ifconfig " ) ) + { + acc->setUseVirtualIP ( true ); + QString VirtualIpLocal = line.section ( ' ', 1, 1 ); + QString VirtualIpRemote = line.section ( ' ', 2, 2 ); + acc->setLocalVirtualIP ( VirtualIpLocal ); + acc->setRemoteVirtualIP ( VirtualIpRemote ); + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: use virtual IP address. Local: %1, remote: %2" ).arg ( VirtualIpLocal ).arg ( VirtualIpRemote ), config->debug ); + } + else if ( line.startsWith ( "client" ) ) + { + // client -> tls-client + pull + acc->setDisablePushFromServer ( false ); + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: Disable push from server: %1" ).arg ( i18n("no") ), config->debug ); + } + else if ( line.startsWith ( "tls-client" ) ) + { + +// if ( config->KvpncDebugLevel > 0 ) +// config->appendLogEntry ( i18n ( "OpenVPN import: use virtual IP address. Local: %1, remote: %2" ).arg ( VirtualIpLocal ).arg ( VirtualIpRemote ), config->debug ); + } + else if ( line.startsWith ( "pull" ) ) + { + acc->setDisablePushFromServer ( false ); + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: Disable push from server: %1" ).arg ( i18n("no") ), config->debug ); + } + else if ( line.startsWith ( "fragment " ) ) + { + acc->setUseFragment( true ); + int Fragment = QString(line.section ( ' ', 1, 1 )).toInt(); + acc->setFragment( Fragment ); + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: use fragmention, size: %1" ).arg ( QString().setNum(Fragment) ), config->debug ); + } + else if ( line.startsWith ( "inactive " ) ) + { +// acc->setUseVirtualIP ( true ); +// QString VirtualIpLocal = line.section ( ' ', 1, 1 ); +// QString VirtualIpRemote = line.section ( ' ', 2, 2 ); +// acc->setLocalVirtualIP ( VirtualIpLocal ); +// acc->setRemoteVirtualIP ( VirtualIpRemote ); +// if ( config->KvpncDebugLevel > 0 ) +// config->appendLogEntry ( i18n ( "OpenVPN import: use virtual IP address. Local: %1, remote: %2" ).arg ( VirtualIpLocal ).arg ( VirtualIpRemote ), config->debug ); + } + else if ( line.startsWith ( "mssfix" ) ) + { + acc->setUseMssfix ( true ); + int Mssfix = QString(line.section ( ' ', 1, 1 )).toInt(); + acc->setMssfix( Mssfix ); + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: use Mssfix, size: %1" ).arg ( QString().setNum(Mssfix )), config->debug ); + } + else if ( line.startsWith ( "nobind" ) ) + { + acc->setDisableBind ( true ); + + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: Disable bind: %1" ).arg ( i18n("yes") ), config->debug ); + } + else if ( line.startsWith ( "ping " ) ) + { + acc->setUseTunnelPing( true ); + int TunnelPing = QString(line.section ( ' ', 1, 1 )).toInt(); + acc->setTunnelPing ( TunnelPing); + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: use ping through tunnel every: %1" ).arg ( QString().setNum(TunnelPing) ), config->debug ); + } + else if ( line.startsWith ( "ping-restart " ) ) + { + acc->setUseTunnelPingRestart( true ); + int TunnelPingRestart = QString(line.section ( ' ', 1, 1 )).toInt(); + acc->setTunnelPingRestart ( TunnelPingRestart ); + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: restart ping through tunnel fails after: %1" ).arg ( QString().setNum(TunnelPingRestart) ), config->debug ); + } + else if ( line.startsWith ( "reneg-sec " ) ) + { + acc->setUseRenegSec ( true ); + int RenegSec =QString(line.section ( ' ', 1, 1 )).toInt(); + acc->setRenegSec ( RenegSec ); + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: use reneg-sec: %1" ).arg ( QString().setNum(RenegSec) ), config->debug ); + } + else if ( line.startsWith ( "tun-mtu " ) ) + { + acc->setUseMtu ( true ); + int Mtu = QString(line.section ( ' ', 1, 1 )).toInt(); + acc->setMtu ( Mtu ); + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "OpenVPN import: use usedefinied MTU: %1" ).arg ( QString().setNum(Mtu) ), config->debug ); + } + } + } + +// if ( acc->getCertPath().isEmpty() ) { +// // acc->setCertPath("/etc/openvpn/"); +// acc->setCertPath( locateLocal ( "data", "kvpnc" ) ); +// CertPath = acc->getCertPath(); +// } +// // /* we need to put the prefix to all cert paths */ +// if ( !acc->getCaCertificate().isEmpty() && !acc->getCaCertificate().startsWith( CertPath ) ) { +// QString prefix = "./"; +// if ( !filename.find( '/' ) > -1 ) +// prefix = QString( Utils(this->GlobalConfig).removeSpecialCharsForFilename( filename).section( '/', 0, -2 ) + "/" ); +// +// QFile CaCertFileSrc ( prefix + acc->getCaCertificate() ); +// QFile CaCertFileDst ( QString( CertPath + "/openvpnimport_" + acc->getCaCertificate() ) ); +// acc->setCaCertificate( QString( CertPath + "/openvpnimport_" + acc->getCaCertificate() ) ); +// +// QTextStream CaCertDstStream( &CaCertFileDst ); +// +// if ( config->KvpncDebugLevel > 1 ) +// config->appendLogEntry( i18n( "OpenVPN import: try to copy ca cert file %1 to %2." ).arg( CaCertFileSrc.name() ).arg( CaCertFileDst.name() ), config->debug ); +// +// +// if ( CaCertFileSrc.open( IO_ReadOnly ) ) { +// if ( CaCertFileDst.open( IO_WriteOnly ) ) { +// QString CaCertFileString = QString( CaCertFileSrc.readAll() ); +// CaCertDstStream << CaCertFileString; +// CaCertFileDst.close(); +// if ( config->KvpncDebugLevel > 1 ) +// config->appendLogEntry( i18n( "OpenVPN import: ca cert file %1 copied to %2." ).arg( CaCertFileSrc.name() ).arg( CaCertFileDst.name() ), config->debug ); +// } else { +// if ( config->KvpncDebugLevel > 2 ) +// config->appendLogEntry( i18n( "OpenVPN import: ca cert file %1 could not open for writing." ).arg( CaCertFileDst.name() ), config->debug ); +// +// // return; +// } +// CaCertFileDst.close(); +// } else { +// if ( config->KvpncDebugLevel > 2 ) +// config->appendLogEntry( i18n( "OpenVPN import: ca cert file %1 could not open for reading." ).arg( CaCertFileSrc.name() ), config->debug ); +// +// // return; +// } +// } +// if ( !acc->getX509Certificate().isEmpty() && !acc->getX509Certificate().startsWith( CertPath ) ) { +// QString prefix = "./"; +// if ( !filename.find( '/' ) > -1 ) +// prefix = QString( Utils(this->GlobalConfig).removeSpecialCharsForFilename(filename).section( '/', 0, -2 ) + "/" ); +// +// QFile X509CertFileSrc ( prefix + acc->getX509Certificate() ); +// QFile X509CertFileDst ( QString( CertPath + "/openvpnimport_" + acc->getX509Certificate() ) ); +// acc->setX509Certificate( QString( CertPath + "/openvpnimport_" + acc->getX509Certificate() ) ); +// +// QTextStream X509CertDstStream( &X509CertFileDst ); +// +// if ( config->KvpncDebugLevel > 1 ) +// config->appendLogEntry( i18n( "OpenVPN import: try to copy pre shared key file %1 to %2." ).arg( X509CertFileSrc.name() ).arg( X509CertFileDst.name() ), config->debug ); +// +// +// if ( X509CertFileSrc.open( IO_ReadOnly ) ) { +// if ( X509CertFileDst.open( IO_WriteOnly ) ) { +// QString X509CertFileString = QString( X509CertFileSrc.readAll() ); +// X509CertDstStream << X509CertFileString; +// X509CertFileDst.close(); +// if ( config->KvpncDebugLevel > 2 ) +// config->appendLogEntry( i18n( "OpenVPN import: X509 cert file %1 copied to %2." ).arg( X509CertFileSrc.name() ).arg( X509CertFileDst.name() ), config->debug ); +// } else { +// if ( config->KvpncDebugLevel > 2 ) +// config->appendLogEntry( i18n( "OpenVPN import: X509 cert file %1 could not open for writing." ).arg( X509CertFileDst.name() ), config->debug ); +// +// // return; +// } +// X509CertFileDst.close(); +// } else { +// if ( config->KvpncDebugLevel > 2 ) +// config->appendLogEntry( i18n( "OpenVPN import: X509 cert file %1 could not open for reading." ).arg( X509CertFileSrc.name() ), config->debug ); +// +// // return; +// } +// } +// if ( !acc->getPreSharedKey().isEmpty() && !acc->getPreSharedKey().startsWith( CertPath ) ) { +// QString prefix = "./"; +// if ( !filename.find( '/' ) > -1 ) +// prefix = QString( Utils(this->GlobalConfig).removeSpecialCharsForFilename( filename).section( '/', 0, -2 ) + "/" ); +// +// QFile PreSharedKeyFileSrc ( QString( prefix + acc->getPreSharedKey() ) ); +// QFile PreSharedKeyFileDst ( QString( CertPath + "/openvpnimport_" + acc->getPreSharedKey() ) ); +// acc->setPreSharedKey( QString( CertPath + "/openvpnimport_" + acc->getPreSharedKey() ) ); +// +// QTextStream PreSharedKeyDstStream( &PreSharedKeyFileDst ); +// +// if ( config->KvpncDebugLevel > 1 ) +// config->appendLogEntry( i18n( "OpenVPN import: try to copy pre shared key file %1 to %2." ).arg( PreSharedKeyFileSrc.name() ).arg( PreSharedKeyFileDst.name() ), config->debug ); +// +// if ( PreSharedKeyFileSrc.open( IO_ReadOnly ) ) { +// if ( PreSharedKeyFileDst.open( IO_WriteOnly ) ) { +// QString PreSharedKeyFileString = QString( PreSharedKeyFileSrc.readAll() ); +// PreSharedKeyDstStream << PreSharedKeyFileString; +// PreSharedKeyFileDst.close(); +// if ( config->KvpncDebugLevel > 2 ) +// config->appendLogEntry( i18n( "OpenVPN import: pre shared key file %1 copied to %2." ).arg( PreSharedKeyFileSrc.name() ).arg( PreSharedKeyFileDst.name() ), config->debug ); +// } else { +// if ( config->KvpncDebugLevel > 2 ) +// config->appendLogEntry( i18n( "OpenVPN import: pre shared key file %1 could not open for writing." ).arg( PreSharedKeyFileDst.name() ), config->debug ); +// +// // return; +// } +// PreSharedKeyFileDst.close(); +// } else { +// if ( config->KvpncDebugLevel > 2 ) +// config->appendLogEntry( i18n( "OpenVPN import: pre shared key file %1 could not open for reading." ).arg( PreSharedKeyFileSrc.name() ), config->debug ); +// +// // return; +// } +// } + + OpenvpnConfigFile.close(); + importOk = true; + } + else + importOk = false; + + if ( !Pkcs12CertFile.isEmpty() ) + { + + QString filepath = filename.section ( '/', 0, -2 ); // should give the base path + + ImportCertificateDialog dlg ( this, i18n ( "Import Certificate..." ).ascii(), config ); + + QString p12file=""; + + if ( Pkcs12CertFile.find ( '/' ) < 0 ) + p12file = filepath + "/" + Pkcs12CertFile; + else + p12file = Pkcs12CertFile; + + dlg.main->ImporttypeComboBox->setCurrentItem ( ImportCertificateDialog::pkcs12_openvpn ); + dlg.typeToggeled ( ImportCertificateDialog::pkcs12_openvpn ); + dlg.main->ImporttypeComboBox->setEnabled ( false ); + // dlg.main->RacoonCertificatePathUrlrequester->setEnabled(true); + dlg.main->RacoonCertificatePathUrlrequester->setURL ( "/etc/openvpn" ); + dlg.main->PrivateKeyPassGroupBox->setEnabled ( true ); +// dlg.main->PrivateKeyPassGroupBox->setCurrentText(i18n("OpenVPN")); + dlg.main->PrivateKeyPasswordEdit->setEnabled ( true ); + dlg.main->PrivateKeyAgainPasswordEdit->setEnabled ( true ); + + dlg.main->FilenameUrlrequester->setURL ( p12file ); + dlg.main->ImportPasswordEdit->setEnabled ( true ); + dlg.main->P12GroupBox->setEnabled ( true ); + dlg.main->PrivateKeyPassGroupBox->setEnabled ( true ); + dlg.main->FilenameUrlrequester->setFilter ( "*.p12" ); + + dlg.main->ImportPasswordEdit->setFocus(); + + int result = dlg.exec(); + + if ( result == QDialog::Accepted ) + { + if ( dlg.importSuccess ) + { + config->appendLogEntry ( i18n ( "OpenVPN import: import of pkcs12 certificate file %1 was successful." ).arg ( Pkcs12CertFile ), config->info ); + importOk = true; + + acc->setX509Certificate ( dlg.main->RacoonCertificatePathUrlrequester->url() + "/mykeys_" + ( p12file.left ( p12file.length() - 4 ) ).section ( '/', -1, -1 ) + ".pem" ); + acc->setPrivateKey ( dlg.main->RacoonCertificatePathUrlrequester->url() + "/mykeys_" + ( p12file.left ( p12file.length() - 4 ) ).section ( '/', -1, -1 ) + ".pem" ); + acc->setCaCertificate ( dlg.main->RacoonCertificatePathUrlrequester->url() + "/ca_" + ( p12file.left ( p12file.length() - 4 ) ).section ( '/', -1, -1 ) + ".pem" ); + acc->setCertPath ( dlg.main->RacoonCertificatePathUrlrequester->url() ); + acc->setPrivateKeyPass ( dlg.main->ImportPasswordEdit->text() ); + + + } + else + { + config->appendLogEntry ( i18n ( "OpenVPN import: import of pkcs12 certificate file %1 failed!" ).arg ( Pkcs12CertFile ), config->error ); + importOk = false; + } + } + else + { + config->appendLogEntry ( i18n ( "OpenVPN import: import of pkcs12 certificate file was cancelled." ).arg ( Pkcs12CertFile ), config->info ); + importOk = false; + } + + } + + //std::cout << "accept" << std::endl; + QDialog::accept(); +} + diff --git a/src/importopenvpnprofiledialog.h b/src/importopenvpnprofiledialog.h new file mode 100644 index 0000000..59b736c --- /dev/null +++ b/src/importopenvpnprofiledialog.h @@ -0,0 +1,53 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef IMPORTOPENVPNPROFILEDIALOG_H +#define IMPORTOPENVPNPROFILEDIALOG_H + +#include +#include "importopenvpnprofiledialogbase.h" +#include "vpnaccountdata.h" +#include "kvpncconfig.h" + +/** +@author Christoph Thielecke +*/ +class ImportOpenvpnProfileDialog : public KDialogBase +{ +Q_OBJECT +public: + ImportOpenvpnProfileDialog( KVpncConfig *config, QWidget *parent, const QString& caption, QString file); + ~ImportOpenvpnProfileDialog(); + + void canAccept(); + QString filename; + bool importOk; + VpnAccountData *acc; + ImportOpenvpnProfileDialogBase *main; + +public slots: + void accept(); + +private: + KVpncConfig* config; + QString Pkcs12CertFile; + QString CertPath; +}; + +#endif diff --git a/src/importopenvpnprofiledialogbase.ui b/src/importopenvpnprofiledialogbase.ui new file mode 100644 index 0000000..7a59be9 --- /dev/null +++ b/src/importopenvpnprofiledialogbase.ui @@ -0,0 +1,122 @@ + +ImportOpenvpnProfileDialogBase +Christoph Thielecke + + + ImportOpenvpnProfileDialogBase + + + + 0 + 0 + 506 + 143 + + + + + 400 + 0 + + + + Import OpenVPN profile + + + + unnamed + + + + layout52 + + + + unnamed + + + + layout51 + + + + unnamed + + + + spacer35 + + + Horizontal + + + Expanding + + + + 241 + 21 + + + + + + OpenProfileManagerCheckBox + + + open &profile manager after import + + + Alt+P + + + + + + + layout204 + + + + unnamed + + + + textLabel1 + + + File name: + + + + + FilenameUrlrequester + + + File name of the OpenVPN config (*.ovpn, *.conf) + + + + + + + TextLabel + + + <b>Please choose the OpenVPN config file:</b> + + + + + + + + canAccept() + + + + kurlrequester.h + klineedit.h + kpushbutton.h + + diff --git a/src/importprofiledialog.cpp b/src/importprofiledialog.cpp new file mode 100644 index 0000000..80ec8a0 --- /dev/null +++ b/src/importprofiledialog.cpp @@ -0,0 +1,601 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +//BEGIN INCLUDES +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "importprofiledialog.h" +#include "importcertificatedialog.h" +#include "utils.h" +#include "ciscopasswddecoder.h" +//END INCLUDES + +ImportProfileDialog::ImportProfileDialog(KVpncConfig *GlobalConfig, QWidget *parent, const QString& caption, QString file) + : KDialogBase( parent, "Import_Cisco_PCF_profile", true, caption, + KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, true ) +{ + decodeEncPasswd = false; + if (!file.isEmpty()) + filename = file; + else + filename = ""; + importOk = false; + this->GlobalConfig= GlobalConfig; + + main = new ImportProfileDialogBase(this); + setMainWidget(main); + main->setMinimumSize(main->sizeHint()); + + main->FilenameUrlrequester->setFilter( "*.pcf" ); + main->FilenameUrlrequester->setURL(filename); + +} + + +ImportProfileDialog::~ImportProfileDialog() +{ + delete main; +} + +void ImportProfileDialog::accept() +{ + + //filename="/etc/CiscoSystemsVPNClient/Profiles/hs_harz.pcf"; + filename = main->FilenameUrlrequester->url(); + if ( !filename.isEmpty() ) + { + f = new QFile(filename); + canAccept(); + } + + else + { + KMessageBox::sorry( 0, i18n( "File name can not be empty!" ), i18n( "Empty File Name" ) ); + } +} + + +void ImportProfileDialog::canAccept() +{ + + if ( !f->exists() ) + { + KMessageBox::information( 0, i18n( "File not found." ), i18n( "No File" ) ); + + // emit progress( 100 ); + return ; + } + + KConfig config( filename, true, false ); + + QStringList grouplist = config.groupList(); + + if (GlobalConfig->KvpncDebugLevel > 0) + { + QString groups=""; + for ( QStringList::Iterator group = grouplist.begin(); group != grouplist.end(); ++group ) + groups += QString(" "+*group); + GlobalConfig->appendLogEntry(i18n("PCF import: groups found: [ %1 ]").arg(groups), GlobalConfig->debug); + } + + config.setGroup( "main" ); + + // sample config + + /* + [main] + Description= + Host = 192.168.13.1 + AuthType=1 + GroupName = hs_harz + GroupPwd = + Username = u15119 + SaveUserPassword = 0 + UserPassword = + NTDomain = + EnableBackup = 0 + BackupServer = + EnableMSLogon = 1 + TunnelingMode = 0 + TcpTunnelingPort = 10000 + CertStore = 0 + CertName = + CertPath = + CertSubjectName = + CertSerialHash = 00000000000000000000000000000000 + SendCertChain = 0 + VerifyCertDN = + DHGroup = 2 + ForceKeepAlives = 0 + PeerTimeout = 90 + EnableLocalLAN = 1 // only reading because we dont want to do this + EnableSplitDNS = 1 + EnableNAT = 1 + */ + + + VpnAccountData::ConnectionType ConnType = VpnAccountData::cisco; + QString ProfileName = QFileInfo ( f->name().stripWhiteSpace().remove(".pcf").remove(".PCF") ).fileName(); + acc = new VpnAccountData ( ConnType, Utils(this->GlobalConfig).removeSpecialCharsForFilename( ProfileName )); + + QString Description = config.readEntry( "Description", "" ); + + if (Description.isEmpty()) + Description = config.readEntry("!Description",i18n("Profile imported from file %1.").arg(filename)); + + if (!Description.isEmpty()) + { + if (GlobalConfig->KvpncDebugLevel > 0) + GlobalConfig->appendLogEntry(i18n("PCF import: description found: %1").arg(Description), GlobalConfig->debug); + acc->setDescription( Description ); + } + + + QString Gateway = config.readEntry( "Host", "" ); + + if (Gateway.isEmpty()) + Gateway = config.readEntry( "!Host", "" ); + + if (!Gateway.isEmpty()) + { + if (GlobalConfig->KvpncDebugLevel > 0) + GlobalConfig->appendLogEntry(i18n("PCF import: gateway found: %1").arg(Gateway), GlobalConfig->debug); + acc->setGateway( Gateway ); + } + + bool useApplicationVersion = false; + acc->setUseApplicationVersion( useApplicationVersion ); + + bool enableBackup = config.readBoolEntry( "EnableBackup" , FALSE ); + QString BackupServer = config.readEntry( "BackupServer", "" ); + + QString GroupName = config.readEntry( "GroupName" , "" ); + + if (GroupName.isEmpty()) + GroupName = config.readEntry( "!GroupName", "" ); + + if (GroupName.isEmpty()) + GroupName = "importedProfile"; + + if (!GroupName.isEmpty()) + { + if (GlobalConfig->KvpncDebugLevel > 0) + GlobalConfig->appendLogEntry(i18n("PCF import: group name found: %1").arg(GroupName), GlobalConfig->debug); + acc->setID( GroupName ); + } + + QString NtDomain = config.readEntry( "NTDomain" ); + if (NtDomain.isEmpty()) + NtDomain = config.readEntry( "!NTDomain", "" ); + + if (!NtDomain.isEmpty()) + { + if (GlobalConfig->KvpncDebugLevel > 0) + GlobalConfig->appendLogEntry(i18n("PCF import: NT domain found: %1").arg(NtDomain), GlobalConfig->debug); + acc->setNtDomainName( NtDomain ); + } + + bool enableMSLogon = config.readBoolEntry( "EnableMSLogon", FALSE ); + bool useNtDomainName = false; + + if ( enableMSLogon && !NtDomain.isEmpty() ) + useNtDomainName = true; + + QString CertName = config.readEntry( "CertName", "" ); + + if (GlobalConfig->KvpncDebugLevel > 0) + GlobalConfig->appendLogEntry(i18n("PCF import: certificate name found: %1").arg(CertName), GlobalConfig->debug); + + QString CertPath = config.readEntry( "CertPath", "" ); + QString CertSubjectName = config.readEntry( "CertSubjectName", "" ); + QString CertSerialHash = config.readEntry( "CertSerialHash", "" ); + // bool SendCertChain = config.readBoolEntry( "SendCertChain" , "" ); + // bool VerifyCertDN = config.readBoolEntry( "VerifyCertDN", FALSE ); + + /* + 0 = default, none + 1 = Cisco + */ + bool useCertStore=false; + int CertStore = config.readNumEntry( "CertStore", -1 ); + if (CertStore == 1) + useCertStore = true; + if (GlobalConfig->KvpncDebugLevel > 0) + GlobalConfig->appendLogEntry(i18n("PCF import: certificate should be stored into cisco cert store: %1").arg(QString().setNum(int(useCertStore))), GlobalConfig->debug); + + if (useCertStore) + { + // we have to import into the store + if (!CertName.isEmpty()) + { + bool CertPathFound = false; + QString CertFullPath = CertName; + if (!QFile(CertFullPath).exists()) + { + CertFullPath = CertPath+"/"+CertName; + if (!QFile(CertFullPath).exists()) + { + GlobalConfig->appendLogEntry(i18n("Cisco certificate import: cert not found, skipping."), GlobalConfig->error); + } + else + { + if (GlobalConfig->KvpncDebugLevel > 0) + GlobalConfig->appendLogEntry(i18n("Cisco certificate import: cert found at current path."), GlobalConfig->debug); + CertPathFound = true; + } + } + else + { + if (GlobalConfig->KvpncDebugLevel > 0) + GlobalConfig->appendLogEntry(i18n("Cisco certificate import: cert found at cert path."), GlobalConfig->debug); + CertPathFound = true; + + } + if (CertPathFound) + { + QStringList OldCiscoCerts = Utils(GlobalConfig).getCertsFromCiscoCertStore(); + ImportCertificateDialog dlg( this, i18n( "Import certificate..." ).ascii(), GlobalConfig ); + dlg.main->FilenameUrlrequester->setURL(CertFullPath); + dlg.main->ImporttypeComboBox->setCurrentItem(dlg.ciscouserca); // import user and ca cert + int result = dlg.exec(); + if (result == QDialog::Accepted) + { + acc->setUseCiscoCertStore(true); + QStringList CiscoCerts = Utils(GlobalConfig).getCertsFromCiscoCertStore(); + for ( QStringList::Iterator ciscoit = CiscoCerts.begin(); ciscoit != CiscoCerts.end(); ++ciscoit ) + { + if (OldCiscoCerts.findIndex(QString(*ciscoit)) < 1 ) + { + // if it was not in list, then its the new added one. + acc->setX509Certificate(*ciscoit); + break; + } + } + } + } + } + } + { + acc->setX509Certificate(CertName); + acc->setCertPath(CertPath); + } + + + int TcpTunnelingPort = config.readNumEntry( "TcpTunnelingPort", 10000 ); //std::cout << "tunneling port: " << TunnelingPort << std::endl; + /* + 0, the default, specifies IPSec over UDP for NAT transparency + 1 specifies IPSec over TCP for NAT transparency + */ + bool useUdp = config.readBoolEntry( "TunnelingMode", 0 ); + acc->setUseUdp( useUdp ); + + int LocalPort=10000; + bool useLocalPort = false; + if (TcpTunnelingPort != 10000) + useLocalPort = true; + + if (useLocalPort && useUdp == false) + { + acc->setLocalPort(LocalPort); + acc->setUseLocalPort(true); + } + + + // bool ForceKeepAlives = config.readBoolEntry( "ForceKeepAlives", FALSE ); + + // bool EnableLocalLAN = config.readBoolEntry( "EnableLocalLAN", FALSE ); // nur auslesen aber immer aus :) + // bool EnableSplitDNS = config.readBoolEntry( "EnableSplitDNS", FALSE ); + + + if (useUdp == false) + { + // vpnc does not support TCP :( + acc->setConnectionType(VpnAccountData::cisco); + } + if (useUdp) + { + if (GlobalConfig->KvpncDebugLevel > 0) + GlobalConfig->appendLogEntry(i18n("PCF import: using %1 for tunneling").arg("UDP"), GlobalConfig->debug); + acc->setUseUdp( true); + } + else + { + if (GlobalConfig->KvpncDebugLevel > 0) + GlobalConfig->appendLogEntry(i18n("PCF import: using %1 for tunneling").arg("TCP"), GlobalConfig->debug); + acc->setUseUdp( false); + } + /* + 0, the default, disables IPSec through NAT mode + 1 enables IPSec through NAT mode + */ + bool enableNAT = config.readNumEntry("EnableNat", false); + if (enableNAT) + { + if (GlobalConfig->KvpncDebugLevel > 0) + GlobalConfig->appendLogEntry(i18n("PCF import: enable NAT mode: %1").arg(i18n("yes")), GlobalConfig->debug); + acc->setUseNat(true); + } + else + { + if (GlobalConfig->KvpncDebugLevel > 0) + GlobalConfig->appendLogEntry(i18n("PCF import: enable NAT mode: %1").arg(i18n("no")), GlobalConfig->debug); + acc->setUseNat(false); + } + + bool useUdpPort= true; + + +// if ( TunnelingPort != 10000 ) +// { +// useUdp=true; //FIXME: is this right? I guess its only on udp +// useUdpPort = true; +// } + + QString PerfectForwardSecrecy = ""; //QString("dh"+QString().setNum(DHGroup)); + // bool usePerfectForwardSecrety = false; + bool usePerfectSecrecy = false; + acc->setPerfectForwardSecrety( PerfectForwardSecrecy ); + acc->setUsePerfectForwardSecrety( usePerfectSecrecy ); + bool useIkeGroup = false; + QString IkeGroup; + int DHGroup = config.readNumEntry( "DHGroup", -1 ); + if (DHGroup != -1 ) + { + if (GlobalConfig->KvpncDebugLevel > 0) + GlobalConfig->appendLogEntry(i18n("PCF import: Diffie Hellman group found: %1").arg(QString().setNum(DHGroup)), GlobalConfig->debug); + IkeGroup = "dh" + QString().setNum( DHGroup ) ; + useIkeGroup = true; + acc->setIkeGroup( IkeGroup ); + } + + int PeerTimeout = config.readNumEntry( "PeerTimeout", -1 ); + if (PeerTimeout > -1 ) + { + if (GlobalConfig->KvpncDebugLevel > 0) + GlobalConfig->appendLogEntry(i18n("PCF import: peer timeout found: %1").arg(QString().setNum(PeerTimeout)), GlobalConfig->debug); + // read minutes but store seconds + acc->setPeerTimeout( PeerTimeout*60 ); + } + + QString Username = config.readEntry( "Username" , "" ); + if (!Username.isEmpty()) + { + if (GlobalConfig->KvpncDebugLevel > 0) + GlobalConfig->appendLogEntry(i18n("PCF import: user name found: %1").arg(Username), GlobalConfig->debug); + acc->setUserName( Username ); + } + + QString UserPassword = config.readEntry( "UserPassword", "" ); + if (UserPassword.isEmpty()) + UserPassword = config.readEntry( "!UserPassword", "" ); + + if (!UserPassword.isEmpty()) + { + if (GlobalConfig->KvpncDebugLevel > 0) + GlobalConfig->appendLogEntry(i18n("PCF import: clear text user password found: %1").arg(UserPassword), GlobalConfig->debug); + acc->setUserPassword( UserPassword ); + } + + QString enc_UserPassword = config.readEntry( "enc_UserPassword", "" ); + if (enc_UserPassword.isEmpty()) + enc_UserPassword = config.readEntry( "!enc_UserPassword", "" ); + + if (!enc_UserPassword.isEmpty()) + { + if (GlobalConfig->KvpncDebugLevel > 0) + GlobalConfig->appendLogEntry(i18n("PCF import: encrypted user password found: %1").arg(enc_UserPassword), GlobalConfig->debug); + } + + CiscoPasswdDecoder dec (filename); + QString userpasswd=""; + QString grouppasswd=""; + dec.decodePasswords(userpasswd,grouppasswd); + + // std::cout << "decoded userpasswd: " << userpasswd << std::endl; + // std::cout << "decoded grouppasswd: " << grouppasswd << std::endl; + + bool saveUserPassword = config.readBoolEntry( "SaveUserPassword", FALSE ); + + if (saveUserPassword == false) + config.readBoolEntry( "!SaveUserPassword", FALSE ); + + if ( UserPassword.isEmpty() && userpasswd.isEmpty() ) + saveUserPassword = false; + + if (!userpasswd.isEmpty()) + { + if (GlobalConfig->KvpncDebugLevel > 3) + GlobalConfig->appendLogEntry(i18n("PCF import: decrypted user password found: %1").arg(userpasswd), GlobalConfig->debug); + acc->setUserPassword( userpasswd ); + } + + if (GlobalConfig->KvpncDebugLevel > 0) + if (saveUserPassword) + GlobalConfig->appendLogEntry(i18n("PCF import: save user pass : %1").arg(i18n("yes")), GlobalConfig->debug); + else + GlobalConfig->appendLogEntry(i18n("PCF import: save user pass : %1").arg(i18n("no")), GlobalConfig->debug); + acc->setSaveUserPassword( saveUserPassword ); + + bool saveGroupPwd = true; + QString GroupPwd = config.readEntry( "GroupPwd" , "" ); + if (GroupPwd.isEmpty()) + GroupPwd = config.readEntry( "!GroupPwd", "" ); + + if (!GroupPwd.isEmpty()) + { + if (GlobalConfig->KvpncDebugLevel > 3) + GlobalConfig->appendLogEntry(i18n("PCF import: clear text group password found: %1").arg(GroupPwd), GlobalConfig->debug); + acc->setPreSharedKey( GroupPwd ); + } + + QString enc_GroupPwd = config.readEntry( "enc_GroupPwd", "" ); + + if (enc_GroupPwd.isEmpty()) + enc_GroupPwd = config.readEntry( "!enc_GroupPwd", "" ); + + if (!grouppasswd.isEmpty()) + { + if (GlobalConfig->KvpncDebugLevel > 3) + GlobalConfig->appendLogEntry(i18n("PCF import: decrypted group password found: %1").arg(grouppasswd), GlobalConfig->debug); + acc->setPreSharedKey( grouppasswd ); + } + + if ( GroupPwd.isEmpty() && grouppasswd.isEmpty()) + saveGroupPwd = false; + acc->setSavePsk( saveGroupPwd ); + + if ( Description.isEmpty() ) + { + Description = ( QUrl( filename ).fileName() ); + Description = Utils(this->GlobalConfig).removeSpecialCharsForFilename( Description.left( filename.section('/',-1).length() - 4 )); + } + + if ( GroupName.isEmpty() ) + { + GroupName = Utils(this->GlobalConfig).removeSpecialCharsForFilename( GroupName.left( filename.section('/',-1).length() - 4 )); + } + + /* + AuthType= + The authentication type of the user: + 1 = Pre-shared keys (default) + 3 = Digital Certificate using an RSA signature. + 5 = Mutual authentication (hybrid) + */ + int AuthType = config.readNumEntry( "AuthType" , -1 ); + + if (AuthType==-1) + AuthType = config.readNumEntry( "!AuthType", -1 ); + + if (GlobalConfig->KvpncDebugLevel > 0) + if (AuthType ==1) + GlobalConfig->appendLogEntry(i18n("PCF import: authentication type found: %1").arg(i18n("PSK")), GlobalConfig->debug); + else if (AuthType ==3) + GlobalConfig->appendLogEntry(i18n("PCF import: authentication type found: %1").arg(i18n("certificate")), GlobalConfig->debug); + else if (AuthType ==5) + GlobalConfig->appendLogEntry(i18n("PCF import: authentication type found: %1").arg(i18n("hybrid")), GlobalConfig->debug); + else + GlobalConfig->appendLogEntry(i18n("PCF import: no authentication type found, assuming %1").arg(i18n("PSK")), GlobalConfig->debug); + + if (AuthType == 3 || AuthType == 5) + { + // vpnc has no cert support :( + acc->setConnectionType (VpnAccountData::ciscoorig); + acc->setAuthType( VpnAccountData::cert); + + if (!CertName.isEmpty()) + acc->setX509Certificate(CertName); + } + else if (AuthType == 1 ) + acc->setAuthType( VpnAccountData::psk); + else + acc->setAuthType( VpnAccountData::psk); + + bool useGlobalIpsecSecret = false; + acc->setUseGlobalIpsecSecret( useGlobalIpsecSecret ); + + bool useSingleDes = false; + acc->setUseSingleDes( useSingleDes ); + + //acc->setUseAdvancedSettings( useAdvancedSettings ); + acc->setUseAdvancedSettings( true ); + + /* + std::cout << Description + std::cout << Gateway + std::cout << AuthType + std::cout << GroupName + std::cout << GroupPwd + std::cout << enc_GroupPwd + std::cout << Username + std::cout << saveUserPassword + std::cout << UserPassword + std::cout << NtDomain + std::cout << bool enableBackup + std::cout << BackupServer + std::cout << bool enableMSLogon + std::cout << TunnelingMode + std::cout << TunnelingPort + std::cout << CertStore + std::cout << CertName + std::cout << CertPath + std::cout << CertSubjectName + std::cout << CertSerialHash + std::cout << SendCertChain + std::cout << VerifyCertDN + std::cout << DHGroup + std::cout << ForceKeepAlives + std::cout << PeerTimeout + std::cout << EnableLocalLAN + std::cout << EnableSplitDNS + std::cout << saveGroupPwd + std::cout << usePerfectSecrecy + std::cout << useSingleDes + std::cout << useLocalPort + std::cout << useNtDomainName + std::cout << useLocalPort + std::cout << IkeGroup + std::cout << PerfectForwardSecrecy + std::cout << useAdvancedSettings + */ + /* + acc.setName( Description ); + acc.setGateway( Gateway ); + acc.setID( GroupName ); + acc.setGroupPassword( GroupPwd ); + acc.setUserName( Username ); + acc.setUserPassword( UserPassword ); + acc.setSaveUserPassword( saveUserPassword ); + acc.setSaveGroupPassword( true ); + //acc.setIkeGroup( QString IkeGroup ); + acc.setPerfectForwardSecrety( QString PerfectForwardSecrecy ); + acc.setNtDomainName( QString Name ); + acc.setApplicationVersion( QString version ); + acc.setUseSingleDes( bool useSingleDes ); + acc.setLocalPort( int port ); + acc.setUseIkeGroup( bool useIkeGroup); + acc.setUsePerfectForwardSecrety(bool usePerfectForwardSecrety); + acc.setUseNtDomainName(bool useNtDomainName); + acc.setUseApplicationVersion(bool useApplicationVersion); + acc.setUseLocalPort(bool useLocalPort); + acc.setUseAdvancedSettings(bool useAdvancedSettings); + acc.setUseGlobalIpsecSecret(bool useGlobalIpsecSecret); + */ + importOk = true; + //std::cout << "accept" << std::endl; + QDialog::accept(); +} + diff --git a/src/importprofiledialog.h b/src/importprofiledialog.h new file mode 100644 index 0000000..7215b2a --- /dev/null +++ b/src/importprofiledialog.h @@ -0,0 +1,54 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef IMPORTPROFILEDIALOG_H +#define IMPORTPROFILEDIALOG_H + +#include +#include "importprofiledialogbase.h" +#include "vpnaccountdata.h" +#include "kvpncconfig.h" + +/** +@author Christoph Thielecke +*/ +class ImportProfileDialog : public KDialogBase +{ +Q_OBJECT +public: + ImportProfileDialog( KVpncConfig *config, QWidget *parent, const QString& caption, QString file); + ~ImportProfileDialog(); + + void canAccept(); + bool decodeEncPasswd; + QString filename; + bool importOk; + VpnAccountData *acc; + ImportProfileDialogBase *main; + QFile *f; + +public slots: + void accept(); + +private: + KVpncConfig* GlobalConfig; + +}; + +#endif diff --git a/src/importprofiledialogbase.ui b/src/importprofiledialogbase.ui new file mode 100644 index 0000000..95535ae --- /dev/null +++ b/src/importprofiledialogbase.ui @@ -0,0 +1,126 @@ + +ImportProfileDialogBase +Christoph Thielecke + + + ImportProfileDialogBase + + + + 0 + 0 + 506 + 137 + + + + Import Profile + + + + unnamed + + + + layout7 + + + + unnamed + + + + layout203 + + + + unnamed + + + + textLabel1_2 + + + <b>Please choose the PCF file:</b> + + + + + layout202 + + + + unnamed + + + + textLabel1 + + + File name: + + + + + FilenameUrlrequester + + + File name of the Cisco profile (*.PCF) + + + + + + + + + layout6 + + + + unnamed + + + + spacer35 + + + Horizontal + + + Expanding + + + + 258 + 21 + + + + + + OpenProfileManagerCheckBox + + + open &profile manager after import + + + Alt+P + + + + + + + + + + canAccept() + + + + kurlrequester.h + klineedit.h + kpushbutton.h + + diff --git a/src/kfeedback.cpp b/src/kfeedback.cpp new file mode 100644 index 0000000..e1eefac --- /dev/null +++ b/src/kfeedback.cpp @@ -0,0 +1,504 @@ + +/* + * File name: kfeedback.cpp + * Summary: User feedback form + * License: LGPL - See file COPYING.LIB for details. + * Author: Stefan Hundhammer + * + * Updated: 2004-11-23 + */ + + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "kfeedback.h" + + +KFeedbackDialog::KFeedbackDialog( const QString & feedbackMailAddress, + const QString & helpTopic ) + : KDialogBase( Plain, // dialogFace + i18n( "Feedback" ), // caption + Apply | Cancel + | ( helpTopic.isEmpty() ? 0 : (int) Help ), // buttonMask + Apply ) // defaultButton +{ + QVBoxLayout * layout = new QVBoxLayout( plainPage(), 0, spacingHint() ); + setButtonApply( KGuiItem( i18n( "&Mail this..." ) ) ); + + if ( ! helpTopic.isEmpty() ) + setHelp( helpTopic ); + + _form = new KFeedbackForm( feedbackMailAddress, plainPage() ); + Q_CHECK_PTR( _form ); + + layout->addWidget( _form ); + checkSendButton(); + + connect( this, SIGNAL( applyClicked() ), + _form, SLOT ( sendMail() ) ); + + connect( _form, SIGNAL( mailSent() ), + this, SLOT ( hide() ) ); + + connect( _form, SIGNAL( mailSent() ), + this, SIGNAL( mailSent() ) ); + + connect( _form, SIGNAL( checkComplete() ), + this, SLOT ( checkSendButton() ) ); +} + + +KFeedbackDialog::~KFeedbackDialog() +{ + // NOP +} + + +void +KFeedbackDialog::checkSendButton() +{ + enableButtonApply( _form->readyToSend() ); +} + + + + + +KFeedbackForm::KFeedbackForm( const QString & feedbackMailAddress, + QWidget * parent ) + : QVBox( parent ) + , _feedbackMailAddress( feedbackMailAddress ) +{ + // + // Explanation above the question list + // + + QLabel * label = new QLabel( i18n( "

Please tell us your opinion about this program.

" + "

You will be able to review everything in your mailer " + "before any mail is sent.
" + "Nothing will be sent behind your back.

" + ), this ); + // + // Question list + // + + _questionList = new KFeedbackQuestionList( this ); + Q_CHECK_PTR( _questionList ); + + connect( _questionList, SIGNAL( checkComplete() ), + this, SLOT ( slotCheckComplete() ) ); + + + // + // Explanation below the question list + // + + QHBox * hbox = new QHBox( this ); + Q_CHECK_PTR( hbox ); + + QSizePolicy pol( QSizePolicy::Fixed, QSizePolicy::Fixed ); // hor / vert + + label = new QLabel( i18n( "Questions marked with " ), hbox ); + Q_CHECK_PTR( label ); + label->setSizePolicy( pol ); + + label = new QLabel( hbox ); + Q_CHECK_PTR( label ); + label->setPixmap( KGlobal::iconLoader()->loadIcon( "edit", KIcon::Small ) ); + label->setSizePolicy( pol ); + + label = new QLabel( i18n( " must be answered before a mail can be sent.") , hbox ); + Q_CHECK_PTR( label ); + label->setSizePolicy( pol ); + + new QWidget( hbox ); // Fill any leftover space to the right. + + + // + // Free-text comment field + // + + label = new QLabel( "\n" + i18n( "&Additional Comments:" ), this ); Q_CHECK_PTR( label ); + _comment = new QMultiLineEdit( this ); Q_CHECK_PTR( _comment ); + + label->setBuddy( _comment ); +#if (QT_VERSION < 300) + _comment->setFixedVisibleLines( 5 ); +#endif + _comment->setWordWrap( QMultiLineEdit::FixedColumnWidth ); + _comment->setWrapColumnOrWidth( 70 ); +} + + +KFeedbackForm::~KFeedbackForm() +{ + // NOP +} + + +void +KFeedbackForm::sendMail() +{ + // + // Build mail subject + // + + QString subject; + + const KAboutData * aboutData = KGlobal::instance()->aboutData(); + + if ( aboutData ) + subject = aboutData->programName() + "-" + aboutData->version(); + else + subject = kapp->name(); + + subject = "[kde-feedback] " + subject + " user feedback"; + + + // + // Build mail body + // + + QString body = subject + "\n\n" + + formatComment() + + _questionList->result(); + + + // + // Build "mailto:" URL from all this + // + + KURL mail; + mail.setProtocol( "mailto" ); + mail.setPath( _feedbackMailAddress ); + mail.setQuery( "?subject=" + KURL::encode_string( subject ) + + "&body=" + KURL::encode_string( body ) ); + + // TODO: Check for maximum command line length. + // + // The hard part with this is how to get this from all that 'autoconf' + // stuff into 'config.h' or some other include file without hardcoding + // anything - this is too system dependent. + + + // + // Actually send mail + // + + kapp->invokeMailer( mail ); + + emit mailSent(); +} + + +void +KFeedbackForm::slotCheckComplete() +{ + emit checkComplete(); +} + + +QString +KFeedbackForm::formatComment() +{ + QString result = _comment->text(); + + if ( ! result.isEmpty() ) + { + result = "\n" + result + "\n\n\n"; + } + + return result; +} + + +bool +KFeedbackForm::readyToSend() +{ + return _questionList->isComplete(); +} + + + + + + +KFeedbackQuestionList::KFeedbackQuestionList( QWidget *parent ) + : QListView( parent ) +{ + addColumn( "" ); + header()->hide(); +} + + +KFeedbackQuestionList::~KFeedbackQuestionList() +{ + // NOP +} + + +bool +KFeedbackQuestionList::isComplete() +{ + KFeedbackQuestion * question = firstQuestion(); + + while ( question ) + { + if ( question->isRequired() && ! question->isAnswered() ) + return false; + + question = question->nextQuestion(); + } + + return true; +} + + +QString +KFeedbackQuestionList::result() +{ + QString res; + KFeedbackQuestion * question = firstQuestion(); + + while ( question ) + { + res += question->result(); + + question = question->nextQuestion(); + } + + return res; +} + + +KFeedbackQuestion * +KFeedbackQuestionList::addQuestion( const QString & text, + const QString & id, + bool exclusiveAnswer, + bool required ) +{ + KFeedbackQuestion * question = new KFeedbackQuestion( this, text, id, + exclusiveAnswer, + required ); + Q_CHECK_PTR( question ); + + return question; +} + + +void +KFeedbackQuestionList::addYesNoQuestion( const QString & text, + const QString & id, + bool required ) +{ + + KFeedbackQuestion * question = new KFeedbackQuestion( this, text, id, + true, // exclusive + required ); + Q_CHECK_PTR( question ); + question->addAnswer( i18n( "yes" ), "yes" ); + question->addAnswer( i18n( "no" ), "no" ); +} + + +void +KFeedbackQuestionList::questionAnswered() +{ + emit checkComplete(); +} + +void +KFeedbackQuestionList::questionAdded( KFeedbackQuestion * question) +{ + if ( question->isRequired() ) + emit checkComplete(); +} + + + + + +static int nextNo = 0; + +KFeedbackQuestion::KFeedbackQuestion( KFeedbackQuestionList * parent, + const QString & text, + const QString & id, + bool exclusiveAnswer, + bool required, + bool open ) + : QCheckListItem( parent, text ) + , _id( id ) + , _exclusiveAnswer( exclusiveAnswer ) + , _required( required ) +{ + if ( required ) + { + setPixmap( 0, KGlobal::iconLoader()->loadIcon( "edit", KIcon::Small ) ); + } + + setOpen( open ); + _no = nextNo++; + + parent->questionAdded( this ); +} + + +void +KFeedbackQuestion::addAnswer( const QString & text, + const QString & id ) +{ + new KFeedbackAnswer( this, text, id, _exclusiveAnswer ); +} + + +bool +KFeedbackQuestion::isAnswered() +{ + if ( ! _exclusiveAnswer ) + { + /** + * If any number of answers is permitted for this question, this + * question is always considered to be answered. + **/ + + return true; + } + + + /** + * If this question requires an exclusive answer, exactly one of them + * should be checked. We don't need to bother about more than one being + * checked here - QListView does that for us. + **/ + + KFeedbackAnswer *answer = firstAnswer(); + + while ( answer ) + { + if ( answer->isChecked() ) + return true; + + answer = answer->nextAnswer(); + } + + return false; +} + + +QString +KFeedbackQuestion::result() +{ + QString res; + int answers = 0; + + KFeedbackAnswer *answer = firstAnswer(); + + while ( answer ) + { + if ( answer->isChecked() ) + { + res += _id + "=\"" + answer->id() + "\"\n"; + answers++; + } + + answer = answer->nextAnswer(); + } + + if ( answers > 1 ) + { + res = "\n" + res + "\n"; + } + + return res; +} + + +QString +KFeedbackQuestion::text() +{ + return QCheckListItem::text(0); +} + + +QString +KFeedbackQuestion::key( int, bool ) const +{ + QString no; + no.sprintf( "%08d", _no ); + + return no; +} + + +KFeedbackQuestionList * +KFeedbackQuestion::questionList() const +{ + return dynamic_cast( listView() ); +} + + + + + + + +KFeedbackAnswer::KFeedbackAnswer( KFeedbackQuestion * parent, + const QString & text, + const QString & id, + bool exclusive ) + : QCheckListItem( parent, + text, + exclusive + ? QCheckListItem::RadioButton + : QCheckListItem::CheckBox ) + , _id( id ) +{ + _no = nextNo++; +} + + +QString +KFeedbackAnswer::text() +{ + return QCheckListItem::text(0); +} + + +QString +KFeedbackAnswer::key( int, bool ) const +{ + QString no; + no.sprintf( "%08d", _no ); + + return no; +} + + +void +KFeedbackAnswer::stateChange( bool newState ) +{ + if ( newState && question()->isRequired() ) + { + KFeedbackQuestionList * list = question()->questionList(); + + if ( list ) + list->questionAnswered(); + } +} + + + +// EOF diff --git a/src/kfeedback.h b/src/kfeedback.h new file mode 100644 index 0000000..6ba6abd --- /dev/null +++ b/src/kfeedback.h @@ -0,0 +1,450 @@ +/* + * File name: kfeedback.h + * Summary: User feedback form and mailing utilities + * License: LGPL - See file COPYING.LIB for details. + * Author: Stefan Hundhammer + * + * Updated: 2003-01-07 + */ + + +#ifndef KFeedback_h +#define KFeedback_h + +#include +#include +#include + +class KFeedbackForm; +class KFeedbackQuestionList; +class KFeedbackQuestion; +class KFeedbackAnswer; +class QMultiLineEdit; + + +/** + * Dialog containing a @ref KFeedbackForm and all the infrastructure for + * sending a mail etc. + **/ +class KFeedbackDialog: public KDialogBase +{ + Q_OBJECT + +public: + + /** + * Constructor. + **/ + KFeedbackDialog( const QString & feedbackMailAddress, + const QString & helpTopic = QString::null ); + + + /** + * Destructor. + **/ + virtual ~KFeedbackDialog(); + + + /** + * Returns the internal @KFeedbackForm + **/ + KFeedbackForm *form() { return _form; } + + +public slots: + + /** + * Check if sufficient information is available to send a mail now and + * enable / disable the "send mail" button accordingly. + **/ + void checkSendButton(); + + +signals: + /** + * Emitted when the user has sent the feedback mail - i.e. when he clicked + * on the "Send mail" button and the mail has successfully been forwarded + * to the mailer. He can still choose not to send the mail from within the + * mailer, though. + **/ + void mailSent(); + + +protected: + + KFeedbackForm * _form; +}; + + +/** + * User feedback form: + * + * User is asked a list of questions, the answers of which will be sent via + * mail back to a feedback mail address. + **/ +class KFeedbackForm: public QVBox +{ + Q_OBJECT + +public: + /** + * Constructor. + **/ + KFeedbackForm( const QString & feedbackMailAddress, + QWidget * parent ); + + /** + * Destructor. + **/ + virtual ~KFeedbackForm(); + + +public slots: + + /** + * Compose a mail from the user's answers and send it to the feedback mail + * address passed to the constructor. + * + * This method will check with @ref readyToSend() if the mail can be sent + * with the questions answered until now and prompt the user to answer more + * questions if not. + * + * Connect the @ref mailSent() signal if you are interested when exactly + * all this was successful. + **/ + virtual void sendMail(); + + +public: + + /** + * Checks if the mail is ready to send, i.e. if all required fields are + * filled. + **/ + virtual bool readyToSend(); + + /** + * Returns the @ref KFeedbackQuestionList . + **/ + KFeedbackQuestionList * questionList() { return _questionList; } + + +signals: + /** + * Emitted when the user has sent the feedback mail - i.e. when he clicked + * on the "Send mail" button and the mail has successfully been forwarded + * to the mailer. He can still choose not to send the mail from within the + * mailer, though. + **/ + void mailSent(); + + /** + * Emitted when it is time to check for completeness of all information in + * this form: Either when a new question is added or when a question is + * answered. + **/ + void checkComplete(); + + +protected slots: + /** + * Check for completeness of this form. + **/ + void slotCheckComplete(); + + +protected: + + /** + * Format the "personal comments" field for sending mail. + **/ + QString formatComment(); + + + QString _feedbackMailAddress; + KFeedbackQuestionList * _questionList; + QMultiLineEdit * _comment; +}; + + + +/** + * List of feedback questions presented in a @ref QListView widget. + **/ +class KFeedbackQuestionList: public QListView +{ + Q_OBJECT + +public: + + /** + * Constructor. + **/ + KFeedbackQuestionList( QWidget *parent ); + + /** + * Destructor. + **/ + virtual ~KFeedbackQuestionList(); + + /** + * Returns whether or not this question list is answered satisfactorily, + * i.e. if all questions marked as "required" are answered. + **/ + virtual bool isComplete(); + + /** + * The result of all answered questions in ASCII. + **/ + QString result(); + + /** + * Add a yes/no question to the list. + * + * 'text' is the text the user will see (in his native language). + * + * 'id' is what will be sent with the feedback mail, thus it should be + * unique within the application, yet human readable (preferably English) + * and not contain any weird characters that might confuse scripts that are + * later used to automatically parse those mails. + * Examples: "would_recommend_to_a_friend" + * + * Set 'required' to 'true' if answering this question is required to + * successfully complete this form. + * + * Returns a pointer to this question so you can add answers. + **/ + + KFeedbackQuestion * addQuestion( const QString & text, + const QString & id, + bool exclusiveAnswer = true, + bool required = false ); + + /** + * Add a yes/no question to the list. + **/ + void addYesNoQuestion( const QString & text, + const QString & id, + bool required = false ); + + /** + * Returns the first question of that list. + * Use @ref KFeedbackQuestion::next() to get the next one. + **/ + KFeedbackQuestion * firstQuestion() const + { return (KFeedbackQuestion *) QListView::firstChild(); } + + /** + * Notify the list that another question has been answered. + * Emits the @ref checkComplete() signal when all required questions are + * answered. + **/ + void questionAnswered(); + + /** + * Notify the list that another question has been added. + * Emits the @ref checkComplete() signal when a required question is + * added. + **/ + void questionAdded( KFeedbackQuestion * question ); + +signals: + /** + * Emitted when all required questions are answered. + **/ + void checkComplete(); +}; + + +/** + * A user feedback question to be inserted into a @ref KFeedbackQuestionList. + **/ +class KFeedbackQuestion: public QCheckListItem +{ +public: + + /** + * Constructor. + * + * The parent @ref KFeedbackQuestionList assumes ownership of this object, + * so don't delete it unless you want to delete it from the question list + * as well. + * + * 'text' is the text the user will see (in his native language). + * + * 'id' is what will be sent with the feedback mail, thus it should be + * unique within the application, yet human readable (preferably English) + * and not contain any weird characters that might confuse scripts that are + * later used to automatically parse those mails. + * Examples: "features_not_liked", "stability" + * + * Set 'required' to 'true' if answering this question is required to + * successfully complete this form. + * + * Set 'exclusiveAnswer' to 'true' if only one of all answers may be + * checked at any one time, to 'false' if multiple answers are allowed. + **/ + KFeedbackQuestion( KFeedbackQuestionList * parent, + const QString & text, + const QString & id, + bool exclusiveAnswer = true, + bool required = false, + bool open = true ); + + /** + * Add an answer to this question. Again, 'text' is what the user will see + * (translated to his native language), 'id' is what you will get back with + * the mail. The answer IDs need only be unique for that question; answers + * to other questions may have the same ID. + **/ + void addAnswer( const QString & text, + const QString & id ); + + /** + * Returns if answering this question is required. + **/ + bool isRequired() { return _required; } + + /** + * Returns if this question is answered satisfactorily. + **/ + bool isAnswered(); + + /** + * The result of this question in ASCII, e.g. + * recommend="yes" + * or + * features_i_like="builtin_tetris" + * features_i_like="pink_elephant" + * features_i_like="studlycapslyfier" + **/ + QString result(); + + /** + * Return this question's ID. + **/ + QString id() { return _id; } + + /** + * Return this question's text. + **/ + QString text(); + + /** + * Returns whether or not this question requires an exclusive answer. + **/ + bool exclusiveAnswer() { return _exclusiveAnswer; } + + + /** + * Returns the sort key. + * + * Reimplemented from @ref QListViewItem to maintain insertion order. + **/ + virtual QString key( int column, bool ascending ) const; + + /** + * Returns the next question or 0 if there is no more. + **/ + KFeedbackQuestion * nextQuestion() const + { return (KFeedbackQuestion *) QListViewItem::nextSibling(); } + + /** + * Returns the first possible answer to this question. + * Use @ref KFeedbackAnswer::nextAnswer() to get the next one. + **/ + KFeedbackAnswer * firstAnswer() const + { return (KFeedbackAnswer *) QListViewItem::firstChild(); } + + /** + * Returns the @ref KFeedbackQuestionList this question belongs to or 0 if + * the parent is no @ref KFeedbackQuestionList. + **/ + KFeedbackQuestionList * questionList() const; + + +protected: + + QString _id; + bool _exclusiveAnswer; + bool _required; + int _no; +}; + + +class KFeedbackAnswer: public QCheckListItem +{ +public: + /** + * Constructor. + * + * 'exclusive' tells the type of answer: One of many allowed or any number + * of many. + **/ + KFeedbackAnswer( KFeedbackQuestion * parent, + const QString & text, + const QString & id, + bool exclusive = true ); + + /** + * Return this answer's ID. + **/ + QString id() { return _id; } + + /** + * Return this answer's text. + **/ + QString text(); + + /** + * Returns whether or not this is an exclusive answer. + **/ + bool isExclusive() { return _exclusive; } + + /** + * Returns whether or not this answer is checked. + **/ + bool isChecked() { return QCheckListItem::isOn(); } + + /** + * Returns the next possible answer or 0 if there is no more. + **/ + KFeedbackAnswer * nextAnswer() const + { return (KFeedbackAnswer *) QListViewItem::nextSibling(); } + + /** + * Returns the question to this answer. + **/ + KFeedbackQuestion * question() const + { return (KFeedbackQuestion *) QListViewItem::parent(); } + + /** + * Returns the sort key. + * + * Reimplemented from @ref QListViewItem to maintain insertion order. + **/ + virtual QString key( int column, bool ascending ) const; + + + /** + * On/off change. + * + * Reimplemented from @ref QCheckListItem to monitor answering required + * questions. This method notifies the @ref KFeedbackQuestionList whenever + * a required question is being answered. + **/ + virtual void stateChange( bool newState ); + +protected: + + QString _id; + bool _exclusive; + int _no; +}; + + + +#endif // KFeedback_h + + +// EOF diff --git a/src/kvpnc.cpp b/src/kvpnc.cpp new file mode 100644 index 0000000..a743284 --- /dev/null +++ b/src/kvpnc.cpp @@ -0,0 +1,25220 @@ +/************************************************************************* +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* Contains parts of code from klcc project * +* (Peter Simonsson ). * +* * +* Contains parts of code from kdirstat project * +* (Stefan Hundhammer ) * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +//BEGIN includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "debugoutputtextedit.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#include +#include +#include +#include +#include +#include +// #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kvpnc.h" +#include "mainview.h" +#include "mainviewbase.h" +#include "helpdialog.h" +#include "importprofiledialog.h" +#include "importopenvpnprofiledialog.h" +#include "networkinterface.h" +#include "newprofiledialog.h" +#include "importcertificatedialog.h" +#include "vpnaccountdata.h" +#include "enterpassworddialog.h" +#include "enterxauthinteractivepasscodedialog.h" +#include +#include +#include "utils.h" +#include "toolsinfodialog.h" +#include "vpntypesinfodialog.h" +#include "logviewerdialog.h" +#include "generateopenvpnkeydialog.h" +#include "newprofilewizard.h" +#include "manageciscocert.h" +#include "ciscocertificateenrollment.h" + +//END includes + +KVpnc::KVpnc ( KApplication *parent, QWidget*, const char *name ) : KMainWindow ( 0, name ), DCOPObject ( "KVpncInterface" ) +{ + this->parent = parent; + setCaption ( i18n ( "KVpnc" ) ); + + GlobalConfig = new KVpncConfig ( this, statusBar() ); + GlobalConfig->appPointer = parent; + GlobalConfig->config = kapp->config(); + + this->initStatusbar(); + this->initAction(); + this->initDockWindow(); + this->initView(); + mw->buttonConnect->setEnabled ( false ); + mw->buttonDisconnect->setEnabled ( false ); + + GlobalConfig->setLogOutput ( mw->DebugOutput ); + GlobalConfig->status = GlobalConfig->disconnected; + + VpncConnectScript = ""; + VpncDisconnectScript = ""; + OldDefaultroute = ""; + + TunnelInterfaceIP = ""; + VpncDevice = ""; + L2tpPppDevice = ""; + PppdDevice = ""; + OpenvpnDevice = ""; + SshDevice = ""; + + connectCounter = 0; + + VpncProcess = 0; + DisconnectProcess = 0; + RacoonProcess = 0; + RacoonHelperProcess = 0; + IpsecProcess = 0; + PingProcess = 0; + RacoonTailProcess = 0; + X509CertificateExtractProcess = 0; + PptpProcess = 0; + OpenvpnProcess = 0; + CmdAfterConnectProcess = 0; + CmdAfterDisconnectProcess = 0; + RouteProcess = 0; + SetVirtualIPProcess = 0; + ReplaceDefaultRouteProcess = 0; + ConnectionStatusCheckProcess = 0; + hour = min = sec = 0; + env = new QStringList(); + *env << "LC_ALL=C" << "LANG=C" << "PATH=/bin:/usr/bin:/usr/sbin:/sbin"; + + AuthRetry = false; + GlobalConfig->doAutoConnectAtStartup = false; + quitFromKicker = false; + ciscoVpncRunning = false; + showProfilesOnly=false; + + tmpPath = locateLocal ( "data", "kvpnc/" ); + QFile file ( tmpPath + "kvpnc_running" ); + + if ( !file.exists() ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "KVpnc started normal." ), GlobalConfig->debug ); + QTextStream stream ( &file ); + if ( file.open ( IO_WriteOnly ) ) + { + stream << "created at: " << QDate().currentDate().toString ( "yyyyMMdd" ) << QTime().currentTime().toString ( "hhmm" ) << "\n"; + file.close(); + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "Warning: could not write lock file in kde data dir, please check permissions." ), GlobalConfig->info ); + } + GlobalConfig->loadOptions(); + preserveNetworkEnvironment(); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "KVpnc started after a crash, restoring network environment and config." ), GlobalConfig->debug ); + restoreNetworkEnvironment(); + GlobalConfig->restoreBackupConfig(); + GlobalConfig->loadOptions(); + } + + GlobalConfig->ToolList = Utils ( GlobalConfig ).getToolList(); + GlobalConfig->getToolsInfo(); + + toolBar ( "mainToolBar" ) ->applySettings ( GlobalConfig->config, "ToolBar Settings" ); + // ShowToolbarAction->setChecked( GlobalConfig->showToolBar ); + + ShowStatusbarAction->setChecked ( GlobalConfig->showStatusBar ); + slotShowStatusbar(); + + if ( GlobalConfig->showDebugConsole ) + { + mw->DebugOutput->show(); + } + else + { + mw->DebugOutput->hide(); + // setMinimumSize(0,0); + // this->resize( minimumSizeHint() ); + } + DebugconsoleAction ->setChecked ( GlobalConfig->showDebugConsole ); + GlobalConfig->LogOutput->setPaper ( QBrush ( QColor ( GlobalConfig->DebugBackgroundcolor ) ) ); + + if ( GlobalConfig->WindowSize.width() < 50 || GlobalConfig->WindowSize.height() < 50 ) + { + GlobalConfig->WindowSize = QSize ( minimumWidth(), minimumHeight() ); + } + + if ( GlobalConfig->WindowPos.x() < 0 || GlobalConfig->WindowPos.y() < 0 ) + GlobalConfig->WindowPos = QPoint ( 0, 0 ); + + resize ( GlobalConfig->WindowSize ); + move ( GlobalConfig->WindowPos ); + + QuickConnectMenu = new QPopupMenu ( KVpncDock->menu() ); + connect ( QuickConnectMenu, SIGNAL ( activated ( int ) ), this, SLOT ( doQuickConnect ( int ) ) ); + + connect ( parent, SIGNAL ( shutDown() ), this, SLOT ( shutdownCalled() ) ); + + connect ( KVpncDock, SIGNAL ( closeEventKicker ( QCloseEvent * ) ),this,SLOT ( closeEvent ( QCloseEvent * ) ) ); + + for ( uint i = 0; i < GlobalConfig->AccountList->count();i++ ) + { + QuickConnectMenu->insertItem ( GlobalConfig->AccountList->at ( i ) ->getName() ); + mw->SessionCombo->insertItem ( GlobalConfig->AccountList->at ( i ) ->getName() ); + } + + if ( !GlobalConfig->AccountList->isEmpty() ) + mw->SessionCombo->setEnabled ( true ); + + KVpncDock->menu() ->insertItem ( i18n ( "Connecting To..." ), QuickConnectMenu, 0, 3 ); + KVpncDock->menu() ->insertSeparator ( 3 ); + + if ( !GlobalConfig->lastProfile.isEmpty() ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Last used profile found: %1" ).arg ( GlobalConfig->lastProfile ), KVpncConfig::debug ); + VpnAccountData * it; + for ( it = GlobalConfig->AccountList->first(); it; it = GlobalConfig->AccountList->next() ) + { + if ( it->getName() == GlobalConfig->lastProfile ) + { + GlobalConfig->currentProfile = it; + mw->SessionCombo->setCurrentText ( GlobalConfig->lastProfile ); + sessionToggled ( GlobalConfig->lastProfile ); + break; + } + } + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "No last used profile found." ), KVpncConfig::info ); + if ( !GlobalConfig->AccountList->isEmpty() ) + { + this->ConnectAction->setEnabled ( true ); + this->mw->buttonConnect->setEnabled ( true ); + mw->SessionCombo->setCurrentItem ( 1 ); + GlobalConfig->currentProfile = GlobalConfig->AccountList->first(); + mw->SessionCombo->setEnabled ( true ); + } + else + { + DeleteSessionAction->setEnabled ( FALSE ); + ConnectAction->setEnabled ( FALSE ); + GlobalConfig->currentProfile = 0; + } + } + + + + + //Failsafe + if ( KVpncDock->isHidden() && isHidden() ) + { + this->show(); + } + else + { + if ( GlobalConfig->hideMainWindow ) + hide(); + else + show(); + } + + // auto connect + if ( GlobalConfig->doAutoConnectAtStartup ) + { + bool profileInList = false; + for ( uint i = 0; i < GlobalConfig->AccountList->count();i++ ) + { + if ( GlobalConfig->AccountList->at ( i ) ->getName() == GlobalConfig->AutoConnectProfile ) + { + profileInList = true; + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Automatic connection at startup to \"%1\" requested." ).arg ( GlobalConfig->AutoConnectProfile ), GlobalConfig->debug ); + + sessionToggled ( GlobalConfig->AutoConnectProfile ); + mw->SessionCombo->setCurrentText ( GlobalConfig->AutoConnectProfile ); + GlobalConfig->currentProfile = GlobalConfig->AccountList->at ( i ); + connectClicked(); + break; + } + } + + if ( !profileInList ) + { + GlobalConfig->doAutoConnectAtStartup = false; + } + } + +} + +KVpnc::~KVpnc() +{ + delete env; + delete QuickConnectMenu; + delete GlobalConfig; + delete SaveSessionAction; + delete DeleteSessionAction; + // delete NewSessionAction; + delete ImportSessionAction; + delete ImportOpenvpnProfileAction; + delete ImportCertAction; + delete ConnectAction; + delete DisconnectAction; + delete ProfileManagerAction; + delete NewProfileWizardAction; + delete DonateAction; + delete ReportBugAction; + delete DebugconsoleAction; + delete ToolsInfoAction; + delete LogViewerAction; + delete GenerateOpenvpnKeyAction; + delete ManageCiscoCertAction; + delete CiscoCertEnrollmentAction; +} + +void KVpnc::initAction() +{ + disconnectedIcon = KGlobal::iconLoader() ->loadIcon ( "disconnected", KIcon::NoGroup, 22 ); + connectedIcon = KGlobal::iconLoader() ->loadIcon ( "connected", KIcon::NoGroup, 22 ); + connectingIcon = KGlobal::iconLoader() ->loadIcon ( "connecting", KIcon::NoGroup, 22 ); + setIcon ( disconnectedIcon ); + + ( void* ) KStdAction::quit ( this, SLOT ( quitCalled() ), actionCollection() ); + + SaveSessionAction = new KAction ( i18n ( "&Save Profile..." ), "fileexport", Key_S, this, SLOT ( saveSessionClicked() ), actionCollection(), "saveSession" ); + DeleteSessionAction = new KAction ( i18n ( "&Delete Profile..." ), "editdelete", Key_D, this, SLOT ( deleteSessionClicked() ), actionCollection(), "deleteSession" ); + RenameSessionAction = new KAction ( i18n ( "&Rename Profile..." ), "view_detailed", Key_D, this, SLOT ( renameSessionClicked() ), actionCollection(), "renameSession" ); + // NewSessionAction = new KAction( i18n( "&New Profile..." ), "profilenew", Key_N, this, SLOT( newSessionClicked() ), actionCollection(), "newSession" ); + //AdvancedSessionAction = new KAction( i18n( "&Advanced..." ), "wizard", Key_A, this, SLOT( advancedSettingsClicked() ), actionCollection(), "advancedSettingsSession" ); + ImportSessionAction = new KAction ( i18n ( "&Import Cisco pcf file..." ), "cisco", Key_F, this, SLOT ( importProfileClicked() ), actionCollection(), "importSession" ); + ImportOpenvpnProfileAction = new KAction ( i18n ( "Import &OpenVPN config file..." ), "openvpnimport", Key_O, this, SLOT ( importOpenvpnProfileClicked() ), actionCollection(), "importOpenvpnConfig" ); + ImportFreeswanProfileAction = new KAction ( i18n ( "Import &Freeswan/Openswan/strongSwan config file..." ), "openswan", Key_I, this, SLOT ( importIpsecProfileClicked() ), actionCollection(), "importFreeswanConfig" ); + ImportFritzboxProfileAction = new KAction ( i18n ( "Import Fritz&box VPN user config file..." ), "fritzboximport", Key_I, this, SLOT ( importFritzboxProfileClicked() ), actionCollection(), "importFritzboxConfig" ); + ImportCertAction = new KAction ( i18n ( "Import &certificate..." ), "certimport", Key_C, this, SLOT ( importCertClicked() ), actionCollection(), "importCert" ); + ManageCiscoCertAction = new KAction ( i18n ( "Manage Cisco certificates..." ), "certimport", Key_C, this, SLOT ( manageCiscoCertClicked() ), actionCollection(), "manageCiscoCert" ); + CiscoCertEnrollmentAction = new KAction ( i18n ( "Enroll Cisco certificates..." ), "certimport", Key_T, this, SLOT ( enrollCiscoCertClicked() ), actionCollection(), "enrollCiscoCert" ); + ExportOpenvpnProfileAction = new KAction ( i18n ( "Export &OpenVPN profile to config file" ), "openvpnexport", Key_O, this, SLOT ( exportOpenvpnProfileClicked() ), actionCollection(), "exportOpenvpnConfig" ); + + ImportKvpncSettingsAction = new KAction ( i18n ( "Import KVpnc settings..." ), "2downarrow", Key_I, this, SLOT ( importKvpncSettingsClicked() ), actionCollection(), "importKvpncSettings" ); + ExportKvpncSettingsAction = new KAction ( i18n ( "Export KVpnc settings to file" ), "2uparrow", Key_E, this, SLOT ( exportKvpncSettingsClicked() ), actionCollection(), "exportKvpncSettings" ); + + ConnectAction = new KAction ( i18n ( "&Connect" ), "connected", CTRL + Key_Up, this, SLOT ( slotConnecting() ), actionCollection(), "serverConnect" ); + DisconnectAction = new KAction ( i18n ( "&Disconnect" ), "disconnected", CTRL + Key_Down, this, SLOT ( disconnectClicked() ), actionCollection(), "serverDisconnect" ); + ProfileManagerAction = new KAction ( i18n ( "&Manage Profiles" ), "view_detailed", CTRL + Key_M, this, SLOT ( showProfileManagerClicked() ), actionCollection(), "profileManager" ); + NewProfileWizardAction = new KAction ( i18n ( "&new Profile (Wizard)" ), "wizard", CTRL + Key_W, this, SLOT ( showNewProfileWizardClicked() ), actionCollection(), "NewProfileWizard" ); + DonateAction = new KAction ( i18n ( "&Support KVpnc..." ), "donate", CTRL + Key_D, this, SLOT ( donateClicked() ), actionCollection(), "donate" ); + ReportBugAction = new KAction ( i18n ( "&Report a bug..." ), "bug", CTRL + Key_R, this, SLOT ( reportBugClicked() ), actionCollection(), "reportbug" ); + DebugconsoleAction = new KToggleAction ( i18n ( "Toggle Debug &Console" ), "text_center", CTRL + Key_C, this, SLOT ( toggleDebugConsole() ), actionCollection(), "debugconsole" ); + ToolsInfoAction = new KToggleAction ( i18n ( "Show &Tools Info" ), "info", CTRL + Key_I, this, SLOT ( toolsInfoClicked() ), actionCollection(), "toolsinfo" ); + VpnTypesInfoAction = new KToggleAction ( i18n ( "Show &VPN types Info" ), "info", CTRL + Key_T, this, SLOT ( vpnTypesInfoClicked() ), actionCollection(), "vpntypesinfo" ); + // // tmp +// ToolsInfoAction = new KToggleAction ( i18n("Show &Tools Info"), "info", CTRL + Key_T, this, SLOT(helpClicked() ), actionCollection(), "toolsinfo" ); + + LogViewerAction = new KToggleAction ( i18n ( "Show &Log" ), "log", CTRL + Key_L, this, SLOT ( showLogViewer() ), actionCollection(), "logviewer" ); + GenerateOpenvpnKeyAction = new KToggleAction ( i18n ( "Generate OpenVPN Key" ), "key", CTRL + Key_G, this, SLOT ( generateOpenvpnKey() ), actionCollection(), "genOpenvpncKey" ); + SendFeedbackMailAction = new KAction ( i18n ( "Send &Feedback Mail..." ), 0, this, SLOT ( sendFeedbackMail() ), actionCollection(), "help_send_feedback_mail" ); + PrefAction = KStdAction::preferences ( this, SLOT ( slotSettings() ), actionCollection(), "preferences" ); + KStdAction::helpContents ( this, SLOT ( helpClicked () ), actionCollection(), "help" ); + KStdAction::configureNotifications ( this, SLOT ( slotConfigNotifications() ), actionCollection() ); + KStdAction::keyBindings ( this, SLOT ( slotKeyBindings() ), actionCollection() ); + + this->ConnectAction->setEnabled ( false ); + this->DisconnectAction->setEnabled ( false ); + + // ShowToolbarAction = KStdAction::showToolbar( this, SLOT( slotShowToolbar() ), actionCollection() ); + createStandardStatusBarAction(); + ShowStatusbarAction = KStdAction::showStatusbar ( this, SLOT ( slotShowStatusbar() ), actionCollection() ); + PreferencesAction = KStdAction::preferences ( this, SLOT ( slotSettings() ), actionCollection() ); + + ( void* ) KStdAction::keyBindings ( this, SLOT ( slotKeyBindings() ), actionCollection() ); + ( void* ) KStdAction::configureToolbars ( this, SLOT ( slotConfigToolbars() ), actionCollection() ); + ( void* ) KStdAction::configureNotifications ( this, SLOT ( slotConfigNotifications() ), actionCollection() ); + + createGUI(); + +} + +void KVpnc::initView() +{ + + mw = new MainView ( this, "mainView" ); + setCentralWidget ( mw ); + + connect ( mw->buttonConnect, SIGNAL ( clicked() ), this, SLOT ( slotConnecting() ) ); + connect ( mw->buttonDisconnect, SIGNAL ( clicked() ), this, SLOT ( disconnectClicked() ) ); + + connect ( mw->SessionCombo, SIGNAL ( activated ( const QString & ) ), this, SLOT ( sessionToggled ( const QString& ) ) ); + + mw->SessionCombo->setEnabled ( FALSE ); + + statusColorLabel = new QLabel ( this ); + disconnectedStatusPixmap = new QPixmap ( 15, 15 ); + disconnectedStatusPixmap->fill ( QColor ( Qt::red ) ); + connectedStatusPixmap = new QPixmap ( 15, 15 ); + connectedStatusPixmap->fill ( QColor ( Qt::green ) ); + connectingStatusPixmap = new QPixmap ( 15, 15 ); + connectingStatusPixmap->fill ( QColor ( Qt::yellow ) ); + + + statusColorLabel->setPixmap ( *disconnectedStatusPixmap ); + statusBar() ->addWidget ( statusColorLabel, 0, true ); + + KNotifyClient::startDaemon(); + + +} + +void KVpnc::initStatusbar() +{ + statusBar() ->insertItem ( i18n ( "Ready." ), 1, 100 ); + statusBar() ->setItemAlignment ( 1, AlignLeft | AlignVCenter ); + statusBar() ->insertItem ( i18n ( "Disconnected" ), 2, 0, true ); +} + +void KVpnc::initDockWindow() +{ + KVpncDock = new KVpncKicker ( GlobalConfig, this, "kickerIcon" ); + ConnectAction->plug ( KVpncDock->menu(), 1 ); + DisconnectAction->plug ( KVpncDock->menu(), 2 ); + KVpncDock->menu() ->insertSeparator ( 5 ); + PreferencesAction->plug ( KVpncDock->menu(), 6 ); + connect (KVpncDock, SIGNAL(tooltipRequested()), this, SLOT(showDockTooltip())); +} + +void KVpnc::slotSettings() +{ + this->slotStatusMsg ( i18n ( "Setup KVpnc..." ), ID_FLASH_MSG ); + this->slotStatusMsg ( i18n ( "Ready." ), ID_STATUS_MSG ); + + prefDlg = new PreferencesDialog ( this, parent, mw->DebugOutput, GlobalConfig, showProfilesOnly ); +// prefDlg->setMinimumSize ( 800, 600 ); + + VpnAccountData *oldProfile = GlobalConfig->currentProfile; + connect ( prefDlg->ProfileGeneralOptionsWidget->NewSessionPushButton , SIGNAL ( clicked () ), this, SLOT ( showNewProfileWizardClicked() ) ); + connect ( this, SIGNAL(newProfileCreated(QString )), prefDlg, SLOT(slotProfileCreated(QString ))); + prefDlg->exec(); + + GlobalConfig->LogOutput->setPaper ( QBrush ( QColor ( GlobalConfig->DebugBackgroundcolor ) ) ); + + if ( prefDlg->profileAddedOrDeleted ) + { + if ( GlobalConfig->KvpncDebugLevel > 4 ) + GlobalConfig->appendLogEntry ( i18n ( "Profile list has been changed, updating GUI..." ), GlobalConfig->debug ); + GlobalConfig->saveOptions(); + saveGuiOptions(); + if ( GlobalConfig->AccountList->isEmpty() ) + { +// GlobalConfig->currentProfile = 0L; + mw->SessionCombo->setEnabled ( FALSE ); + ConnectAction->setEnabled ( false ); + mw->buttonConnect->setEnabled ( FALSE ); + mw->SessionCombo->clear(); + } + else + { + QString Name = ""; + if ( GlobalConfig->currentProfile != 0 ) + Name = GlobalConfig->currentProfile->getName(); + if ( Name != mw->SessionCombo->currentText() ) + GlobalConfig->currentProfile = oldProfile; // restore from beforNme calling pref dialog + + if ( GlobalConfig->currentProfile != 0 ) + { + mw->SessionCombo->setCurrentText ( Name ); + sessionToggled ( Name ); + } + profileAddedOrDeleted(); + if ( !prefDlg->NewProfileName.isEmpty() ) + { + mw->SessionCombo->setCurrentText ( prefDlg->NewProfileName ); + sessionToggled ( prefDlg->NewProfileName ); + } + } + + } + if ( prefDlg->profileHasChanged ) + { + mw->SessionCombo->setCurrentText ( prefDlg->NewProfileName ); + sessionToggled ( prefDlg->NewProfileName ); + } + + if ( GlobalConfig->showDebugConsole ) + { + mw->DebugOutput->show(); + //resize( minimumSizeHint() ); + } + else + { + mw->DebugOutput->hide(); + setMinimumSize ( 0, 0 ); + this->resize ( minimumSizeHint() ); + } + + if ( GlobalConfig->writeLogFile ) + { + if ( !GlobalConfig->logfile.isOpen() ) + { + KStandardDirs * dirs = KGlobal::dirs(); + QString logfileName = QString ( dirs->saveLocation ( "data" ) ); + QString logfilePath = QString ( logfileName + "/kvpnc/kvpnc.log" ); + //KMessageBox::information( this, "info", logfileName ); + GlobalConfig->logfile.setName ( logfileName ); + if ( !GlobalConfig->logfile.open ( IO_WriteOnly | IO_Append ) ) + { + KMessageBox::error ( this, i18n ( "Log file cannot be opened!" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Log file cannot be opened!" ) , GlobalConfig->error ); + } + else + { + GlobalConfig->logFileStream << i18n ( "Log session started at: " ) << QDateTime::currentDateTime().toString ( Qt::TextDate ) << endl; + } + } + } + else + { + if ( GlobalConfig->logfile.isOpen() ) + { + //QTextStream s( &logfile ); + GlobalConfig->logFileStream << i18n ( "Log session ended at: " ) << QDateTime::currentDateTime().toString ( Qt::TextDate ) << endl; + GlobalConfig->logfile.close(); + } + } + //GlobalConfig->saveOptions(); + //saveGuiOptions(); + saveSessionClicked(); + showProfilesOnly=false; + disconnect ( prefDlg->ProfileGeneralOptionsWidget->NewSessionPushButton , SIGNAL ( clicked () ), this, SLOT ( showNewProfileWizardClicked() ) ); + disconnect ( this, SIGNAL(newProfileCreated(QString )), prefDlg, SLOT(slotProfileCreated(QString ))); + delete prefDlg; +} + +void KVpnc::slotShowToolbar() +{ + // if ( !ShowToolbarAction->isChecked() ) + // toolBar( "mainToolBar" )->hide(); + // else + // toolBar( "mainToolBar" )->show(); +} + +void KVpnc::slotShowStatusbar() +{ + + if ( !ShowStatusbarAction->isChecked() ) + { + statusBar() ->hide(); + GlobalConfig->showStatusBar = false; + ShowStatusbarAction->setChecked ( false ); + } + else + { + statusBar() ->show(); + GlobalConfig->showStatusBar = true; + ShowStatusbarAction->setChecked ( true ); + } +} + +void KVpnc::slotKeyBindings() +{ + + //FIXME remove dublicate entries + KKeyDialog::configure ( actionCollection(), this ); +} + +void KVpnc::slotConfigToolbars() +{ + KEditToolbar dlg ( actionCollection() ); + + if ( dlg.exec() ) + { + createGUI(); + } +} + +void KVpnc::slotConfigNotifications() +{ + KNotifyDialog::configure ( this ); +} + +void KVpnc::slotStatusMsg ( const QString &text, int id ) +{ + if ( id != ID_FLASH_MSG ) + { + statusBar() ->clear(); + statusBar() ->changeItem ( text, id ); + } + else + { + statusBar() ->message ( text, 2000 ); + } + +} + +void KVpnc:: quitCalled() +{ + bool reallyQuit = false; + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "quitCalled()" ), GlobalConfig->debug ); + QString TypeString = ""; + + if ( GlobalConfig->currentProfile != 0 ) + { + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::cisco ) + TypeString = i18n ( "Cisco" ); + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ciscoorig ) + TypeString = i18n ( "Cisco (propritary)" ); + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::pptp ) + TypeString = i18n ( "PPTP" ); + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon ) + TypeString = i18n ( "racoon" ); + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan ) + TypeString = IpsecType; + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::openvpn ) + TypeString = i18n ( "OpenVPN" ); + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) + TypeString = i18n ( "L2TP (racoon)" ); + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + TypeString = IpsecType; + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::vtun ) + TypeString = i18n ( "Vtun" ); + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ssh ) + TypeString = i18n ( "SSH" ); + else + TypeString = i18n ( "other" ); + } + + GlobalConfig->WindowSize = QSize ( QWidget::width(), QWidget::height() ); + GlobalConfig->WindowPos = QPoint ( this->x(), this->y() ); + + if ( GlobalConfig->status == GlobalConfig->connected ) + { + int res; + if ( !GlobalConfig->shutdownIsCalled && !GlobalConfig->useSilentQuit ) + { + res = KMessageBox::questionYesNo ( this, i18n ( "You are still connected to \"%1\" (%2) Do you really want to quit?" ).arg ( GlobalConfig->currentProfile->getName() ).arg ( TypeString ), i18n ( "Quit?" ), KStdGuiItem::quit(), KStdGuiItem::cancel() ); + if ( res != 4 ) + { + disconnectClicked(); + reallyQuit = true; + GlobalConfig->skipKwalletStoring = true; + if ( !GlobalConfig->AccountList->isEmpty() && GlobalConfig->currentProfile != 0 ) + GlobalConfig->lastProfile = GlobalConfig->currentProfile->getName(); + if ( GlobalConfig->writeLogFile ) + { + if ( GlobalConfig->logfile.isOpen() ) + { + // QTextStream s( &logfile ); + GlobalConfig->logFileStream << i18n ( "Log session ended at: " ) << QDateTime::currentDateTime().toString ( Qt::TextDate ) << endl; + GlobalConfig->logfile.flush(); + GlobalConfig->logfile.close(); + GlobalConfig->appPointer->processEvents(); + } + } + saveGuiOptions(); + GlobalConfig->saveOptions(); + restoreNetworkEnvironment(); + tmpPath = locateLocal ( "data", "kvpnc/" ); + QFile file ( tmpPath + "kvpnc_running" ); + file.remove(); + kapp->quit(); + } + } + else + { + disconnectClicked(); + reallyQuit = true; + GlobalConfig->skipKwalletStoring = true; + if ( !GlobalConfig->AccountList->isEmpty() && GlobalConfig->currentProfile != 0 ) + GlobalConfig->lastProfile = GlobalConfig->currentProfile->getName(); + if ( GlobalConfig->writeLogFile ) + { + if ( GlobalConfig->logfile.isOpen() ) + { + // QTextStream s( &logfile ); + GlobalConfig->logFileStream << i18n ( "Log session ended at: " ) << QDateTime::currentDateTime().toString ( Qt::TextDate ) << endl; + GlobalConfig->logfile.flush(); + GlobalConfig->logfile.close(); + GlobalConfig->appPointer->processEvents(); + } + } + saveGuiOptions(); + GlobalConfig->saveOptions(); + restoreNetworkEnvironment(); + tmpPath = locateLocal ( "data", "kvpnc/" ); + QFile file ( tmpPath + "kvpnc_running" ); + file.remove(); + kapp->quit(); + } + } + if ( GlobalConfig->status == GlobalConfig->connecting ) + { + disconnectClicked(); + reallyQuit = true; + GlobalConfig->skipKwalletStoring = true; + if ( !GlobalConfig->AccountList->isEmpty() && GlobalConfig->currentProfile != 0 ) + GlobalConfig->lastProfile = GlobalConfig->currentProfile->getName(); + if ( GlobalConfig->writeLogFile ) + { + if ( GlobalConfig->logfile.isOpen() ) + { + // QTextStream s( &logfile ); + GlobalConfig->logFileStream << i18n ( "Log session ended at: " ) << QDateTime::currentDateTime().toString ( Qt::TextDate ) << endl; + GlobalConfig->logfile.flush(); + GlobalConfig->logfile.close(); + GlobalConfig->appPointer->processEvents(); + } + } + saveGuiOptions(); + GlobalConfig->saveOptions(); + restoreNetworkEnvironment(); + tmpPath = locateLocal ( "data", "kvpnc/" ); + QFile file ( tmpPath + "kvpnc_running" ); + file.remove(); + kapp->quit(); + + } + else + { + reallyQuit = true; + if ( reallyQuit ) + { + if ( !GlobalConfig->AccountList->isEmpty() ) + if ( GlobalConfig->currentProfile != 0 ) + GlobalConfig->lastProfile = GlobalConfig->currentProfile->getName(); + + if ( GlobalConfig->writeLogFile ) + { + if ( GlobalConfig->logfile.isOpen() ) + { + // QTextStream s( &logfile ); + GlobalConfig->logFileStream << i18n ( "Log session ended at: " ) << QDateTime::currentDateTime().toString ( Qt::TextDate ) << endl; + GlobalConfig->logfile.flush(); + GlobalConfig->logfile.close(); + GlobalConfig->appPointer->processEvents(); + } + } + saveGuiOptions(); + GlobalConfig->saveOptions(); + restoreNetworkEnvironment(); + tmpPath = locateLocal ( "data", "kvpnc/" ); + QFile file ( tmpPath + "kvpnc_running" ); + file.remove(); + kapp->quit(); + } + } +} + +void KVpnc::quitCalledKicker() +{ + quitFromKicker = true; + quitCalled(); + //KMessageBox::information( this, "kicker quit", "info" ); +} + +void KVpnc::shutdownCalled() +{ + GlobalConfig->shutdownIsCalled = true; + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "shutdown called!" ), GlobalConfig->debug ); +} + +void KVpnc::closeEvent ( QCloseEvent *e ) +{ + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "CloseEvent recieved (reciever: %1)." ).arg ( "kvpnc" ), GlobalConfig->debug ); + + QString TypeString = ""; + if ( GlobalConfig->currentProfile != 0 ) + { + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::cisco ) + TypeString = i18n ( "Cisco" ); + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ciscoorig ) + TypeString = i18n ( "Cisco (proprietary)" ); + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::pptp ) + TypeString = i18n ( "PPTP" ); + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon ) + TypeString = i18n ( "racoon" ); + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan ) + TypeString = IpsecType; + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::openvpn ) + TypeString = i18n ( "OpenVPN" ); + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) + TypeString = i18n ( "L2TP (racoon)" ); + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + TypeString = IpsecType; + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::vtun ) + TypeString = i18n ( "Vtun" ); + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ssh ) + TypeString = i18n ( "SSH" ); + else + TypeString = i18n ( "other" ); + } + + if ( GlobalConfig->dontQuitOnCloseEvent == false || quitFromKicker == true || kapp->sessionSaving() ) + { + bool reallyQuit = false; + if ( GlobalConfig->status == GlobalConfig->connected ) + { + int res; + if ( kapp->sessionSaving() ) //KDE is going down, skip kwallet, disconnect and quit + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Shutdown was called...exiting.\n" ), GlobalConfig->debug ); + reallyQuit = true; + GlobalConfig->skipKwalletStoring = true; + disconnectClicked(); + } + else + { + if ( !GlobalConfig->useSilentQuit ) + { + res = KMessageBox::questionYesNo ( this, i18n ( "You are still connected to \"%1\" (%2) Do you really want to quit?" ).arg ( GlobalConfig->currentProfile->getName() ).arg ( TypeString ), i18n ( "Quit?" ), KStdGuiItem::quit(), KStdGuiItem::cancel() ); + //KMessageBox::error( this,QString().setNum(res) ); + if ( res != 4 ) + { + reallyQuit = true; + GlobalConfig->skipKwalletStoring = true; + disconnectClicked(); + + if ( reallyQuit ) + { + GlobalConfig->saveOptions(); + saveGuiOptions(); + + if ( GlobalConfig->writeLogFile ) + { + if ( GlobalConfig->logfile.isOpen() ) + { + // QTextStream s( &logfile ); + GlobalConfig->logFileStream << i18n ( "Log session ended at: " ) << QDateTime::currentDateTime().toString ( Qt::TextDate ) << endl; + GlobalConfig->logfile.close(); + GlobalConfig->appPointer->processEvents(); + } + } + tmpPath = locateLocal ( "data", "kvpnc/" ); + QFile file ( tmpPath + "kvpnc_running" ); + file.remove(); + + KMainWindow::closeEvent ( e ); + } + else + { + e = 0L; + } + } + else + { + e = 0L; + } + } + else + { + //disconnect and quit silently + GlobalConfig->skipKwalletStoring = true; + disconnectClicked(); + reallyQuit = true; + } + } + } + else + { + reallyQuit = true; + GlobalConfig->skipKwalletStoring = true; + } + + if ( reallyQuit ) + { + GlobalConfig->saveOptions(); + saveGuiOptions(); + + //KMainWindow::closeEvent( e ); + disconnectClicked(); + tmpPath = locateLocal ( "data", "kvpnc/" ); + QFile file ( tmpPath + "kvpnc_running" ); + file.remove(); + if ( GlobalConfig->writeLogFile ) + { + if ( GlobalConfig->logfile.isOpen() ) + { + GlobalConfig->logFileStream << i18n ( "Log session ended at: " ) << QDateTime::currentDateTime().toString ( Qt::TextDate ) << endl; + GlobalConfig->logfile.flush(); + GlobalConfig->logfile.close(); + GlobalConfig->appPointer->processEvents(); + } + } + e->accept(); + kapp->quit(); + } + } + else + { + if ( !GlobalConfig->hideOnCloseInfo ) + KMessageBox::information ( this, i18n ( "Closing the main window will keep KVpnc running in the system tray. Use Quit from the File menu to quit the application." ), i18n ( "Docking in System Tray" ), "hideOnCloseInfo" ); + hide(); + } +} + +bool KVpnc::queryExit() +{ + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "queryExit recieved (reciever: %1)." ).arg ( "kvpnc" ), GlobalConfig->debug ); + kdDebug() << "KVpnc::queryExit()" << endl; + + if ( GlobalConfig->status == GlobalConfig->connecting || GlobalConfig->status == GlobalConfig->connected ) + { + disconnectClicked(); + } + + if ( !kapp->sessionSaving() ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "KVpnc::queryExit(): dont saving session" ), GlobalConfig->debug ); + kdDebug ( "KVpnc::queryExit(): dont saving session" ); + } + else + { + kdDebug ( "KVpnc::queryExit(): saving session" ); + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "KVpnc::queryExit(): dont saving session" ), GlobalConfig->debug ); +// GlobalConfig->saveOptions(); +// saveGuiOptions(); + + } + return true; +} + +bool KVpnc::queryClose() +{ + if ( kapp->sessionSaving() ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "KVpnc::queryClose()" ), GlobalConfig->debug ); + + return true; + } + else + { + if ( !GlobalConfig->hideOnCloseInfo ) + KMessageBox::information ( this, i18n ( "

Closing the main window will keep KVpnc running in the system tray. Use 'Quit' from the 'File' menu to quit the application.

" ), i18n ( "Docking in System Tray" ), "hideOnCloseInfo" ); + hide(); + return false; + } +} + +void KVpnc::restore ( KConfig *config, int i ) +{ + readPropertiesInternal ( config,i ); +} + +void KVpnc::restore() +{ + KConfig *config = parent->sessionConfig(); + + if ( !config ) + return; + + return; +} + +void KVpnc::saveProperties ( KConfig* c ) +{ + QString saveDir = KGlobal::dirs()->saveLocation ( "appdata", "sessions/" + qApp->sessionId() + "/", true ); + + c = new KSimpleConfig ( saveDir + "list", false ); + c->setGroup ( "Saved Session" ); + + delete c; +} + +void KVpnc::readProperties ( KConfig* c ) +{ + QString saveDir = KGlobal::dirs()->saveLocation ( "appdata", "sessions/" + qApp->sessionId() + "/", true ); + c = new KSimpleConfig ( saveDir + "list", true ); + c->setGroup ( "Saved Session" ); + delete c; +} + +void KVpnc::connectClicked() +{ + ConnectAction->setEnabled ( false ); + + TunnelInterfaceIP = i18n ( "None" ); + + bool ok = true; // if ok we will run process + bool useL2tpAfterFirstConnection = false; + stopContinue = false; + ToolInfo *IpsecToolInfo = Utils ( GlobalConfig ).getToolInfo ( "ipsec" ) ; + + QString TypeString = i18n ( "unknown" ); + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::cisco ) + TypeString = i18n ( "Cisco" ); + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ciscoorig ) + TypeString = i18n ( "Cisco (proprietary)" ); + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::pptp ) + TypeString = i18n ( "PPTP" ); + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan ) + { + if ( IpsecToolInfo->Version.contains ( "Openswan", false ) ) + IpsecType = TypeString = i18n ( "Openswan" ); + else if ( IpsecToolInfo->Version.contains ( "strongSwan", false ) ) + IpsecType = TypeString = i18n ( "strongSwan" ); + else + IpsecType = TypeString = i18n ( "FreeS/WAN" ); + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon ) + TypeString = "racoon"; + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::openvpn ) + TypeString = "OpenVPN"; + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { + TypeString = "L2TP (racoon)"; + useL2tpAfterFirstConnection = true; + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { + if ( IpsecToolInfo->Version.contains ( "Openswan", false ) ) + IpsecType = TypeString = "L2TP (Openswan)"; + else if ( IpsecToolInfo->Version.contains ( "strongSwan", false ) ) + IpsecType = TypeString = "L2TP (strongSwan)"; + else + IpsecType = TypeString = "L2TP (FreeS/WAN)"; + useL2tpAfterFirstConnection = true; + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::vtun ) + TypeString = "Vtun"; + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ssh ) + TypeString = "SSH"; + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Connect try requested, profile: %1, type: %2" ).arg ( GlobalConfig->currentProfile->getName() ).arg ( TypeString ), GlobalConfig->debug ); + + if ( GlobalConfig->currentProfile->getGateway().isEmpty() ) + { + KMessageBox::error ( this, i18n ( "No gateway for profile \"%1\" entered. STOP." ).arg ( GlobalConfig->currentProfile->getName() ) ); + GlobalConfig->appendLogEntry ( i18n ( "No gateway for profile \"%1\" entered. STOP." ).arg ( GlobalConfig->currentProfile->getName() ), GlobalConfig->error ); + ok = false; + setGuiStatus ( disconnected ); + return ; + } + + /* update dns? */ + if ( GlobalConfig->currentProfile->getUseDnsUpdate() ) + { + if ( ! backupResolvConf() ) + { + // if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Connect canceled because %1 could not be backuped." ).arg ( "/etc/resolv.conf" ), GlobalConfig->error ); + return ; + } + } + + // type selection + /* ============ vpnc ================ */ + if ( GlobalConfig->currentProfile != 0 && GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::cisco ) + { + + //setGuiStatus(connecting); + + // looking for vpnc + if ( Utils ( GlobalConfig ).getToolInfo ( "vpnc" )->found == false ) + { + KMessageBox::error ( this, i18n ( "Unable to find \"%1\" at \"%2\"!" ).arg ( "vpnc" ).arg ( GlobalConfig->pathToVpnc ) ); + GlobalConfig->appendLogEntry ( i18n ( "Unable to find \"%1\" at \"%2\"!" ).arg ( "vpnc" ).arg ( GlobalConfig->pathToVpnc ), GlobalConfig->error ); + ok = false; + setGuiStatus ( disconnected ); + return ; + } + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "vpnc: %1" ) .arg ( GlobalConfig->pathToVpnc ), GlobalConfig->debug ); + + + if ( !Utils ( GlobalConfig, parent ).tunDevExists() ) + { + if ( !Utils ( GlobalConfig, parent ).createTunDev() ) + { + KMessageBox::error ( this, i18n ( "Unable to create tunnel device file \"%1\"!" ).arg ( "/dev/net/tun" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Unable to create tunnel device file \"%1\"!" ).arg ( "/dev/net/tun" ), GlobalConfig->error ); + ok = false; + } + else + ok = true; + } + + GlobalConfig->TmpGatewayIP = Utils ( GlobalConfig, parent ).resolveName ( GlobalConfig->currentProfile->getGateway() ); + if ( GlobalConfig->TmpGatewayIP == "0.0.0.0" || GlobalConfig->TmpGatewayIP.isEmpty() ) + { + KMessageBox::error ( this, i18n ( "Host \"%1\" could not be resolved!" ).arg ( GlobalConfig->currentProfile->getGateway() ) ); + GlobalConfig->appendLogEntry ( i18n ( "Host \"%1\" could not be resolved!" ).arg ( GlobalConfig->currentProfile->getGateway() ), GlobalConfig->error ); + ok = false; + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "Gateway hostname (%1) resolved to \"%2\"." ).arg ( GlobalConfig->currentProfile->getGateway() ).arg ( GlobalConfig->TmpGatewayIP ), GlobalConfig->info ); + } + + // define 0.2.1 + int vpnc_version_major = 0; + int vpnc_version_minor = 2; + int vpnc_version_subminor = 1; + + ToolInfo *Tool = Utils ( GlobalConfig ).getToolInfo ( "vpnc" ); + if ( !Tool->Version.isEmpty() ) + { + vpnc_version_major = ( Tool->Version.section ( '.', 0, 0 ) ).toInt(); + vpnc_version_minor = ( Tool->Version.section ( '.', 1, 1 ) ).toInt(); + vpnc_version_subminor = ( Tool->Version.section ( '.', 2, 2 ) ).toInt(); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + { + GlobalConfig->appendLogEntry ( i18n ( "vpnc version (major): \"%1\"" ).arg ( vpnc_version_major ) , GlobalConfig->debug ); + GlobalConfig->appendLogEntry ( i18n ( "vpnc version (minor): \"%1\"" ).arg ( vpnc_version_minor ) , GlobalConfig->debug ); + GlobalConfig->appendLogEntry ( i18n ( "vpnc version (subminor): \"%1\"" ).arg ( vpnc_version_subminor ) , GlobalConfig->debug ); + } + } + + + if ( vpnc_version_minor < 3 ) + { + KMessageBox::error ( this, i18n ( "%1 is too old. Minimum requirement is %2" ).arg ( "vpnc" ).arg ( "0.3.x" ) ); + GlobalConfig->appendLogEntry ( i18n ( "%1 is too old. Minimum requirement is %2" ).arg ( "vpnc" ).arg ( "0.3.x" ), GlobalConfig->error ); + ok = false; + } + + if ( GlobalConfig->currentProfile->getID().isEmpty() ) + { + KMessageBox::error ( this, i18n ( "%1 is empty. Please go to profile settings and enter %2" ).arg ( i18n ( "VPN ID" ) ).arg ( i18n ( "VPN ID" ) ) ); + GlobalConfig->appendLogEntry ( i18n ( "%1 is empty. Please go to profile settings and enter %2" ).arg ( i18n ( "VPN ID" ) ).arg ( i18n ( "VPN ID" ) ), GlobalConfig->error ); + ok = false; + } + + if ( ok ) + { + bool askUsernamePass = false; + VpncDevice = "tun0"; + + if ( AuthRetry ) + askUsernamePass = true; + + bool requestUsername= false; + bool requestGroupPassword=true; + + if ( !GlobalConfig->haveUserData ) + { + if ( !GlobalConfig->currentProfile->getSavePsk() ) + askUsernamePass = true; + + if ( GlobalConfig->currentProfile->getAllowEmptyGroupPassword() && GlobalConfig->currentProfile->getPreSharedKey().isEmpty() ) + askUsernamePass = true; + + if ( GlobalConfig->currentProfile->getUserName().isEmpty() ) + askUsernamePass = true; + + if ( GlobalConfig->currentProfile->getUserPassword().isEmpty() ) + askUsernamePass = true; + + + + requestUsername = GlobalConfig->currentProfile->getUserPassword().isEmpty(); + if ( AuthRetry ) + { + askUsernamePass = true; + requestUsername = true; + } + + if ( GlobalConfig->currentProfile->getHideGroupPasswordInAccountDataDialog() ) + requestGroupPassword=false; + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 4 ) + GlobalConfig->appendLogEntry ( i18n ( "User data already collected." ), GlobalConfig->debug ); + } + + if ( GlobalConfig->currentProfile->getAskUserPasswordOnEachConnect() ) + { + if ( GlobalConfig->KvpncDebugLevel > 4 ) + GlobalConfig->appendLogEntry ( i18n ( "User password on each connect forced." ), GlobalConfig->debug ); + + askUsernamePass = true; + requestUsername = true; + } + + if ( askUsernamePass ) + { + EnterUsernamePasswordDialog dlg ( this, i18n ( "Enter Account Data" ), requestGroupPassword, requestUsername ); + + if ( !GlobalConfig->currentProfile->getUserName().isEmpty() ) + dlg.main->UsernameEdit->setText ( GlobalConfig->currentProfile->getUserName() ); + + if ( !GlobalConfig->currentProfile->getHideGroupPasswordInAccountDataDialog() ) + { + dlg.main->LabelGroupPassword->setText ( i18n ( "Enter group password:" ) ); + + if ( !GlobalConfig->currentProfile->getPreSharedKey().isEmpty() ) + { + dlg.main->PSKLineEdit->setText ( GlobalConfig->currentProfile->getPreSharedKey() ); + } + } + else + { + dlg.main->PSKLineEdit->hide(); + dlg.main->LabelGroupPassword->hide(); + dlg.main->PSKLineEdit->setText ( GlobalConfig->currentProfile->getPreSharedKey() ); + } + + if ( !GlobalConfig->currentProfile->getUserPassword().isEmpty() ) + dlg.main->PasswordEdit->setText ( GlobalConfig->currentProfile->getUserPassword() ); + + if ( !dlg.main->UsernameEdit->text().isEmpty() ) //go straight to pw if username present + { + if ( !GlobalConfig->currentProfile->getHideGroupPasswordInAccountDataDialog() ) + { + if ( !dlg.main->PSKLineEdit->text().isEmpty() ) + dlg.main->PasswordEdit->setFocus(); + else + dlg.main->PSKLineEdit->setFocus(); + } + else + dlg.main->PasswordEdit->setFocus(); + } + + if ( GlobalConfig->currentProfile->getSaveUserPassword() ) + dlg.main->SavePasswordCheckBox->setChecked ( true ); + else + dlg.main->SavePasswordCheckBox->setChecked ( false ); + + if ( !GlobalConfig->currentProfile->getDontSaveUsername() ) + dlg.main->SaveUsernameCheckBox->setChecked ( true ); + else + dlg.main->SaveUsernameCheckBox->setChecked ( false ); + + if ( GlobalConfig->currentProfile->getSavePsk() ) + dlg.main->SavePskCheckBox->setChecked ( true ); + else + dlg.main->SavePskCheckBox->setChecked ( false ); + + if ( dlg.exec() ) + { + GlobalConfig->TmpGroupPassword = dlg.main->PSKLineEdit->text(); + GlobalConfig->TmpUsername = dlg.main->UsernameEdit->text(); + GlobalConfig->TmpPassword = dlg.main->PasswordEdit->text(); + bool needSave=false; + + bool askGroupPass=false; + + if ( GlobalConfig->currentProfile->getHideGroupPasswordInAccountDataDialog() && GlobalConfig->currentProfile->getPreSharedKey().isEmpty() && !GlobalConfig->currentProfile->getAllowEmptyGroupPassword() ) + askGroupPass=true; + + if ( GlobalConfig->TmpGroupPassword.isEmpty() && !GlobalConfig->currentProfile->getAllowEmptyGroupPassword() || askGroupPass ) + { + GlobalConfig->appendLogEntry ( i18n ( "Group password is empty" ), GlobalConfig->error ); + ok = false; + } + + if ( requestUsername && GlobalConfig->currentProfile->getUserName().isEmpty() ) + { + GlobalConfig->appendLogEntry ( i18n ( "Username is empty!" ), GlobalConfig->error ); + ok = false; + } + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Some account data which is needed got from password enter dialog." ), GlobalConfig->debug ); + + if ( dlg.main->SaveUsernameCheckBox->isChecked() ) + { + GlobalConfig->currentProfile->setDontSaveUsername ( false ); + GlobalConfig->currentProfile->setUserName ( GlobalConfig->TmpUsername ); + needSave=true; + } + else + { + GlobalConfig->currentProfile->setDontSaveUsername ( true ); + needSave = true; + } + + if ( !GlobalConfig->currentProfile->getHideGroupPasswordInAccountDataDialog() ) + { + if ( dlg.main->SavePskCheckBox->isChecked() ) + { + GlobalConfig->currentProfile->setSavePsk ( true ); + GlobalConfig->currentProfile->setPreSharedKey ( GlobalConfig->TmpGroupPassword ); + needSave=true; + } + else + { + GlobalConfig->currentProfile->setSavePsk ( false ); + needSave = true; + } + } + else + { + GlobalConfig->TmpGroupPassword = GlobalConfig->currentProfile->getPreSharedKey(); + } + + if ( dlg.main->SavePasswordCheckBox->isChecked() ) + { + GlobalConfig->currentProfile->setSaveUserPassword ( true ); + GlobalConfig->currentProfile->setUserPassword ( GlobalConfig->TmpPassword ); + needSave=true; + } + else + { + GlobalConfig->currentProfile->setSaveUserPassword ( false ); + } + if ( needSave == true ) + GlobalConfig->saveOptions(true, GlobalConfig->currentProfile->getName()); + + GlobalConfig->haveUserData=true; + } + else + { + ok = false; + AuthRetry = false; + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Connect canceled because account data dialog aborted." ), GlobalConfig->debug ); + setGuiStatus ( disconnected ); + return; + } + } + else + { + GlobalConfig->TmpPassword= GlobalConfig->currentProfile->getUserPassword(); + GlobalConfig->TmpGroupPassword = GlobalConfig->currentProfile->getPreSharedKey(); + GlobalConfig->TmpUsername = GlobalConfig->currentProfile->getUserName(); + } + } + + + // here we go + if ( ok ) + { + if ( GlobalConfig->currentProfile->getExecuteCmdBeforeConnect() ) + executeCommandBeforeConnect(); + + tmpPath = locateLocal ( "data", "kvpnc/" ); + + QString tmpInterface; + QString LocalIP; + NetworkInterface iface ( GlobalConfig , parent ); + if ( GlobalConfig->currentProfile->getNetworkDevice() == "default" ) + { + tmpInterface = iface.getDefaultInterface(); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Default interface: \"%1\"." ).arg ( tmpInterface ) , GlobalConfig->debug ); + LocalIP = iface.getInterfaceIP ( iface.getDefaultInterface() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "IP address of default interface: \"%1\"." ).arg ( LocalIP ) , GlobalConfig->debug ); + } + else + { + tmpInterface = GlobalConfig->currentProfile->getNetworkDevice(); + LocalIP = iface.getInterfaceIP ( GlobalConfig->currentProfile->getNetworkDevice() ); + } + if ( tmpInterface.isEmpty() ) + { + tmpInterface = iface.getDefaultInterface(); + LocalIP = iface.getInterfaceIP ( iface.getDefaultInterface() ); + if ( tmpInterface.isEmpty() ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + { + GlobalConfig->appendLogEntry ( i18n ( "No default interface found, using \"lo\"." ), GlobalConfig->debug ); + tmpInterface = "lo"; // no default interface found :( + LocalIP = "127.0.0.1"; + } + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "No default interface given, tried default interface, got success, using \"%1\"." ).arg ( tmpInterface ), GlobalConfig->debug ); + } + } + + if ( LocalIP.isEmpty() ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "No IP for default interface found, using \"127.0.0.1\"." ), GlobalConfig->debug ); + LocalIP = "127.0.0.1"; // no IP for default interface found :( + } + + // QString tunneldevice = "tun0"; + OldDefaultroute = tmpPath + "default-route." + GlobalConfig->currentProfile->getName(); // default-route. + +// QFile DefaultRouteBackupFile(OldDefaultroute + ".sh"); +// QTextStream DefaultRouteBackupFileStream(&DefaultRouteBackupFile); +// if (DefaultRouteBackupFile.open(QIODevice::WriteOnly)) { +// DefaultRouteBackupFileStream << "# generated by kvpnc. Do not edit it." << "\n"; +// DefaultRouteBackupFileStream << "\n"; +// DefaultRouteBackupFileStream << GlobalConfig->pathToIp + " route show | grep default > " + OldDefaultroute + "\n"; +// DefaultRouteBackupFile.close(); +// QProcess backupDefaultRouteProcess(this); +// QString proc = GlobalConfig->InterpreterShell; +// QStringList args; +// backupDefaultRouteProcess.setEnvironment(*env); +// args.append(OldDefaultroute + ".sh"); +// backupDefaultRouteProcess.setEnvironment(*env); +// backupDefaultRouteProcess.start(proc,args); +// if (!backupDefaultRouteProcess.waitForStarted()) { +// // if ( GlobalConfig->KvpncDebugLevel > 0 ) +// GlobalConfig->appendLogEntry(i18n("Connect canceled because default route backup process could not be started."), KVpncEnum::error); +// return ; +// } else { +// if (GlobalConfig->KvpncDebugLevel > 2) +// GlobalConfig->appendLogEntry(i18n("Default route backup process started."), KVpncEnum::debug); +// backupDefaultRouteProcess.waitForFinished(); +// +// } +// } else { +// // if ( GlobalConfig->KvpncDebugLevel > 0 ) +// GlobalConfig->appendLogEntry(i18n("Connect canceled because a backup of the default route could not be created."), KVpncEnum::error); +// return ; +// } + backupDefaultRoute(); + + VpncGateway = tmpPath + "gateway." + GlobalConfig->currentProfile->getName(); // gateway. + VpncConnectScript = tmpPath + "vpnc-connect." + GlobalConfig->currentProfile->getName() + ".sh"; // vpnc-connect..sh + GlobalConfig->Vpnc_pid_file = tmpPath + "vpnc-pid." + GlobalConfig->currentProfile->getName() + ".pid"; // vpnc-pid..pid + + // write vpnc connect script + VpncScript = tmpPath + "vpnc-script." + GlobalConfig->currentProfile->getName(); // vpnc-script. + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "VpncScript: " + VpncScript + "\n", GlobalConfig->debug ); + QFile file ( VpncScript ); + QTextStream stream ( &file ); + if ( file.open ( IO_WriteOnly ) ) + { + stream << "#!"<< GlobalConfig->InterpreterShell << "\n"; + stream << "#* reason -- why this script was called, one of: pre-init connect disconnect\n"; + stream << "#* VPNGATEWAY -- vpn gateway address (always present)\n"; + stream << "#* TUNDEV -- tunnel device (always present)\n"; + stream << "#* INTERNAL_IP4_ADDRESS -- address (always present)\n"; + stream << "#* INTERNAL_IP4_NETMASK -- netmask (often unset)\n"; + stream << "#* INTERNAL_IP4_DNS -- list of dns serverss\n"; + stream << "#* INTERNAL_IP4_NBNS -- list of wins servers\n"; + stream << "#* CISCO_DEF_DOMAIN -- default domain name\n"; + stream << "#* CISCO_BANNER -- banner from server\n"; + stream << "#* CISCO_SPLIT_INC -- number of networks in split-network-list\n"; + stream << "#* CISCO_SPLIT_INC_%d_ADDR -- network address\n"; + stream << "#* CISCO_SPLIT_INC_%d_MASK -- subnet mask (for example: 255.255.255.0)\n"; + stream << "#* CISCO_SPLIT_INC_%d_MASKLEN -- subnet masklen (for example: 24)\n"; + stream << "#* CISCO_SPLIT_INC_%d_PROTOCOL -- protocol (often just 0)\n"; + stream << "#* CISCO_SPLIT_INC_%d_SPORT -- source port (often just 0)\n"; + stream << "#* CISCO_SPLIT_INC_%d_DPORT -- destination port (often just 0)\n"; + stream << "\n"; + stream << "#set -x\n"; + stream << "\n"; + stream << "OS=\"`uname -s`\"\n"; + stream << "DEFAULT_ROUTE_FILE=/var/run/vpnc/defaultroute\n"; + stream << "RESOLV_CONF_BACKUP=" + tmpPath + "resolv.conf.before.kvpnc_" + GlobalConfig->currentProfile->getName() + "\n"; + stream << "\n"; + stream << "IPROUTE=" + GlobalConfig->pathToIp + "\n"; + stream << "\n"; + stream << "if [ \"$OS\" = \"Linux\" ]; then\n"; + stream << " ifconfig_syntax_ptp=\"pointopoint\"\n"; + stream << " route_syntax_gw=\"gw\"\n"; + stream << " route_syntax_del=\"del\"\n"; + stream << " route_syntax_netmask=\"netmask\"\n"; + stream << "else\n"; + stream << " ifconfig_syntax_ptp=\"\"\n"; + stream << " route_syntax_gw=\"\"\n"; + stream << " route_syntax_del=\"delete\"\n"; + stream << " route_syntax_netmask=\"-netmask\"\n"; + stream << "fi\n"; + stream << "\n"; + stream << "####\n"; + stream << "\n"; + stream << "kernel_is_2_6_or_above()\n"; + stream << "{\n"; + stream << " case \"$(uname -r)\" in\n"; + stream << " 1.*|2.[012345]*) return 1 ;;\n"; + stream << " *) return 0 ;;\n"; + stream << " esac\n"; + stream << "}\n"; + stream << "\n"; + stream << "udev_is_active()\n"; + stream << "{\n"; + stream << " test -e /dev/.udev.tdb || test -d /dev/.udevdb || return 1\n"; + stream << " kernel_is_2_6_or_above || return 1\n"; + stream << " return 0\n"; + stream << "}\n"; + stream << "\n"; + stream << "\n"; + stream << "do_pre_init() {\n"; + stream << " if [ \"$OS\" = \"Linux\" ]; then\n"; + stream << " if (exec 6<> /dev/net/tun) > /dev/null 2>&1 ; then\n"; + stream << " :\n"; + stream << " else # can't open /dev/net/tun\n"; + stream << " test -e /proc/sys/kernel/modprobe && `cat /proc/sys/kernel/modprobe` tun 2>/dev/null\n"; + stream << " # fix for broken devfs in kernel 2.6.x\n"; + stream << " if [ \"`readlink /dev/net/tun`\" = misc/net/tun \\\n"; + stream << " -a ! -e /dev/net/misc/net/tun -a -e /dev/misc/net/tun ] ; then\n"; + stream << " ln -sf /dev/misc/net/tun /dev/net/tun\n"; + stream << " fi\n"; + stream << " # make sure tun device exists\n"; + stream << " if [ ! -e /dev/net/tun ]; then\n"; + stream << " mkdir -p /dev/net\n"; + stream << " mknod -m 0640 /dev/net/tun c 10 200\n"; + stream << " fi\n"; + stream << "\n"; + stream << " # workaround for a possible latency caused by udev, sleep max. 10s\n"; + stream << " if udev_is_active ; then\n"; + stream << " for x in `seq 100` ; do\n"; + stream << " (exec 6<> /dev/net/tun) > /dev/null 2>&1 && break;\n"; + stream << " sleep 0.1\n"; + stream << " done\n"; + stream << " fi\n"; + stream << " fi\n"; + stream << " elif [ \"$OS\" = \"FreeBSD\" ]; then\n"; + stream << " if [ ! -e /dev/tun ]; then\n"; + stream << " kldload if_tun\n"; + stream << " fi\n"; + stream << " elif [ \"$OS\" = \"NetBSD\" ]; then\n"; + stream << " :\n"; + stream << " elif [ \"$OS\" = \"OpenBSD\" ]; then\n"; + stream << " :\n"; + stream << " elif [ \"$OS\" = \"SunOS\" ]; then\n"; + stream << " :\n"; + stream << " fi\n"; + stream << "}\n"; + stream << "\n"; + stream << "do_ifconfig() {\n"; + if ( GlobalConfig->currentProfile->getUseMtu() ) + stream << GlobalConfig->pathToIfconfig + " \"$TUNDEV\" inet \"$INTERNAL_IP4_ADDRESS\" $ifconfig_syntax_ptp \"$INTERNAL_IP4_ADDRESS\" netmask 255.255.255.255 mtu " + QString().setNum ( GlobalConfig->currentProfile->getMtu() ) + " up\n"; + else + stream << GlobalConfig->pathToIfconfig + " \"$TUNDEV\" inet \"$INTERNAL_IP4_ADDRESS\" $ifconfig_syntax_ptp \"$INTERNAL_IP4_ADDRESS\" netmask 255.255.255.255 mtu 1390 up\n"; + stream << "}\n"; + stream << "\n"; + stream << "if [ -n \"$IPROUTE\" ]; then\n"; + stream << " fix_ip_get_output () {\n"; +// stream << " sed 's/cache//;s/metric \\?[0-9]\\+ [0-9]\\+//g'\n"; // (works on etch) + stream << " sed 's/cache//;s/metric[ 0-9]\\+//g;s/hoplimit[ 0-9]\\+//g'" << "\n"; // sed 's/cache//;s/metric[ 0-9]\+//g;s/hoplimit[ 0-9]\+//g' (works on fc6) + stream << " }\n"; + stream << "\n"; + stream << " set_vpngateway_route() {\n"; + stream << " $IPROUTE route add `" + GlobalConfig->pathToIp + " route get \"$VPNGATEWAY\" | fix_ip_get_output`\n"; + stream << " $IPROUTE route flush cache\n"; + stream << " }\n"; + stream << " \n"; + stream << " del_vpngateway_route() {\n"; + stream << " $IPROUTE route del \"$VPNGATEWAY\"\n"; + stream << " $IPROUTE route flush cache\n"; + stream << " }\n"; + stream << " \n"; + stream << " set_default_route() {\n"; + if ( GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + { + stream << " mkdir -p /var/run/vpnc\n"; + stream << " $IPROUTE route | grep '^default' | fix_ip_get_output > \"$DEFAULT_ROUTE_FILE\"\n"; + stream << " $IPROUTE route del default\n"; + stream << " $IPROUTE route add default dev \"$TUNDEV\"\n"; + stream << " $IPROUTE route flush cache\n"; + } + else + { + stream << " echo \"\"\n"; + } + stream << " }\n"; + stream << " \n"; + stream << " set_network_route() {\n"; + stream << " NETWORK=\"$1\"\n"; + stream << " NETMASK=\"$2\"\n"; + stream << " NETMASKLEN=\"$3\"\n"; + stream << " $IPROUTE route add \"$NETWORK/$NETMASKLEN\" dev \"$TUNDEV\"\n"; + stream << " $IPROUTE route flush cache\n"; + stream << " }\n"; + stream << " \n"; + stream << " reset_default_route() {\n"; + stream << " $IPROUTE route del default > /dev/null 2>&1\n"; + stream << " $IPROUTE route add `cat \"$DEFAULT_ROUTE_FILE\"`\n"; + stream << " $IPROUTE route flush cache\n"; + stream << " }\n"; + stream << " \n"; + stream << " del_network_route() {\n"; +// if ( !GlobalConfig->currentProfile->getKeepDefaultRoute() ) +// { +// stream << " # linux deletes routes automatically if the device is shut down\n"; +// stream << " return\n"; +// } + stream << " #NETWORK=\"$1\"\n"; + stream << " #NETMASK=\"$2\"\n"; + stream << " #NETMASKLEN=\"$3\"\n"; + if ( GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + stream << " #$IPROUTE route del \"$NETWORK/$NETMASKLEN\" dev \"$TUNDEV\" \n"; + else + stream << " #$IPROUTE route del \"$NETWORK/$NETMASKLEN\" dev \"" + tmpInterface + "\"\n"; + stream << " #$IPROUTE route flush cache\n"; + stream << " # linux deletes routes automatically if the device is shut down\n"; + stream << " echo \"\"\n"; + stream << " }\n"; + stream << "else\n"; + stream << " get_default_gw() {\n"; + stream << " # solaris again ...\n"; + stream << " netstat -r -n | sed 's/default/0.0.0.0/' | grep '^0.0.0.0' | awk '{print $2}'\n"; + stream << " }\n"; + stream << " \n"; + stream << " set_vpngateway_route() {\n"; + stream << " " + GlobalConfig->pathToRoute + " add -host \"$VPNGATEWAY\" $route_syntax_gw \"`get_default_gw`\"\n"; + stream << " }\n"; + stream << "\n"; + stream << " del_vpngateway_route() {\n"; + stream << " " + GlobalConfig->pathToRoute + " $route_syntax_del -host \"$VPNGATEWAY\"\n"; + stream << " }\n"; + stream << " \n"; + stream << " set_default_route() {\n"; + if ( GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + { + stream << " DEFAULTGW=\"`get_default_gw`\"\n"; + stream << " echo \"$DEFAULTGW\" > \"$DEFAULT_ROUTE_FILE\"\n"; + stream << " route $route_syntax_del default \"$DEFAULTGW\"\n"; + stream << " route add default $route_syntax_gw \"$INTERNAL_IP4_ADDRESS\"\n"; + } + else + { + stream << " echo \"\"\n"; + } + stream << " }\n"; + stream << " \n"; + stream << " set_network_route() {\n"; + stream << " NETWORK=\"$1\"\n"; + stream << " NETMASK=\"$2\"\n"; + stream << " NETMASKLEN=\"$3\"\n"; + stream << " route add -net \"$NETWORK\" $route_syntax_netmask \"$NETMASK\" $route_syntax_gw \"$INTERNAL_IP4_ADDRESS\"\n"; + stream << " }\n"; + stream << " \n"; + stream << " reset_default_route() {\n"; + if ( GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + { + stream << " route $route_syntax_del default\n"; + stream << " route add default $route_syntax_gw `cat \"$DEFAULT_ROUTE_FILE\"`\n"; + } + else + { + stream << " echo \"\"\n"; + } + stream << " }\n"; + stream << " \n"; + stream << " del_network_route() {\n"; + stream << " if [ \"$OS\" = \"Linux\" ]; then\n"; + stream << " # linux deletes routes automatically if the device is shut down\n"; + stream << " return\n"; + stream << " fi\n"; + stream << " NETWORK=\"$1\"\n"; + stream << " NETMASK=\"$2\"\n"; + stream << " NETMASKLEN=\"$3\"\n"; + stream << " route $route_syntax_del -net \"$NETWORK\" $route_syntax_netmask \"$NETMASK\" $route_syntax_gw \"$INTERNAL_IP4_ADDRESS\"\n"; + stream << " }\n"; + stream << "fi\n"; + stream << "\n"; + stream << "write_resolvconf() {\n"; + stream << "\n"; + + /* update dns? */ + if ( GlobalConfig->currentProfile->getUseDnsUpdate() ) + { + stream << " cat /etc/resolv.conf > " + tmpPath + "resolv.conf.before.kvpnc_" + GlobalConfig->currentProfile->getName() + "\n"; + stream << " if [ -f /sbin/resolvconf ] ; then\n"; + stream << " mkdir -p /var/run/vpnc\n"; + stream << " ( \n"; + stream << " if [ \"$CISCO_DEF_DOMAIN\" ] ; then\n"; + stream << " echo domain \"$CISCO_DEF_DOMAIN\"\n"; + stream << " echo search \"$CISCO_DEF_DOMAIN\"\n"; + stream << " fi\n"; + stream << " nameserver_found=0\n"; + stream << " for ip in \"$INTERNAL_IP4_DNS\" ; do\n"; + stream << " echo nameserver $ip\n"; + stream << " nameserver_found=1\n"; + stream << " done\n"; + stream << " if [ \"$nameserver_found\" = \"0\" ]; then" << "\n"; + stream << " echo \"# old nameserver\"\n"; + stream << " cat "+tmpPath + "/resolv.conf.before.kvpnc_" + GlobalConfig->currentProfile->getName() +" | grep nameserver\n"; + stream << " fi" << "\n"; + stream << " ) > /var/run/vpnc/resolvconf\n"; + stream << " cat /var/run/vpnc/resolvconf | /sbin/resolvconf -a $TUNDEV\n"; + + /* crissi: -u seems not nessesary */ + //stream << " cat /var/run/vpnc/resolvconf | /sbin/resolvconf -u\n"; + + stream << " return\n"; + stream << " fi\n"; + stream << "\n"; + stream << " grep '^#@VPNC_GENERATED@' /etc/resolv.conf > /dev/null 2>&1 || cp -- /etc/resolv.conf \"$RESOLV_CONF_BACKUP\"\n"; + stream << " NEW_RESOLVCONF=\"#@VPNC_GENERATED@ -- this file is generated by vpnc\n"; + stream << "# and will be overwritten by vpnc\n"; + stream << "# as long as the above mark is intact\"\n"; + stream << " \n"; + stream << " exec 6< /etc/resolv.conf\n"; + stream << " while read LINE <&6 ; do\n"; + stream << " case \"$LINE\" in\n"; + stream << " nameserver*)\n"; + stream << " if [ -n \"$INTERNAL_IP4_DNS\" ]; then\n"; + stream << " read ONE_NAMESERVER INTERNAL_IP4_DNS <<-EOF\n"; + stream << " $INTERNAL_IP4_DNS\n"; + stream << "EOF\n"; + stream << " LINE=\"nameserver $ONE_NAMESERVER\"\n"; + stream << " else\n"; + stream << " LINE=""\n"; + stream << " fi\n"; + stream << " ;;\n"; + stream << " domain*|search*)\n"; + stream << " if [ -n \"$CISCO_DEF_DOMAIN\" ]; then\n"; + stream << " LINE=\"$LINE $CISCO_DEF_DOMAIN\"\n"; + stream << " CISCO_DEF_DOMAIN=""\n"; + stream << " fi\n"; + stream << " ;;\n"; + stream << " esac\n"; + stream << " NEW_RESOLVCONF=\"$NEW_RESOLVCONF\n"; + stream << "$LINE\"\n"; + stream << " done\n"; + stream << " exec 6<&-\n"; + stream << " \n"; + stream << " for i in $INTERNAL_IP4_DNS ; do\n"; + stream << " NEW_RESOLVCONF=\"$NEW_RESOLVCONF\n"; + stream << "nameserver $i\"\n"; + stream << " done\n"; + stream << " if [ -n \"$CISCO_DEF_DOMAIN\" ]; then\n"; + stream << " NEW_RESOLVCONF=\"$NEW_RESOLVCONF\n"; + stream << "search $CISCO_DEF_DOMAIN\"\n"; + stream << " fi\n"; + stream << " echo \"$NEW_RESOLVCONF\" > /etc/resolv.conf\n"; + + } + else + { + /* dont update dns */ + setenv ( "DNS_UPDATE", "NO",1 ); + stream << " return\n"; + } + stream << "}\n"; + stream << "\n"; + stream << "reset_resolvconf() {\n"; + stream << "\n"; + + /* update dns? */ + if ( GlobalConfig->currentProfile->getUseDnsUpdate() ) + { +// stream << " case \"$DNS_UPDATE\" in\n"; +// stream << " *no|*NO|*No|*nO)\n"; +// stream << " return\n"; +// stream << " ;;\n"; +// stream << " esac\n"; +// stream << "\n"; + stream << " if [ -f /sbin/resolvconf ] ; then\n"; + stream << " /sbin/resolvconf -d \"$TUNDEV\"\n"; + stream << " return\n"; + stream << " else\n"; + stream << " cat " + tmpPath + "resolv.conf.before.kvpnc_" + GlobalConfig->currentProfile->getName() + " > /etc/resolv.conf\n"; + stream << " fi\n"; + } + else + { + + /* dont update dns */ + setenv ( "DNS_UPDATE", "NO",1 ); + stream << " return\n"; + } + stream << "}\n"; + stream << "\n"; + stream << "do_connect() {\n"; + stream << " # Debian specific, insert your code there to avoid modification of\n"; + stream << " # conffiles like this script\n"; + stream << " if [ -r /etc/vpnc/vpnc-script-connect-action ] ; then\n"; + stream << " . /etc/vpnc/vpnc-script-connect-action\n"; + stream << " fi\n"; + stream << " if [ -n \"$CISCO_BANNER\" ]; then\n"; + stream << " echo \"Connect Banner:\"\n"; + stream << " echo \"$CISCO_BANNER\" | while read LINE ; do echo \"|\" \"$LINE\" ; done\n"; + stream << " echo\n"; + stream << " fi\n"; + stream << " \n"; + stream << " do_ifconfig\n"; + stream << " set_vpngateway_route\n"; + stream << "\n"; + stream << " # -- Debian specific\n"; + stream << " if test \"$TARGET_NETWORKS\" ; then\n"; + stream << " for network in $TARGET_NETWORKS ; do\n"; + stream << " " + GlobalConfig->pathToIp + " route del $network 2>/dev/null\n"; + stream << " " + GlobalConfig->pathToIp + " route add $network dev $TUNDEV\n"; + stream << " done\n"; + stream << " else\n"; + stream << "\n"; + stream << " if [ -n \"$CISCO_SPLIT_INC\" ]; then\n"; + stream << " i=0\n"; + stream << " while [ $i -lt $CISCO_SPLIT_INC ] ; do\n"; + stream << " eval NETWORK=\"\\${CISCO_SPLIT_INC_${i}_ADDR}\"\n"; + stream << " eval NETMASK=\"\\${CISCO_SPLIT_INC_${i}_MASK}\"\n"; + stream << " eval NETMASKLEN=\"\\${CISCO_SPLIT_INC_${i}_MASKLEN}\"\n"; + stream << " set_network_route \"$NETWORK\" \"$NETMASK\" \"$NETMASKLEN\"\n"; + stream << " i=`expr $i + 1`\n"; + stream << " done\n"; + stream << " for i in $INTERNAL_IP4_DNS ; do\n"; + stream << " set_network_route \"$i\" \"255.255.255.255\" \"32\"\n"; + stream << " done\n"; + stream << " else\n"; + stream << " set_default_route\n"; + stream << " fi\n"; + stream << "\n"; + stream << " fi\n"; + stream << " \n"; + stream << " if [ -n \"$INTERNAL_IP4_DNS\" ]; then\n"; + stream << " write_resolvconf\n"; + stream << " fi\n"; + stream << "}\n"; + stream << "\n"; + stream << "do_disconnect() {\n"; + stream << " # Debian specific, insert your code there to avoid modification of\n"; + stream << " # conffiles like this script\n"; + stream << " if [ -r /etc/vpnc/vpnc-script-disconnect-action ] ; then\n"; + stream << " . /etc/vpnc/vpnc-script-disconnect-action\n"; + stream << " fi\n"; + stream << " if [ -n \"$CISCO_SPLIT_INC\" ]; then\n"; + stream << " i=0\n"; + stream << " while [ $i -lt $CISCO_SPLIT_INC ] ; do\n"; + stream << " eval NETWORK=\"\\${CISCO_SPLIT_INC_${i}_ADDR}\"\n"; + stream << " eval NETMASK=\"\\${CISCO_SPLIT_INC_${i}_MASK}\"\n"; + stream << " eval NETMASKLEN=\"\\${CISCO_SPLIT_INC_${i}_MASKLEN}\"\n"; + stream << " del_network_route \"$NETWORK\" \"$NETMASK\" \"$NETMASKLEN\"\n"; + stream << " i=`expr $i + 1`\n"; + stream << " done\n"; + stream << " for i in $INTERNAL_IP4_DNS ; do\n"; + stream << " del_network_route \"$i\" \"255.255.255.255\" \"32\"\n"; + stream << " done\n"; + stream << " else\n"; + stream << " if [ -s \"$DEFAULT_ROUTE_FILE\" ]; then\n"; + stream << " reset_default_route\n"; + stream << " rm -f -- \"$DEFAULT_ROUTE_FILE\"\n"; + stream << " fi\n"; + stream << " fi\n"; + stream << " \n"; + stream << " del_vpngateway_route\n"; + stream << " \n"; + stream << " if [ -n \"$INTERNAL_IP4_DNS\" ]; then\n"; + stream << " reset_resolvconf\n"; + stream << " fi\n"; + stream << "}\n"; + stream << "\n"; + stream << "####\n"; + stream << "\n"; + stream << "if [ -z \"$reason\" ]; then\n"; + stream << " echo \"this script must be called from vpnc\" 1>&2\n"; + stream << " exit 1\n"; + stream << "fi\n"; + stream << "\n"; + //stream << " echo \"vpn reason: $reason\" >> /tmp/a.txt\n"; + stream << "case \"$reason\" in\n"; + stream << " pre-init)\n"; + stream << " do_pre_init\n"; + stream << " ;;\n"; + stream << " connect)\n"; + stream << " do_connect\n"; + stream << " ;;\n"; + stream << " disconnect)\n"; + stream << " do_disconnect\n"; + stream << " ;;\n"; + stream << " *)\n"; + stream << " echo \"unknown reason '$reason'. Maybe vpnc-script is out of date\" 1>&2\n"; + stream << " exit 1\n"; + stream << " ;;\n"; + stream << "esac\n"; + stream << "\n"; + stream << "exit 0\n"; + file.close(); + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Writing VpncScript finished." ), GlobalConfig->debug ); + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "Creating %1 has been failed." ).arg ( QString ( "VpncScript" ) ), GlobalConfig->error ); + setGuiStatus ( disconnected ); + timer.stop(); + return ; + } + + if ( Utils ( GlobalConfig ).doChmod ( VpncScript, "+x" ) ) + { + + //sleep ( 1 ); + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Checking tun device support" ), GlobalConfig->debug ); + + //if ( !NetworkInterface ( GlobalConfig, parent, this ).interfaceExist ( "tun0" ) ) //FIXME make it dynamiclly (tun+) + { + QFile tundevfile ( "/dev/net/tun" ); + if ( !tundevfile.exists() ) + { + if ( !Utils ( GlobalConfig, parent ).createTunDev() ) + { + KMessageBox::error ( this, i18n ( "Creating of \"%1\" has been failed!" ).arg ( "/dev/net/tun" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Tunnel device is missing, creating has been failed: stop." ), GlobalConfig->error ); + disconnectClicked(); + setGuiStatus ( disconnected ); + GlobalConfig->status = GlobalConfig->disconnected; + return ; + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Tunnel device is missing, creating has been succeded." ), GlobalConfig->debug ); + } + } + // load the module 'tun' + + + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Checking tun support" ), GlobalConfig->debug ); + bool tunsupportfound = false; + QString procmisc = ""; + QFile f ( "/proc/misc" ); + if ( f.open ( IO_ReadOnly ) ) + { + QTextStream procmiscstream ( &f ); + QString procmiscontent = QString(procmiscstream.read()); + QStringList procmisc_content_list = QStringList::split("\n", procmiscontent); + QString line = ""; + for ( QStringList::Iterator it = procmisc_content_list.begin(); it != procmisc_content_list.end(); ++it ) + { + line = *it; // line of text excluding '\n' + if ( line.contains ( "tun", false ) ) + { + tunsupportfound = true; + break; + } + } + f.close(); + } + if ( tunsupportfound ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Support for TUN/TAP found (compiled into kernel or kernel module already loaded)." ), GlobalConfig->debug ); + } + else + { + if ( !Utils ( GlobalConfig, parent ).loadKernelModule ( "tun", parent ) ) + { + KMessageBox::information ( this, i18n ( "Loading of module \"%1\" failed!" ).arg ( "tun" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Tunnel device is missing, loading module \"%1\" has failed: stop." ).arg ( "tun" ), GlobalConfig->error ); + disconnectClicked(); + setGuiStatus ( disconnected ); + GlobalConfig->status = GlobalConfig->disconnected; + return ; + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Loading of module \"%1\" was successful." ).arg ( "tun" ), GlobalConfig->debug ); + } + } + } + + + + QString vpncConfig = ""; + vpncConfig += "IPSec gateway " + GlobalConfig->TmpGatewayIP + "\n"; + vpncConfig += "IPSec ID " + GlobalConfig->currentProfile->getID() + "\n"; + QString GrpPassStr = ""; + if ( !GlobalConfig->currentProfile->getSavePsk() || AuthRetry ) + GrpPassStr = GlobalConfig->TmpGroupPassword; + else + GrpPassStr = GlobalConfig->currentProfile->getPreSharedKey(); + vpncConfig += "IPSec secret " + GrpPassStr + "\n"; + vpncConfig += "Xauth username " + GlobalConfig->TmpUsername + "\n"; + + if ( ( vpnc_version_minor == 3 && vpnc_version_minor >= 2 ) || ( vpnc_version_minor > 3 ) ) + vpncConfig += "Xauth password " + GlobalConfig->TmpPassword + "\n"; + + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::psk ) + { + + } + else if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::cert ) + { + + } + else if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::hybrid ) + { + vpncConfig += QString("IKE Authmode")+ " " + "hybrid" + "\n"; + if ( !GlobalConfig->currentProfile->getCaCertificate().isEmpty() ) + { + vpncConfig += QString( "CA-File " + GlobalConfig->currentProfile->getCaCertificate() + "\n"); + } + if ( !GlobalConfig->currentProfile->getCertPath().isEmpty() ) + { + vpncConfig += QString("CA-Dir " + GlobalConfig->currentProfile->getCertPath() + "\n"); + } + } + + + if ( GlobalConfig->KvpncDebugLevel > 3 ) + { + QStringList vpncConfigLineList = QStringList::split ( '\n', vpncConfig ); + //GlobalConfig->appendLogEntry ( i18n ( "start\n" ), GlobalConfig->debug ); + for ( QStringList::Iterator it = vpncConfigLineList.begin(); it != vpncConfigLineList.end(); ++it ) + { + QString configstring = *it; + if ( configstring.find ( "Xauth password",0 ) > -1 ) + configstring = "Xauth password ******"; + if ( configstring.find ( "IPSec secret",0 ) > -1 ) + configstring = "IPSec secret ******"; + + GlobalConfig->appendLogEntry ( i18n ( "vpnconfig: %1" ).arg ( configstring ), GlobalConfig->debug ); + //GlobalConfig->appendLogEntry ( i18n ( "end" ).arg ( vpncConfig ), GlobalConfig->debug ); + } + } + + QString VpncConfigFile = tmpPath + "vpnc-config." + GlobalConfig->currentProfile->getName(); // vpnc-config. + if ( vpnc_version_major <= 0 && vpnc_version_minor <= 3 && vpnc_version_subminor <= 2 ) + { + // write vpnc connect script + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( "VpncConfig: " + VpncConfigFile + "\n", GlobalConfig->debug ); + QFile configfile ( VpncConfigFile ); + QTextStream configstream ( &configfile ); + if ( configfile.open ( IO_WriteOnly ) ) + { + configstream << vpncConfig << "\n"; + configfile.close(); + } + else + { + KMessageBox::information ( this, i18n ( "Write of \"%1\" has been failed!" ).arg ( VpncConfigFile ) ); + GlobalConfig->appendLogEntry ( i18n ( "Write of \"%1\" has been failed!" ).arg ( VpncConfigFile ), GlobalConfig->error ); + disconnectClicked(); + setGuiStatus ( disconnected ); + GlobalConfig->status = GlobalConfig->disconnected; + return ; + } + + } + + VpncProcess = new QProcess ( this ); + VpncProcess->setCommunication ( QProcess::Stdin | QProcess::Stdout | QProcess::Stderr | QProcess::DupStderr ); + connect ( VpncProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readOutputFrom_vpnc() ) ); + + + VpncProcess->addArgument ( GlobalConfig->pathToVpnc ); + VpncProcess->addArgument ( "--script" ); + VpncProcess->addArgument ( VpncScript ); + + if ( vpnc_version_major <= 0 && vpnc_version_minor <= 3 && vpnc_version_subminor <= 2 ) + { +// VpncProcess->addArgument ( "--gateway" ); +// VpncProcess->addArgument ( GlobalConfig->TmpGatewayIP ); +// VpncProcess->addArgument ( "--id" ); +// VpncProcess->addArgument ( GlobalConfig->currentProfile->getID() ); + VpncProcess->addArgument ( VpncConfigFile ); + } + + if ( GlobalConfig->VpncDebugLevel > 0 ) + { + + VpncProcess->addArgument ( "--debug" ); + VpncProcess->addArgument ( QString().setNum ( GlobalConfig->VpncDebugLevel ) ); + } + VpncProcess->addArgument ( "--pid-file" ); + VpncProcess->addArgument ( GlobalConfig->Vpnc_pid_file ); + + //if ( ( vpnc_version_minor == 3 && vpnc_version_subminor >= 3 ) || ( vpnc_version_minor >= 3 && vpnc_version_minor >= 3 && vpnc_version_subminor >= 3 ) ) + // VpncProcess->addArgument ( "--non-inter" ); + +// // these options now set via config file +// if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::psk ) +// { +// +// } +// else if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::cert ) +// { +// +// } +// else if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::hybrid ) +// { +// VpncProcess->addArgument ( "--hybrid" ); +// VpncProcess->addArgument ( "---ca-file" ); +// VpncProcess->addArgument ( GlobalConfig->currentProfile->getCaCertificate() ); +// +// VpncProcess->addArgument ( "--ca-dir" ); +// VpncProcess->addArgument ( GlobalConfig->currentProfile->getCertPath() ); +// } + + if ( GlobalConfig->currentProfile->getUseNtDomainName() ) + { + VpncProcess->addArgument ( "--domain" ); + VpncProcess->addArgument ( GlobalConfig->currentProfile->getNtDomainName() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Using (NT) domain name \"%1\"." ).arg ( GlobalConfig->currentProfile->getNtDomainName() ), GlobalConfig->debug ); + } + + if ( GlobalConfig->currentProfile->getUseNat() && GlobalConfig->currentProfile->getCiscoNatMode() != "none" ) + { + if ( vpnc_version_major >= 0 && vpnc_version_minor >= 4 ) + { + // TODO add other nat modes + VpncProcess->addArgument ( "--natt-mode" ); + VpncProcess->addArgument ( GlobalConfig->currentProfile->getCiscoNatMode() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Using NAT-T mode \"%1\"." ).arg ( GlobalConfig->currentProfile->getCiscoNatMode() ), GlobalConfig->debug ); + } + else + VpncProcess->addArgument ( "--udp" ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Using UDP." ), GlobalConfig->debug ); + } + else + { + if ( ( vpnc_version_major == 0 && vpnc_version_minor >= 4 ) || ( vpnc_version_major >= 1 ) ) + { + VpncProcess->addArgument ( "--natt-mode" ); + VpncProcess->addArgument ( "none" ); + } + else + { + VpncProcess->addArgument ( "--disable-natt" ); + } + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Disabling NAT-T." ), GlobalConfig->debug ); + } + + if ( GlobalConfig->currentProfile->getUseLocalPort() == true ) + { + VpncProcess->addArgument ( "--local-port" ); + VpncProcess->addArgument ( QString().setNum ( GlobalConfig->currentProfile->getLocalPort() ) ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Using userdefined local port \"%1\"." ).arg ( QString().setNum ( GlobalConfig->currentProfile->getLocalPort() ) ), GlobalConfig->debug ); + } + + + if ( GlobalConfig->currentProfile->getUseUdpPort() ) + { + VpncProcess->addArgument ( "--udp-port" ); + VpncProcess->addArgument ( QString().setNum ( GlobalConfig->currentProfile->getUdpPort() ) ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Using userdefined UDP port \"%1\"." ).arg ( GlobalConfig->currentProfile->getUdpPort() ), GlobalConfig->debug ); + } + + + if ( GlobalConfig->currentProfile->getUseXauthInteractive() && ( ( vpnc_version_minor == 3 && vpnc_version_minor >= 2 ) || ( vpnc_version_minor > 3 ) ) ) + { + VpncProcess->addArgument ( "--xauth-inter" ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Enabling interactive extended authentication (for challange response auth)" ), GlobalConfig->debug ); + } + + if ( GlobalConfig->currentProfile->getUseApplicationVersion() ) + { + VpncProcess->addArgument ( "--application-version" ); + VpncProcess->addArgument ( GlobalConfig->currentProfile->getApplicationVersion() ); + GlobalConfig->appendLogEntry ( i18n ( "Using userdefined application version \"%1\"." ).arg ( GlobalConfig->currentProfile->getApplicationVersion() ) , GlobalConfig->debug ); + } + + + // else + // { + // VpncProcess->addArgument( "--local-port" ); + // VpncProcess->addArgument( "0" ); // random port + // GlobalConfig->appendLogEntry ( i18n( "Using random port." ), KVpncConfig::info); + // } + + + if ( GlobalConfig->currentProfile->getUsePerfectForwardSecrety() && !GlobalConfig->currentProfile->getPerfectForwardSecrety().isEmpty() ) + { + VpncProcess->addArgument ( "--pfs" ); + VpncProcess->addArgument ( GlobalConfig->currentProfile->getPerfectForwardSecrety() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Using userdefined PFS \"%1\"." ).arg ( GlobalConfig->currentProfile->getPerfectForwardSecrety() ), GlobalConfig->debug ); + } + + if ( GlobalConfig->currentProfile->getUseIkeGroup() && !GlobalConfig->currentProfile->getIkeGroup().isEmpty() ) + { + VpncProcess->addArgument ( "--dh" ); + VpncProcess->addArgument ( GlobalConfig->currentProfile->getIkeGroup() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Using userdefined IKE group \"%1\"." ).arg ( GlobalConfig->currentProfile->getIkeGroup() ), GlobalConfig->debug ); + } + + if ( GlobalConfig->currentProfile->getUseSingleDes() ) + { + VpncProcess->addArgument ( "--enable-1des" ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Using single DES." ), GlobalConfig->debug ); + } + + if ( vpnc_version_major >= 0 && vpnc_version_minor >= 4 ) + { + VpncProcess->addArgument ( "--ifmode" ); + if ( GlobalConfig->currentProfile->getTunnelDeviceType() == "tap" ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Using tunnel device type: %1." ).arg ( "TAP" ), GlobalConfig->debug ); + VpncProcess->addArgument ( "tap" ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Using tunnel device type: %1." ).arg ( "TUN" ), GlobalConfig->debug ); + VpncProcess->addArgument ( "tun" ); + } + } + if ( GlobalConfig->currentProfile->getDisableDataEncryption() == true ) + { + if ( vpnc_version_major >= 0 && vpnc_version_minor >= 5 ) + { + VpncProcess->addArgument ( "--enable-no-encryption" ); + } + } + + if ( ( vpnc_version_major == 0 && vpnc_version_minor >= 5 ) || ( vpnc_version_major > 0 ) ) + { + if ( GlobalConfig->currentProfile->getUseDpdIdleTimeout() ) + { + VpncProcess->addArgument ( "--dpd-idle" ); + VpncProcess->addArgument ( QString().setNum ( GlobalConfig->currentProfile->getDpdIdleTimeout() ) ); + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Using DPD idle timeout: %1." ).arg ( GlobalConfig->currentProfile->getDpdIdleTimeout() ), GlobalConfig->debug ); + } + else + { + // disabling DPD (Dead Peer Detection) + VpncProcess->addArgument ( "--dpd-idle" ); + VpncProcess->addArgument ( "0" ); + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Disabling DPD idle timeout." ), GlobalConfig->debug ); + } + } + + if ( vpnc_version_major >= 0 && vpnc_version_minor > 2 ) + { + if ( vpnc_version_minor > 3 ) + { + // we send config via stdin + VpncProcess->addArgument ( "-" ); + } + else + { + if ( vpnc_version_subminor > 2 ) + { + // we send config via stdin + VpncProcess->addArgument ( "-" ); + } + } + } + + + + GlobalConfig->appendLogEntry ( i18n ( "Trying to connect to server \"%1\" (%2) with user \"%3\" and IPSec ID \"%4\"...\n" ).arg ( GlobalConfig->currentProfile->getGateway() ).arg ( GlobalConfig->TmpGatewayIP ).arg ( GlobalConfig->currentProfile->getUserName() ).arg ( GlobalConfig->currentProfile->getID() ), GlobalConfig->info ); + + if ( GlobalConfig->currentProfile->getUseDnsUpdate() ) + { + setenv ( "DNS_UPDATE", "Yes", 1 ); + *env << "DNS_UPDATE=Yes"; + } + else + { + setenv ( "DNS_UPDATE", "NO", 1 ); + *env << "DNS_UPDATE=NO"; + } + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Setting DNS_UPDATE \"%1\"." ).arg ( getenv ( "DNS_UPDATE" ) ), GlobalConfig->debug ); + + if ( GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Replacing default route: %1" ).arg ( i18n ( "yes" ) ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Replacing default route: %1" ).arg ( i18n ( "no" ) ), GlobalConfig->debug ); + } + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + { + QString args = ""; + QStringList list = VpncProcess->arguments(); + QStringList::Iterator it = list.begin(); + while ( it != list.end() ) + { + args += QString ( " " + *it ) ; + ++it; + } + GlobalConfig->appendLogEntry ( i18n ( "vpnc arguments: %1" ).arg ( args ), GlobalConfig->debug ); + } + if ( !VpncProcess->start ( env ) ) + { + KMessageBox::sorry ( this, i18n ( "\"%1\" start failed!" ).arg ( "vpnc" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "vpnc" ), GlobalConfig->error ); + disconnectClicked(); + setGuiStatus ( disconnected ); + } + else + { + slotStatusMsg ( i18n ( "Connecting..." ), ID_CONNECTION_MSG ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( "vpnc" ), GlobalConfig->debug ); + ConnectingProcess = VpnAccountData::cisco; + GlobalConfig->status = GlobalConfig->connecting; + mw->buttonDisconnect->setEnabled ( true ); + this->DisconnectAction->setEnabled ( true ); + mw->buttonConnect->setEnabled ( false ); + this->ConnectAction->setEnabled ( false ); + + connect ( VpncProcess, SIGNAL ( processExited () ), this, SLOT ( vpncStarted() ) ); + connect ( VpncProcess, SIGNAL ( wroteToStdin() ), this, SLOT ( wroteToStdin_vpncConfig() ) ); + + if ( vpnc_version_major >= 0 && vpnc_version_minor > 2 ) + { + if ( vpnc_version_minor > 3 ) + { + // we send config via stdin + VpncProcess->writeToStdin ( vpncConfig ); + } + else + { + if ( vpnc_version_subminor > 2 ) + { + // we send config via stdin + VpncProcess->writeToStdin ( vpncConfig ); + } + } + } + + disconnect ( &timer, SIGNAL ( timeout() ), this, SLOT ( slotConnectTimedOut() ) ); + connect ( &timer, SIGNAL ( timeout() ), this, SLOT ( slotConnectTimedOut() ) ); + timer.start ( GlobalConfig->tryConnectTimeout * 1000, FALSE ); + } + } + } + else + { + VpncScript = tmpPath + "vpnc-script." + GlobalConfig->currentProfile->getName(); // vpnc-script. + GlobalConfig->appendLogEntry ( i18n ( "Making %1 (%2) excutable failed!" ).arg ( "VpncScript" ).arg ( VpncScript ), GlobalConfig->error ); + setGuiStatus ( disconnected ); + timer.stop(); + return ; + } + } // vpnc + + /* ============ vpnclient (Cisco propritary) ================ */ + else if ( GlobalConfig->currentProfile != 0 && GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ciscoorig ) + { + // looking for vpnclient + if ( Utils ( GlobalConfig ).getToolInfo ( "vpnclient" )->found == false ) + { + KMessageBox::error ( this, i18n ( "Unable to find \"%1\" at \"%2\"!" ).arg ( "vpnclient" ).arg ( GlobalConfig->pathToCiscoVpnc ) ); + GlobalConfig->appendLogEntry ( i18n ( "Unable to find \"%1\" at \"%2\"!" ).arg ( "vpnclient" ).arg ( GlobalConfig->pathToCiscoVpnc ), GlobalConfig->error ); + ok = false; + setGuiStatus ( disconnected ); + return ; + } + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "vpnclient: %1" ) .arg ( GlobalConfig->pathToCiscoVpnc ), GlobalConfig->debug ); + + + if ( checkCiscoVpncStatus() == false ) + { + startCiscoVpnc(); + if ( checkCiscoVpncStatus() == false ) + { + KMessageBox::error ( this, i18n ( "The Cisco ipsec interface could not setup!" ) ); + GlobalConfig->appendLogEntry ( i18n ( "The Cisco ipsec interface could not setup!" ), GlobalConfig->error ); + ok = false; + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "The Cisco ipsec interface was down and could be started and is now up." ), GlobalConfig->debug ); + } + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "The Cisco ipsec interface is up." ), GlobalConfig->debug ); + } + + + GlobalConfig->TmpGatewayIP = Utils ( GlobalConfig, parent ).resolveName ( GlobalConfig->currentProfile->getGateway() ); + if ( GlobalConfig->TmpGatewayIP == "0.0.0.0" || GlobalConfig->TmpGatewayIP.isEmpty() ) + { + KMessageBox::error ( this, i18n ( "Host \"%1\" could not be resolved!" ).arg ( GlobalConfig->currentProfile->getGateway() ) ); + GlobalConfig->appendLogEntry ( i18n ( "Host \"%1\" could not be resolved!" ).arg ( GlobalConfig->currentProfile->getGateway() ), GlobalConfig->error ); + ok = false; + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "Gateway hostname (%1) resolved to \"%2\"." ).arg ( GlobalConfig->currentProfile->getGateway() ).arg ( GlobalConfig->TmpGatewayIP ), GlobalConfig->info ); + } + + // here we go + if ( ok ) + { + bool askUsernamePass = false; + bool askGroupPass=false; + CiscoVpncDevice = "cipsec0"; + + if ( AuthRetry ) + askUsernamePass = true; + + if ( !GlobalConfig->haveUserData ) + { + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::psk && !GlobalConfig->currentProfile->getSavePsk() ) + askUsernamePass = true; + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::psk && GlobalConfig->currentProfile->getAllowEmptyGroupPassword() && GlobalConfig->currentProfile->getPreSharedKey().isEmpty() ) + askUsernamePass = true; + + if ( GlobalConfig->currentProfile->getUserName().isEmpty() ) + askUsernamePass = true; + + if ( GlobalConfig->currentProfile->getUserPassword().isEmpty() ) + askUsernamePass = true; + + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::psk ) + askGroupPass=true; + + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 4 ) + GlobalConfig->appendLogEntry ( i18n ( "User data already collected." ), GlobalConfig->debug ); + } + if ( GlobalConfig->currentProfile->getAskUserPasswordOnEachConnect() ) + { + if ( GlobalConfig->KvpncDebugLevel > 4 ) + GlobalConfig->appendLogEntry ( i18n ( "User password on each connect forced." ), GlobalConfig->debug ); + + askUsernamePass = true; + } + + if ( askUsernamePass ) + { + bool requestUsername = GlobalConfig->currentProfile->getUserPassword().isEmpty(); + EnterUsernamePasswordDialog dlg ( this, i18n ( "Enter Account Data" ), askGroupPass, requestUsername ); + + if ( !GlobalConfig->currentProfile->getUserName().isEmpty() ) + dlg.main->UsernameEdit->setText ( GlobalConfig->currentProfile->getUserName() ); + + if ( !GlobalConfig->currentProfile->getHideGroupPasswordInAccountDataDialog() ) + { + dlg.main->LabelGroupPassword->setText ( i18n ( "Enter group password:" ) ); + + if ( !GlobalConfig->currentProfile->getPreSharedKey().isEmpty() ) + { + dlg.main->PSKLineEdit->setText ( GlobalConfig->currentProfile->getPreSharedKey() ); + } + } + else + { + dlg.main->PSKLineEdit->hide(); + dlg.main->LabelGroupPassword->hide(); + dlg.main->PSKLineEdit->setText ( GlobalConfig->currentProfile->getPreSharedKey() ); + } + + if ( !GlobalConfig->currentProfile->getUserPassword().isEmpty() ) + dlg.main->PasswordEdit->setText ( GlobalConfig->currentProfile->getUserPassword() ); + + if ( !GlobalConfig->currentProfile->getHideGroupPasswordInAccountDataDialog() ) + { + if ( !dlg.main->UsernameEdit->text().isEmpty() ) //go straight to pw if username present + { + if ( !dlg.main->PSKLineEdit->text().isEmpty() ) + dlg.main->PasswordEdit->setFocus(); + else + dlg.main->PSKLineEdit->setFocus(); + } + } + else + dlg.main->PasswordEdit->setFocus(); + + if ( GlobalConfig->currentProfile->getSaveUserPassword() ) + dlg.main->SavePasswordCheckBox->setChecked ( true ); + else + dlg.main->SavePasswordCheckBox->setChecked ( false ); + + if ( !GlobalConfig->currentProfile->getDontSaveUsername() ) + dlg.main->SaveUsernameCheckBox->setChecked ( true ); + else + dlg.main->SaveUsernameCheckBox->setChecked ( false ); + + if ( GlobalConfig->currentProfile->getSavePsk() ) + dlg.main->SavePskCheckBox->setChecked ( true ); + else + dlg.main->SavePskCheckBox->setChecked ( false ); + + + if ( dlg.exec() ) + { + GlobalConfig->TmpUsername = dlg.main->UsernameEdit->text(); + GlobalConfig->TmpGroupPassword = dlg.main->PSKLineEdit->text(); + GlobalConfig->TmpPassword = dlg.main->PasswordEdit->text(); + bool needSave=false; + + if ( GlobalConfig->currentProfile->getHideGroupPasswordInAccountDataDialog() && GlobalConfig->currentProfile->getPreSharedKey().isEmpty() && !GlobalConfig->currentProfile->getAllowEmptyGroupPassword() ) + askGroupPass=true; + if ( askGroupPass && GlobalConfig->TmpGroupPassword.isEmpty() && !GlobalConfig->currentProfile->getAllowEmptyGroupPassword() ) + { + GlobalConfig->appendLogEntry ( i18n ( "Group password is empty" ), GlobalConfig->error ); + ok = false; + } + + if ( requestUsername && GlobalConfig->TmpUsername.isEmpty() ) + { + GlobalConfig->appendLogEntry ( i18n ( "Username is empty!" ), GlobalConfig->error ); + ok = false; + } + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Some account data which is needed got from password enter dialog." ), GlobalConfig->debug ); + + if ( dlg.main->SaveUsernameCheckBox->isChecked() ) + { + GlobalConfig->currentProfile->setDontSaveUsername ( false ); + GlobalConfig->currentProfile->setUserName ( dlg.main->UsernameEdit->text() ); + needSave=true; + } + else + { + GlobalConfig->currentProfile->setDontSaveUsername ( true ); + needSave = true; + } + + + if ( !GlobalConfig->currentProfile->getHideGroupPasswordInAccountDataDialog() ) + { + if ( dlg.main->SavePskCheckBox->isChecked() && askGroupPass ) + { + GlobalConfig->currentProfile->setSavePsk ( true ); + GlobalConfig->currentProfile->setPreSharedKey ( GlobalConfig->TmpGroupPassword ); + needSave=true; + } + else + { + GlobalConfig->currentProfile->setSavePsk ( false ); + needSave = true; + } + } + else + { + GlobalConfig->TmpGroupPassword = GlobalConfig->currentProfile->getPreSharedKey(); + } + + if ( dlg.main->SavePasswordCheckBox->isChecked() ) + { + GlobalConfig->currentProfile->setSaveUserPassword ( true ); + GlobalConfig->currentProfile->setUserPassword ( GlobalConfig->TmpPassword ); + needSave=true; + } + else + { + GlobalConfig->currentProfile->setSaveUserPassword ( false ); + } + if ( needSave == true ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Need to save because user had request it." ), GlobalConfig->debug ); + + GlobalConfig->saveOptions(true, GlobalConfig->currentProfile->getName()); + } + GlobalConfig->haveUserData=true; + } + else + { + ok = false; + AuthRetry = false; + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Connect canceled because account data dialog aborted." ), GlobalConfig->debug ); + setGuiStatus ( disconnected ); + return; + } + GlobalConfig->TmpPassword= GlobalConfig->currentProfile->getUserPassword(); + GlobalConfig->TmpGroupPassword = GlobalConfig->currentProfile->getPreSharedKey(); + GlobalConfig->TmpUsername = GlobalConfig->currentProfile->getUserName(); + } + + + if ( GlobalConfig->currentProfile->getExecuteCmdBeforeConnect() ) + executeCommandBeforeConnect(); + + tmpPath = locateLocal ( "data", "kvpnc/" ); + + QString tmpInterface; + QString LocalIP; + NetworkInterface iface ( GlobalConfig , parent ); + if ( GlobalConfig->currentProfile->getNetworkDevice() == "default" ) + { + tmpInterface = iface.getDefaultInterface(); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Default interface: \"%1\"." ).arg ( tmpInterface ) , GlobalConfig->debug ); + LocalIP = iface.getInterfaceIP ( iface.getDefaultInterface() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "IP address of default interface: \"%1\"." ).arg ( LocalIP ) , GlobalConfig->debug ); + } + else + { + tmpInterface = GlobalConfig->currentProfile->getNetworkDevice(); + LocalIP = iface.getInterfaceIP ( GlobalConfig->currentProfile->getNetworkDevice() ); + } + if ( tmpInterface.isEmpty() ) + { + tmpInterface = iface.getDefaultInterface(); + LocalIP = iface.getInterfaceIP ( iface.getDefaultInterface() ); + if ( tmpInterface.isEmpty() ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + { + GlobalConfig->appendLogEntry ( i18n ( "No default interface found, using \"lo\"." ), GlobalConfig->debug ); + tmpInterface = "lo"; // no default interface found :( + LocalIP = "127.0.0.1"; + } + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "No default interface given, tried default interface, got success, using \"%1\"." ).arg ( tmpInterface ), GlobalConfig->debug ); + } + } + + if ( LocalIP.isEmpty() ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "No IP for default interface found, using \"127.0.0.1\"." ), GlobalConfig->debug ); + LocalIP = "127.0.0.1"; // no IP for default interface found :( + } + + // QString tunneldevice = "tun0"; + OldDefaultroute = tmpPath + "default-route." + GlobalConfig->currentProfile->getName(); // default-route. + + QFile DefaultRouteBackupFile ( OldDefaultroute + ".sh" ); + QTextStream DefaultRouteBackupFileStream ( &DefaultRouteBackupFile ); + if ( DefaultRouteBackupFile.open ( IO_WriteOnly ) ) + { + DefaultRouteBackupFileStream << "# generated by kvpnc. Do not edit it." << "\n"; + DefaultRouteBackupFileStream << "\n"; + DefaultRouteBackupFileStream << GlobalConfig->pathToIp + " route show | grep default > " + OldDefaultroute + "\n"; + DefaultRouteBackupFile.close(); + QProcess backupDefaultRouteProcess ( this ); + backupDefaultRouteProcess.addArgument ( GlobalConfig->InterpreterShell ); + backupDefaultRouteProcess.addArgument ( OldDefaultroute + ".sh" ); + if ( !backupDefaultRouteProcess.start() ) + { + // if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Connect canceled because default route backup process could not be started." ), GlobalConfig->error ); + return ; + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Default route backup process started." ), GlobalConfig->debug ); + } + } + else + { + // if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Connect canceled because default route could not be backuped." ), GlobalConfig->error ); + return ; + } + + QString ResolvConfBackupProfile = tmpPath + "resolv.conf.before.kvpnc_" + GlobalConfig->currentProfile->getName(); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Backup file of %1: %1" ).arg ( "resolv.conf" ).arg ( ResolvConfBackupProfile ), GlobalConfig->debug ); + + QString UserPassStr = ""; + if ( !GlobalConfig->currentProfile->getUserPassword() || GlobalConfig->currentProfile->getUserPassword() == "" || AuthRetry ) + UserPassStr = GlobalConfig->TmpPassword; + else + UserPassStr = GlobalConfig->currentProfile->getUserPassword(); + + CiscoVpncProcess = new QProcess ( this ); + CiscoVpncProcess->setCommunication ( QProcess::Stdin | QProcess::Stdout | QProcess::Stderr | QProcess::DupStderr ); + connect ( CiscoVpncProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readOutputFrom_ciscovpnc() ) ); + + // write vpnc connect script + QString CiscoVpncConfig = QString ( "/etc/opt/cisco-vpnclient/Profiles/" ) +QString ( "kvpnc_" ) +QString ( GlobalConfig->currentProfile->getName() +".pcf" ); // vpnc-script. + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "CiscoVpncConfig: " + CiscoVpncConfig + "\n", GlobalConfig->debug ); + QFile file ( CiscoVpncConfig ); + QTextStream stream ( &file ); + if ( file.open ( IO_WriteOnly ) ) + { +// stream << "# generated by kvpnc. Do not edit it." << "\n"; + stream << "[main]" << "\n"; + stream << "Description=KVpnc profile " << GlobalConfig->currentProfile->getName() << "\n"; + stream << "Host=" << GlobalConfig->currentProfile->getGateway() << "\n"; + + // 1 = Pre-shared keys (default) + // 3 = Digital Certificate using an RSA signature. + // 5 = Mutual authentication + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::psk ) + stream << "AuthType=1" << "\n"; + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::cert ) + stream << "AuthType=3" << "\n"; + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::hybrid ) + stream << "AuthType=5" << "\n"; + + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::psk ) + { + stream << "GroupName=" << GlobalConfig->currentProfile->getID() << "\n"; + stream << "GroupPwd=" << GlobalConfig->currentProfile->getPreSharedKey() << "\n"; + } + stream << "EnableISPConnect=0" << "\n"; + stream << "ISPConnectType=0" << "\n"; + stream << "ISPConnect=" << "\n"; + stream << "ISPCommand=" << "\n"; + if ( GlobalConfig->currentProfile->getUserName().isEmpty() || AuthRetry ) + stream << "Username=" << GlobalConfig->TmpUsername << "\n"; + else + stream << "Username=" << GlobalConfig->currentProfile->getUserName() << "\n"; + if ( GlobalConfig->currentProfile->getSaveUserPassword() ) + stream << "SaveUserPassword=0" << "\n"; + else + stream << "SaveUserPassword=1" << "\n"; +// stream << "UserPassword=" << "\n"; + if ( GlobalConfig->currentProfile->getUseNtDomainName() ) + { + stream << "NTDomain=" << GlobalConfig->currentProfile->getNtDomainName() << "\n"; + stream << "EnableMSLogon=1" << "\n"; + } + else + { + stream << "NTDomain=" << "\n"; + stream << "EnableMSLogon=0" << "\n"; + } + stream << "EnableBackup=0" << "\n"; + stream << "BackupServer=" << "\n"; + + stream << "MSLogonType=0" << "\n"; + + if ( GlobalConfig->currentProfile->getUseNat() ) + { + stream << "EnableNat=1" << "\n"; + } + else + { + stream << "EnableNat=0" << "\n"; + } + + if ( GlobalConfig->currentProfile->getUseUdp() ) + { + stream << "TunnelingMode=0" << "\n"; + } + else + { + stream << "TunnelingMode=1" << "\n"; + if ( GlobalConfig->currentProfile->getUseLocalPort()) + stream << "TcpTunnelingPort=" << GlobalConfig->currentProfile->getLocalPort() << "\n"; + } + + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::cert ) + { + if ( GlobalConfig->currentProfile->getUseCiscoCertStore() ) + { + stream << "CertStore=1" << "\n"; + } + else + { + stream << "CertStore=0" << "\n"; + } + stream << "CertPath=" << GlobalConfig->currentProfile->getCertPath() << "\n"; + stream << "CertName=" << GlobalConfig->currentProfile->getX509Certificate() << "\n"; + + //stream << "CertSubjectName=" << "\n"; + //stream << "CertSerialHash=00000000000000000000000000000000" << "\n"; + stream << "SendCertChain=0" << "\n"; + } + + stream << "PeerTimeout=" << GlobalConfig->currentProfile->getDpdIdleTimeout() << "\n"; + stream << "EnableLocalLAN=0" << "\n"; // always off + + file.close(); + + CiscoVpncProcess->addArgument ( GlobalConfig->pathToCiscoVpnc ); + + CiscoVpncProcess->addArgument ( "connect" ); + CiscoVpncProcess->addArgument ( "kvpnc_"+GlobalConfig->currentProfile->getName() ); + CiscoVpncProcess->addArgument ( "user" ); + CiscoVpncProcess->addArgument ( GlobalConfig->currentProfile->getUserName() ); + + + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::psk ) + { + GlobalConfig->appendLogEntry ( i18n ( "Trying to connect to server \"%1\" (%2) with user \"%3\" and IPSec ID \"%4\"...\n" ).arg ( GlobalConfig->currentProfile->getGateway() ).arg ( GlobalConfig->TmpGatewayIP ).arg ( GlobalConfig->currentProfile->getUserName() ).arg ( GlobalConfig->currentProfile->getID() ), GlobalConfig->info ); + } + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::cert ) + { + GlobalConfig->appendLogEntry ( i18n ( "Trying to connect to server \"%1\" (%2) with user \"%3\"...\n" ).arg ( GlobalConfig->currentProfile->getGateway() ).arg ( GlobalConfig->TmpGatewayIP ).arg ( GlobalConfig->currentProfile->getUserName() ), GlobalConfig->info ); + } + + setenv ( "DNS_UPDATE", ( GlobalConfig->currentProfile->getUseDnsUpdate() ? "Yes" : "NO" ), 1 ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Setting DNS_UPDATE \"%1\"." ).arg ( getenv ( "DNS_UPDATE" ) ), GlobalConfig->debug ); + + + if ( !CiscoVpncProcess->start ( env ) ) + { + delete CiscoVpncProcess; + CiscoVpncProcess=0L; + KMessageBox::sorry ( this, i18n ( "\"%1\" start failed!" ).arg ( "vpnclient" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "vpnclient" ), GlobalConfig->error ); + disconnectClicked(); + setGuiStatus ( disconnected ); + } + else + { + slotStatusMsg ( i18n ( "Connecting..." ), ID_CONNECTION_MSG ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( "vpnclient" ), GlobalConfig->debug ); + ConnectingProcess = VpnAccountData::cisco; + GlobalConfig->status = GlobalConfig->connecting; + mw->buttonDisconnect->setEnabled ( true ); + this->DisconnectAction->setEnabled ( true ); + mw->buttonConnect->setEnabled ( false ); + this->ConnectAction->setEnabled ( false ); + +// connect ( VpncProcess, SIGNAL ( processExited () ), this, SLOT ( vpncStarted() ) ); +// connect ( VpncProcess, SIGNAL ( wroteToStdin() ), this, SLOT ( wroteToStdin_vpncConfig() ) ); + + } + disconnect ( &timer, SIGNAL ( timeout() ), this, SLOT ( slotConnectTimedOut() ) ); + connect ( &timer, SIGNAL ( timeout() ), this, SLOT ( slotConnectTimedOut() ) ); + timer.start ( GlobalConfig->tryConnectTimeout * 1000, FALSE ); + } + else + { + // file could not written + GlobalConfig->appendLogEntry ( i18n ( "Connect canceled because profile file could not be written." ), GlobalConfig->error ); + setGuiStatus ( disconnected ); + return ; + } + } + else + { + // ok is false + setGuiStatus ( disconnected ); + return ; + } + } + + /* ============ racoon ================ */ + else if ( GlobalConfig->currentProfile != 0 && ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon || GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) ) + { + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "racoon" ), GlobalConfig->debug ); + + //setGuiStatus(connecting); + // looking for racoon + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon ) + { + if ( Utils ( GlobalConfig ).getToolInfo ( "racoon" )->found == false ) + { + KMessageBox::error ( this, i18n ( "Unable to find \"%1\" at \"%2\"!" ).arg ( "racoon" ).arg ( GlobalConfig->pathToRacoon ) ); + GlobalConfig->appendLogEntry ( i18n ( "Unable to find \"%1\" at \"%2\"!" ).arg ( "racoon" ).arg ( GlobalConfig->pathToRacoon ), GlobalConfig->error ); + ok = false; + setGuiStatus ( disconnected ); + return ; + } + } + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { + if ( Utils ( GlobalConfig ).getToolInfo ( "l2tpd" )->found == false && Utils ( GlobalConfig ).getToolInfo ( "xl2tpd" )->found == false ) + { + KMessageBox::error ( this, i18n ( "Unable to find \"%1\" or \"%2\"!" ).arg ( "l2tpd" ).arg ( "xl2tpd" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Unable to find \"%1\" or \"%2\"!" ).arg ( "l2tpd" ).arg ( "xl2tpd" ), GlobalConfig->error ); + ok = false; + setGuiStatus ( disconnected ); + return ; + } + } + + // looking for setkey + if ( GlobalConfig->useDefaultPaths ) + { + GlobalConfig->pathToSetkey = KStandardDirs::findExe ( "setkey", QString::null ); + } + else if ( GlobalConfig->pathToSetkey.isEmpty() || KStandardDirs::findExe ( GlobalConfig->pathToSetkey.section ( '/', -1, -1 ), GlobalConfig->pathToSetkey.section ( '/', 0, -2 ) ).isEmpty() ) + { + KMessageBox::error ( this, i18n ( "Unable to find \"%1\" at \"%2\"!" ).arg ( "setkey" ).arg ( GlobalConfig->pathToSetkey ) ); + GlobalConfig->appendLogEntry ( i18n ( "Unable to find \"%1\" at \"%2\"!" ).arg ( "setkey" ).arg ( GlobalConfig->pathToSetkey ), GlobalConfig->error ); + ok = false; + setGuiStatus ( disconnected ); + return ; + } + + QString resolvedIp = Utils ( GlobalConfig, parent ).resolveName ( GlobalConfig->currentProfile->getGateway() ); + if ( resolvedIp == "0.0.0.0" || resolvedIp.isEmpty() ) + { + KMessageBox::error ( this, i18n ( "Host \"%1\" could not be resolved!" ).arg ( GlobalConfig->currentProfile->getGateway() ) ); + GlobalConfig->appendLogEntry ( i18n ( "Host \"%1\" could not be resolved!" ).arg ( GlobalConfig->currentProfile->getGateway() ), GlobalConfig->error ) ; + ok = false; + setGuiStatus ( disconnected ); + return; + } + else + { + GlobalConfig->TmpGatewayIP = resolvedIp; + GlobalConfig->appendLogEntry ( i18n ( "Gateway hostname (%1) resolved to \"%2\"." ).arg ( GlobalConfig->currentProfile->getGateway() ).arg ( GlobalConfig->TmpGatewayIP ), GlobalConfig->info ); + } + + if ( GlobalConfig->currentProfile->authtype == VpnAccountData::cert ) + { + QFile CertTmpFile; + CertTmpFile.setName ( GlobalConfig->currentProfile->getX509Certificate() ); + if ( !CertTmpFile.exists() ) + { + KMessageBox::error ( 0, i18n ( "Certificate file (%1) could not be found. Please check the path of it." ).arg ( GlobalConfig->currentProfile->getCertPath() ), i18n ( "File Not Found" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Certificate file (%1) could not be found. Please check the path of it." ).arg ( GlobalConfig->currentProfile->getX509Certificate() ), GlobalConfig->error ); + ok = false; + } + } + + RacoonProcess = 0L; + RacoonctlProcess = 0L; + + if ( !Utils ( GlobalConfig, parent ).loadKernelModule ( "esp4", parent ) ) + { +// KMessageBox::information ( this, i18n ( "Loading of module \"%1\" failed!" ).arg ( "esp4" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Loading module \"%1\" has failed." ).arg ( "esp4" ), GlobalConfig->info ); +// ok = false; + } + + if ( !Utils ( GlobalConfig, parent ).loadKernelModule ( "ah4", parent ) ) + { +// KMessageBox::information ( this, i18n ( "Loading of module \"%1\" failed!" ).arg ( "ah4" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Loading module \"%1\" has failed." ).arg ( "ah4" ), GlobalConfig->info ); +// ok = false; + } + + + if ( ok==false ) + return; + + bool askUsernamePass = false; + bool askPsk = false; + + if ( !GlobalConfig->haveUserData ) + { + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::psk && ( GlobalConfig->currentProfile->getSavePsk() == false || GlobalConfig->currentProfile->getPreSharedKey().isEmpty() ) ) + { + askUsernamePass = false; + askPsk = true; + } + } + + // L2TP/XAUTH + if ( GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) + { + if ( !GlobalConfig->haveUserData ) + { + GlobalConfig->TmpUsername = GlobalConfig->currentProfile->getUserName(); + GlobalConfig->TmpPassword = GlobalConfig->currentProfile->getUserPassword(); + + if ( GlobalConfig->TmpPassword.isEmpty() || GlobalConfig->TmpUsername.isEmpty() ) + askUsernamePass=true; + + if ( !GlobalConfig->currentProfile->getPskIsInFile() ) + GlobalConfig->TmpGroupPassword = GlobalConfig->currentProfile->getPreSharedKey(); + else + { + QFile PskFile ( GlobalConfig->currentProfile->getPreSharedKeyFile() ); + if ( PskFile.open ( IO_ReadOnly ) ) + { + QString PskFileContent = QString ( PskFile.readAll() ); + PskFile.close(); + GlobalConfig->TmpGroupPassword = PskFileContent; + } + } + GlobalConfig->WaitingForXauth=false; + GlobalConfig->haveUserData=true; + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 4 ) + GlobalConfig->appendLogEntry ( i18n ( "User data already collected." ), GlobalConfig->debug ); + } + } + + if ( AuthRetry ) + askUsernamePass = true; + + if ( GlobalConfig->currentProfile->getAskUserPasswordOnEachConnect() ) + { + if ( GlobalConfig->KvpncDebugLevel > 4 ) + GlobalConfig->appendLogEntry ( i18n ( "User password on each connect forced." ), GlobalConfig->debug ); + + askUsernamePass = true; + } + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon && ( !GlobalConfig->currentProfile->getSaveUserPassword() && GlobalConfig->currentProfile->getUserName().isEmpty() || GlobalConfig->currentProfile->getUserPassword().isEmpty() ) ) + askUsernamePass = true; + + if ( askUsernamePass || askPsk ) + { + bool requestUsername = false; + EnterUsernamePasswordDialog dlg ( this, i18n ( "Enter Account Data" ), askPsk, askUsernamePass ); + if ( askUsernamePass ) + { + requestUsername = GlobalConfig->currentProfile->getUserPassword().isEmpty(); + + if ( !GlobalConfig->currentProfile->getUserName().isEmpty() ) + dlg.main->UsernameEdit->setText ( GlobalConfig->currentProfile->getUserName() ); + dlg.main->LabelGroupPassword->setText ( i18n ( "PSK:" ) ); + + if ( !GlobalConfig->currentProfile->getUserPassword().isEmpty() ) + dlg.main->PasswordEdit->setText ( GlobalConfig->currentProfile->getUserPassword() ); + else + dlg.main->PasswordEdit->setFocus(); + } + if ( askPsk ) + { + if ( !GlobalConfig->currentProfile->getPreSharedKey().isEmpty() ) + dlg.main->PSKLineEdit->setText ( GlobalConfig->currentProfile->getPreSharedKey() ); + else + if ( !GlobalConfig->currentProfile->getUserPassword().isEmpty() ) + dlg.main->PSKLineEdit->setFocus(); + if ( !askUsernamePass ) + { + dlg.main->PasswordEdit->hide(); + dlg.main->UsernameEdit->hide(); + dlg.main->LabelPassword->hide(); + dlg.main->LabelUsername->hide(); + } + } + else + { + dlg.main->LabelGroupPassword->hide(); + dlg.main->PSKLineEdit->hide(); + } + + // dlg.main->SaveValuesCheckBox->setChecked( GlobalConfig->currentProfile->getSaveUserPassword() || !GlobalConfig->currentProfile->getDontSaveUsername() ); + + if ( dlg.exec() ) + { + bool needSave = false; + GlobalConfig->TmpGroupPassword = dlg.main->PSKLineEdit->text(); + GlobalConfig->TmpUsername = dlg.main->UsernameEdit->text(); + GlobalConfig->TmpPassword = dlg.main->PasswordEdit->text(); + + if ( askPsk || AuthRetry ) + { + + if ( GlobalConfig->currentProfile->getPreSharedKey().isEmpty() || GlobalConfig->TmpGroupPassword.isEmpty() ) + { + GlobalConfig->appendLogEntry ( i18n ( "PSK is empty!" ), GlobalConfig->error ); + ok = false; + } + } + + if ( dlg.main->SaveUsernameCheckBox->isChecked() ) + { + GlobalConfig->currentProfile->setDontSaveUsername ( false ); + GlobalConfig->currentProfile->setUserName ( dlg.main->UsernameEdit->text() ); + needSave = true; + } + else + { + GlobalConfig->TmpUsername = dlg.main->UsernameEdit->text(); + GlobalConfig->currentProfile->setDontSaveUsername ( true ); + needSave = true; + } + + + if ( dlg.main->SavePskCheckBox->isChecked() ) + { + GlobalConfig->currentProfile->setSavePsk ( true ); + GlobalConfig->currentProfile->setPreSharedKey ( GlobalConfig->TmpGroupPassword ); + needSave = true; + } + else + { + GlobalConfig->currentProfile->setSavePsk ( false ); + } + + if ( dlg.main->SavePasswordCheckBox->isChecked() ) + { + GlobalConfig->currentProfile->setSaveUserPassword ( true ); + GlobalConfig->currentProfile->setUserPassword ( GlobalConfig->TmpPassword ); + } + else + { + GlobalConfig->currentProfile->setSaveUserPassword ( false ); + needSave = true; + } + if (needSave) + GlobalConfig->saveOptions(true, GlobalConfig->currentProfile->getName()); + + if ( ok ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Some account data which is needed got from password enter dialog." ), GlobalConfig->debug ); + // saveSessionClicked(); + } + } + else + { + ok = false; + AuthRetry = false; + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Connect canceled because account data dialog aborted." ), GlobalConfig->debug ); + } + } + if ( GlobalConfig->currentProfile->getPskIsInFile() ) + { + QFile f ( GlobalConfig->currentProfile->getPreSharedKeyFile() ); + if ( f.open ( IO_ReadOnly ) ) + { + QTextStream stream ( &f ); + QString line = ""; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' + if ( !line.find ( '#', 0 ) < 0 ) + { + GlobalConfig->TmpGroupPassword = line; + break; + } + } + f.close(); + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "PSK could not read from file because PSK key file %1 could not be read." ).arg ( GlobalConfig->currentProfile->getPreSharedKeyFile() ), GlobalConfig->error ); + ok = false; + } + if ( GlobalConfig->TmpGroupPassword.isEmpty() ) + { + GlobalConfig->appendLogEntry ( i18n ( "PSK could not read from file because PSK key file %1 contains no key." ).arg ( GlobalConfig->currentProfile->getPreSharedKeyFile() ), GlobalConfig->error ); + ok = false; + } + } + // here we go + if ( ok ) + { + if ( GlobalConfig->currentProfile->getExecuteCmdBeforeConnect() ) + executeCommandBeforeConnect(); + + QString tmpInterface; + QString LocalIP; + NetworkInterface iface ( GlobalConfig, parent ); + if ( GlobalConfig->currentProfile->getNetworkDevice() == "default" || GlobalConfig->currentProfile->getNetworkDevice() == "" ) + { + tmpInterface = iface.getDefaultInterface(); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Default interface: \"%1\"." ).arg ( tmpInterface ) , GlobalConfig->debug ); + LocalIP = iface.getInterfaceIP ( iface.getDefaultInterface() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "IP address of default interface: \"%1\"." ).arg ( LocalIP ) , GlobalConfig->debug ); + } + else + { + tmpInterface = GlobalConfig->currentProfile->getNetworkDevice(); + LocalIP = iface.getInterfaceIP ( GlobalConfig->currentProfile->getNetworkDevice() ); + } + if ( tmpInterface.isEmpty() ) + { + tmpInterface = iface.getDefaultInterface(); + LocalIP = iface.getInterfaceIP ( iface.getDefaultInterface() ); + if ( tmpInterface.isEmpty() ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + { + GlobalConfig->appendLogEntry ( i18n ( "No default interface found, using \"lo\"." ), GlobalConfig->debug ); + tmpInterface = "lo"; // no default interface found :( + } + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "No default interface given, tried default interface, got success, using \"%1\"." ).arg ( tmpInterface ), GlobalConfig->debug ); + } + } + + if ( LocalIP.isEmpty() ) + { + if ( GlobalConfig->PppdDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "No IP for default interface found, using \"127.0.0.1\"." ), GlobalConfig->debug ); + LocalIP = "127.0.0.1"; // no IP for default interface found :( + } + + // FIXME + // if not virtual ip, its same as LocalIP + QString VirtualLocalIP=LocalIP; + // if not virtual ip, its 32 (only one host) + QString VirtualLocalNetmask="32"; + + if ( GlobalConfig->currentProfile->getUseLeftSourceIp() ) + { + VirtualLocalIP = GlobalConfig->currentProfile->getLeftSourceIp(); + } + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + { + GlobalConfig->appendLogEntry ( i18n ( "Default interface: %1" ).arg ( tmpInterface ), GlobalConfig->debug ); + GlobalConfig->appendLogEntry ( i18n ( "Local IP address: %1" ).arg ( LocalIP ), GlobalConfig->debug ); + GlobalConfig->appendLogEntry ( i18n ( "Local IP address (virtual): %1" ).arg ( VirtualLocalIP ), GlobalConfig->debug ); + GlobalConfig->appendLogEntry ( i18n ( "Local netmask (virtual): %1" ).arg ( VirtualLocalNetmask ), GlobalConfig->debug ); + } + + QString Gateway = GlobalConfig->currentProfile->getGateway(); + QString RemoteNetAddr = GlobalConfig->currentProfile->getRemoteNetAddr(); + QString RemoteNetMask = GlobalConfig->currentProfile->getRemoteNetMask(); + QString RemoteNet = RemoteNetAddr + "/" + RemoteNetMask; + + tmpPath = locateLocal ( "data", "kvpnc/" ); // should be + // KTempDir tmpdir; + // tmpPath = tmpdir.name(); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "tmppath: " + tmpPath, GlobalConfig->debug ); + QString ProfileName = GlobalConfig->currentProfile->getName(); + QString CertPath = GlobalConfig->currentProfile->getCertPath(); + + // write setkey.conf + QFile file ( tmpPath + "setkey." + ProfileName + ".conf" ); + QTextStream stream ( &file ); + if ( file.open ( IO_WriteOnly ) ) + { + + QString PolicyRemote = ""; + QString PolicyLocal = ""; + + QString Remote = GlobalConfig->currentProfile->getGateway(); + + //FIXME make it dynamiclly + QString LocalPort = "4500"; + QString RemotePort = "4500"; + + if ( !GlobalConfig->currentProfile->getUseNat() ) + { + // Use this for a non NAT-T setup + PolicyLocal = LocalIP; + PolicyRemote = GlobalConfig->TmpGatewayIP; + } + else + { + PolicyLocal = LocalIP + "[" + LocalPort + "]"; + PolicyRemote = GlobalConfig->TmpGatewayIP + "[" + RemotePort + "]"; + } + + stream << "flush;" << "\n"; + stream << "spdflush;" << "\n"; + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { + stream << "spdadd " << Remote << "[1701] " << LocalIP << "[any] udp -P in ipsec esp/transport//require;" << "\n"; + stream << "spdadd " << LocalIP << "[any] " << Remote << "[1701] udp -P out ipsec esp/transport//require;" << "\n"; + // stream << "spdadd " << Remote << "[1701] " << LocalIP << "[any] udp -P in ipsec esp/tunnel/" + GlobalConfig->TmpGatewayIP + "-" + LocalIP + "/require;" << "\n"; + // stream << "spdadd " << LocalIP << "[any] " << Remote << "[1701] udp -P out ipsec esp/tunnel/" + LocalIP + "-" + GlobalConfig->TmpGatewayIP + "/require;" << "\n"; + } + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon || ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon && GlobalConfig->currentProfile->getAuthType() == VpnAccountData::hybrid ) ) + { + // stream << "spdadd " + LocalIP + " " + RemoteNet + " any -P out ipsec esp/tunnel/" + PolicyLocal + "-" + PolicyRemote + "/require;" << "\n"; + // stream << "spdadd " + RemoteNet + " " + LocalIP + " any -P in ipsec esp/tunnel/" + PolicyRemote + "-" + PolicyLocal + "/require;" << "\n"; + if ( GlobalConfig->currentProfile->getUseRemoteNetwork() ) + { + stream << "spdadd " + VirtualLocalIP + " " + RemoteNet + " any -P out ipsec esp/tunnel/" + LocalIP + "-" + GlobalConfig->TmpGatewayIP + "/require;" << "\n"; + stream << "spdadd " + RemoteNet + " " + VirtualLocalIP + " any -P in ipsec esp/tunnel/" + GlobalConfig->TmpGatewayIP + "-" + LocalIP + "/require;" << "\n"; + } + else + { + stream << "spdadd " + LocalIP + " " + GlobalConfig->TmpGatewayIP+" any -P out ipsec esp/transport//require;" << "\n"; + stream << "spdadd " + GlobalConfig->TmpGatewayIP+" " + LocalIP + " any -P in ipsec esp/transport//require;" << "\n"; + } + + } + + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { + + stream << "spdadd " + LocalIP + "[1701] " + Remote + "[any] udp -P in ipsec esp/transport//require;" << "\n"; + stream << "spdadd " + Remote + "[any] " + LocalIP + "[1701] udp -P out ipsec esp/transport//require;" << "\n"; + stream << "spdadd " + LocalIP + "[1701] " + Remote + "[any] udp -P fwd ipsec esp/transport//require;" << "\n"; + + // additional network routes + if ( !GlobalConfig->currentProfile->getAdditionalNetworkRoutes().isEmpty() ) + { + QStringList AdditionalNetworkRoutes = GlobalConfig->currentProfile->getAdditionalNetworkRoutes(); + + for ( QStringList::Iterator it = AdditionalNetworkRoutes.begin(); it != AdditionalNetworkRoutes.end();++it ) + { + QString net = ( *it ).section ( '#', 0, 0 ); + // stream << "spdadd " + LocalIP + " " + net + " any -P out ipsec esp/tunnel/" + PolicyLocal + "-" + PolicyRemote + "/require;" << "\n"; + // stream << "spdadd " + net + " " + LocalIP + " any -P in ipsec esp/tunnel/" + PolicyRemote + "-" + PolicyLocal + "/require;" << "\n"; + stream << "spdadd " + LocalIP + " " + net + " any -P out ipsec esp/tunnel/" + LocalIP + "-" + GlobalConfig->TmpGatewayIP + "/require;" << "\n"; + stream << "spdadd " + net + " " + LocalIP + " any -P in ipsec esp/tunnel/" + GlobalConfig->TmpGatewayIP + "-" + LocalIP + "/require;" << "\n"; + } + } + } + file.close(); + } + // write racoon..conf + file.setName ( tmpPath + "racoon." + ProfileName + ".conf" ); + if ( file.open ( IO_WriteOnly ) ) + { + stream.setDevice ( &file ); + stream << "# generated by kvpnc. Do not edit it." << "\n"; + stream << "# profile: " + ProfileName << "\n"; + + stream << "\n"; + if ( GlobalConfig->RacoonDebugLevel != "none" ) + stream << "log " + GlobalConfig->RacoonDebugLevel << ";" << "\n"; // FIXME: validate racoon version + + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::cert || GlobalConfig->currentProfile->getAuthType() == VpnAccountData::hybrid ) + stream << "path certificate \"" + GlobalConfig->currentProfile->getCertPath() + "\";" << "\n"; + + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::psk ) + stream << "path pre_shared_key \"" + tmpPath + "psk." + GlobalConfig->currentProfile->getName() + ".key" + "\";" << "\n"; + + + + + +// stream << "#option of controlling racoon by racoonctl tool is enabled" << "\n"; + stream << "listen {" << "\n"; + stream << " adminsock \"/var/run/racoon/racoon.sock\" \"root\" \"operator\" 0660;" << "\n"; + if ( GlobalConfig->currentProfile->getUseNat() ) + { + stream << " isakmp_natt " << LocalIP << " [4500];" << "\n"; + } +// else +// { + stream << " isakmp " << LocalIP << " [500];" << "\n"; +// } + stream << "}" << "\n"; + +// if ( GlobalConfig->currentProfile->getUseNat() ) +// { +// stream << "" << "\n"; +// stream << "timer" << "\n"; +// stream << "{" << "\n"; +// +// //FIXME make it dynamiclly +// stream << " natt_keepalive 20 sec;" << "\n"; +// stream << "}" << "\n"; +// } + stream << "" << "\n"; + stream << "remote " << GlobalConfig->TmpGatewayIP << " {" << "\n"; + stream << " exchange_mode " << GlobalConfig->currentProfile->getExchangeMode() << ";" << "\n"; + + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::cert ) + { + stream << " certificate_type x509 \"" << GlobalConfig->currentProfile->getX509Certificate() << "\" \"" << GlobalConfig->currentProfile->getX509Certificate() + "\";" << "\n"; + if ( !GlobalConfig->currentProfile->getCaCertificate().isEmpty() ) + stream << " ca_type x509 \"" << GlobalConfig->currentProfile->getCaCertificate() << "\";" << "\n"; + + // FIXME make it dynamiclly + stream << " proposal_check obey;" << "\n"; + + if ( GlobalConfig->currentProfile->getVerifyCaCert() ) + stream << " verify_cert on;" << "\n"; + else + stream << " verify_cert off;" << "\n"; +// if ( GlobalConfig->currentProfile->getUseSpecialRemoteID() ) +// { +// stream << " peers_identifier asn1dn " << GlobalConfig->currentProfile->getSpecialRemoteID() << ";" << "\n"; +// } +// else +// { +// if ( GlobalConfig->currentProfile->getUseMailAddressAsIdentifier() ) +// { +// QString MailAddressOfUserCert = Utils ( GlobalConfig ).getEmailAddressOfCert ( GlobalConfig->currentProfile->getX509Certificate() ); +// +// if ( GlobalConfig->KvpncDebugLevel > 0 ) +// GlobalConfig->appendLogEntry ( i18n ( "Using mail address as VPN id: %1." ).arg ( MailAddressOfUserCert ), GlobalConfig->debug ); +// +// // stream << " peers_identifier asn1dn;" << "\n"; +// //FIXME check if MailAddressOfUserCert is empty +// stream << " my_identifier user_fqdn \"" << MailAddressOfUserCert << "\";" << "\n"; +// } + } + + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::hybrid ) + { + if ( !GlobalConfig->currentProfile->getCaCertificate().isEmpty() ) + stream << " ca_type x509 \"" << GlobalConfig->currentProfile->getCaCertificate() << "\";" << "\n"; + + // FIXME make it dynamiclly + stream << " proposal_check obey;" << "\n"; + + if ( GlobalConfig->currentProfile->getVerifyCaCert() ) + stream << " verify_cert on;" << "\n"; + else + stream << " verify_cert off;" << "\n"; + } + + if ( GlobalConfig->currentProfile->getUseNat() ) + { + stream << " nat_traversal on;" << "\n"; + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Using NAT-T." ), GlobalConfig->debug ); + } + else + { + stream << " nat_traversal off;" << "\n"; + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Disabling NAT-T." ), GlobalConfig->debug ); + } + + // FIXME make it dynamiclly + stream << " ike_frag on;" << "\n"; + + if ( GlobalConfig->currentProfile->getUseModeConfig() ) + { + stream << " mode_cfg on;" << "\n"; + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Using Mode Config." ), GlobalConfig->debug ); + } + else + { + stream << " mode_cfg off;" << "\n"; + } + + stream << " passive off;" << "\n"; + +// stream << " #IKE first phase starting script" << "\n"; + stream << " script \""+tmpPath+"racoon-"+ProfileName+".phase1-up.sh\" phase1_up;" << "\n"; +// stream << "\n"; +// stream << " #IKE first phase ending script" << "\n"; + stream << " script \""+tmpPath+"racoon-"+ProfileName+".phase1-down.sh\" phase1_down;" << "\n"; + + /* + none: No ID + address: The type is the IP address. This is the default type if you do not specify an identifier to use + user_fqdn: The type is a USER_FQDN (user fully-qualified domain name) + fqdn: The type is a FQDN (fully-qualified domain name) + keyid (file): The type is a KEY_ID, read from the file + keyid: The type is a KEY_ID, specified in the quoted string + asn1dn: The type is an ASN.1 distinguished name. If empty, DN from the Subject field in the certificate will be used + */ + + QString RemoteIDType = GlobalConfig->currentProfile->getRemoteIDType(); + + if ( RemoteIDType == "none" ) + { + // no ID + } + else if ( RemoteIDType == "address" ) + { + if ( !GlobalConfig->currentProfile->getSpecialRemoteID().isEmpty() ) + stream << " peers_identifier address \"" << GlobalConfig->currentProfile->getSpecialRemoteID() << "\";" << "\n"; + else + stream << " peers_identifier address;" << "\n"; + } + else if ( RemoteIDType == "user_fqdn" ) + { + stream << " peers_identifier user_fqdn \"" << GlobalConfig->currentProfile->getSpecialRemoteID() << "\";" << "\n"; + } + else if ( RemoteIDType == "fqdn" ) + { + stream << " peers_identifier fqdn \"" << GlobalConfig->currentProfile->getSpecialRemoteID() << "\";" << "\n"; + } + else if ( RemoteIDType == "keyid (file)" ) + { + stream << " peers_identifier keyid tag " << GlobalConfig->currentProfile->getSpecialRemoteID() << ";" << "\n"; + } + else if ( RemoteIDType == "keyid" ) + { + stream << " peers_identifier keyid \"" << GlobalConfig->currentProfile->getSpecialRemoteID() << "\";" << "\n"; + } + else if ( RemoteIDType == "asn1dn" ) + { + stream << " peers_identifier asn1dn;" << "\n"; + } + + QString LocalIDType = GlobalConfig->currentProfile->getLocalIDType(); + if ( LocalIDType == "none" ) + { + // no ID + } + else if ( LocalIDType == "address" ) + { + if ( !GlobalConfig->currentProfile->getSpecialLocalID().isEmpty() ) + stream << " my_identifier address \"" << GlobalConfig->currentProfile->getSpecialLocalID() << "\";" << "\n"; + else + stream << " my_identifier address;" << "\n"; + } + else if ( LocalIDType == "user_fqdn" ) + { + stream << " my_identifier user_fqdn \"" << GlobalConfig->currentProfile->getSpecialLocalID() << "\";" << "\n"; + } + else if ( LocalIDType == "fqdn" ) + { + stream << " my_identifier fqdn \"" << GlobalConfig->currentProfile->getSpecialLocalID() << "\";" << "\n"; + } + else if ( LocalIDType == "keyid (file)" ) + { + stream << " peers_identifier keyid tag " << GlobalConfig->currentProfile->getSpecialLocalID() << ";" << "\n"; + } + else if ( LocalIDType == "keyid" ) + { + stream << " my_identifier keyid \"" << GlobalConfig->currentProfile->getSpecialLocalID() << "\";" << "\n"; + } + else if ( LocalIDType == "asn1dn" ) + { + stream << " my_identifier asn1dn;" << "\n"; + } + + + + // stream << " passive on;" << "\n"; + if ( GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) + { +// stream << " # XAUTH" << "\n"; +// stream << " xauth_login \"" << GlobalConfig->TmpUsername << "\";" <<"\n"; + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Using XAUTH." ), GlobalConfig->debug ); + } + + // FIXME: make dynamiclly + stream << " proposal_check obey;" << "\n"; + + stream << " proposal {" << "\n"; + +// stream << " # for phase 1" << "\n"; + stream << " encryption_algorithm " << GlobalConfig->currentProfile->getIpsecIke() << ";" << "\n"; + + if ( ! GlobalConfig->currentProfile->getHashAlgo().isEmpty() ) + stream << " hash_algorithm " << GlobalConfig->currentProfile->getHashAlgo() << ";" << "\n"; + + // x509 + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::cert ) + stream << " authentication_method rsasig;" << "\n"; + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::psk ) + stream << " authentication_method pre_shared_key;" << "\n"; + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::hybrid ) + stream << " authentication_method hybrid_rsa_client;" << "\n"; + + /* + modp768 1 + modp1024 2 + modp1536 5 + modp2048 14 + modp3072 15 + modp4096 16 + modp6144 17 + modp8192 18 + */ + QString DhGroupNumber = "2"; + if (GlobalConfig->currentProfile->getIkeGroup() == "modp768") + DhGroupNumber = "1"; + else if (GlobalConfig->currentProfile->getIkeGroup() == "modp1024") + DhGroupNumber = "2"; + else if (GlobalConfig->currentProfile->getIkeGroup() == "modp1536") + DhGroupNumber = "5"; + else if (GlobalConfig->currentProfile->getIkeGroup() == "modp2048") + DhGroupNumber = "14"; + else if (GlobalConfig->currentProfile->getIkeGroup() == "modp3072") + DhGroupNumber = "15"; + else if (GlobalConfig->currentProfile->getIkeGroup() == "modp4096") + DhGroupNumber = "16"; + else if (GlobalConfig->currentProfile->getIkeGroup() == "modp6144") + DhGroupNumber = "17"; + else if (GlobalConfig->currentProfile->getIkeGroup() == "modp8192") + DhGroupNumber = "18"; + + stream << " dh_group " + DhGroupNumber + ";" << "\n"; + + stream << " }" << "\n"; + + stream << "}" << "\n"; + stream << "" << "\n"; + + QString RemoteNetAddr = GlobalConfig->currentProfile->getRemoteNetAddr(); + QString RemoteNetMask = GlobalConfig->currentProfile->getRemoteNetMask(); + QString RemoteNet = RemoteNetAddr + "/" + RemoteNetMask; + + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon || ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon && GlobalConfig->currentProfile->getAuthType() == VpnAccountData::hybrid ) ) + stream << "sainfo anonymous {" << "\n"; + else + { + if ( GlobalConfig->currentProfile->getUseRemoteNetwork() ) + stream << "sainfo address " << VirtualLocalIP << " any subnet " << RemoteNet << " any {" << "\n"; + else + stream << "sainfo address " << VirtualLocalIP << " any address " << GlobalConfig->TmpGatewayIP << "/32 any {" << "\n"; + } + + // FIXME make dynamiclly + + stream << " lifetime time 1 hour;" << "\n"; + + if ( GlobalConfig->currentProfile->getUsePerfectForwardSecrety() ) + { + QString pfs_group = ""; +// if ( GlobalConfig->currentProfile->getPerfectForwardSecrety() == "server" ) +// pfs_group = ""; +// else if ( GlobalConfig->currentProfile->getPerfectForwardSecrety() == "nopfs" ) +// pfs_group = ""; +// else if ( GlobalConfig->currentProfile->getPerfectForwardSecrety() == "dh1" ) +// pfs_group = "1"; +// else if ( GlobalConfig->currentProfile->getPerfectForwardSecrety() == "dh2" ) +// pfs_group = "2"; +// else if ( GlobalConfig->currentProfile->getPerfectForwardSecrety() == "dh5" ) +// pfs_group = "5"; + + pfs_group = GlobalConfig->currentProfile->getPerfectForwardSecrety(); + + QString PFSGroupNumber = "2"; + if (pfs_group== "modp768") + PFSGroupNumber = "1"; + else if (pfs_group== "modp1024") + PFSGroupNumber = "2"; + else if (pfs_group== "modp1536") + PFSGroupNumber = "5"; + else if (pfs_group== "modp2048") + PFSGroupNumber = "14"; + else if (pfs_group== "modp3072") + PFSGroupNumber = "15"; + else if (pfs_group== "modp4096") + PFSGroupNumber = "16"; + else if (pfs_group== "modp6144") + PFSGroupNumber = "17"; + else if (pfs_group== "modp8192") + PFSGroupNumber = "18"; + if ( !pfs_group.isEmpty() ) + stream << " pfs_group " << PFSGroupNumber << ";\n"; + } + else + { + // racoon allows to empty this if no pfs is requested + //stream << " pfs_group modp768;" << "\n"; + } + + stream << " encryption_algorithm " << GlobalConfig->currentProfile->getEncryptionAlgorithm() << ";" << "\n"; +// if ( GlobalConfig->currentProfile->getAuthWithUsernameAndPassword()) + stream << " authentication_algorithm " << GlobalConfig->currentProfile->getAuthenticationAlgorithm() << ";" << "\n"; +// else +// stream << " authentication_algorithm " << GlobalConfig->currentProfile->getAuthenticationAlgorithm() << ", non_auth;" << "\n"; + + +// Utils::IpsecAlgos KernelCrypto = Utils ( GlobalConfig ).getKernelCrypto(); +// // phase 2 encr algos from kernel +// QString EncrAlgos=""; +// for ( QStringList::Iterator it = KernelCrypto.IpsecEspEncryptionAlgorithms.begin(); it != KernelCrypto.IpsecEspEncryptionAlgorithms.end(); ++it ) +// { +// if (EncrAlgos.length() > 0) +// EncrAlgos+=","; +// EncrAlgos+= QString(*it ); +// } +// +// +// // phase 2 auth algos from kernel +// QString AuthAlgos=""; +// for ( QStringList::Iterator it = KernelCrypto.IpsecEspAuthenticationAlgorithms.begin(); it != KernelCrypto.IpsecEspAuthenticationAlgorithms.end(); ++it ) +// { +// if (AuthAlgos.length() > 0) +// AuthAlgos+=","; +// AuthAlgos+= QString(*it ); +// } +// +// +// stream << " encryption_algorithm " << EncrAlgos << ";"<<"\n"; +// stream << " authentication_algorithm " << AuthAlgos << ";"<< "\n"; + + + stream << " compression_algorithm deflate;" << "\n"; + stream << "}" << "\n"; + + // stream << "listen {" << "\n"; + // + // //FIXME make own port useable + // stream << " isakmp " << LocalIP << ";" << "\n"; + // if ( GlobalConfig->currentProfile->getUseNat() ) + // { + // if ( GlobalConfig->currentProfile->getUseUdpPort() ) + // { + // stream << " # isakmp port for nat-t" << "\n"; + // stream << " isakmp_natt " << LocalIP << "["<< GlobalConfig->currentProfile->getUdpPort() << "];" << "\n"; + // } + // else + // { + // stream << " isakmp_natt " << LocalIP << ";" << "\n"; + // } + // } + // stream << "}" << "\n"; + file.close(); + stream.unsetDevice(); + } + + // write setkey..sh + file.setName ( tmpPath + "setkey." + ProfileName + ".sh" ); + stream.setDevice ( &file ); + if ( file.open ( IO_WriteOnly ) ) + { + stream << "#!"<< GlobalConfig->InterpreterShell << "\n"; + stream << "# generated by kvpnc. Do not edit it." << "\n"; + stream << "# profile: " + ProfileName << "\n"; + stream << "" << "\n"; + stream << "# run setkey" << "\n"; + stream << GlobalConfig->pathToSetkey << " -f " << tmpPath + "setkey." + GlobalConfig->currentProfile->getName() + ".conf" << "\n"; + file.close(); + stream.unsetDevice(); + } + + + // iptables need the right interface (eth0:1 => eth0) + QString tmpInterface2 = ""; + int pointPos = tmpInterface.find ( ':', 0, FALSE ); + if ( pointPos > 1 ) + { + tmpInterface2 = tmpInterface.left ( pointPos ); + } + else + tmpInterface2 = tmpInterface; + + // write iptables..sh + file.setName ( tmpPath + "iptables." + ProfileName + ".add_racoon.sh" ); + stream.setDevice ( &file ); + if ( file.open ( IO_WriteOnly ) + ) + { + stream << "#!"<< GlobalConfig->InterpreterShell << "\n" ; + stream << "# generated by kvpnc. Do not edit it." << "\n"; + stream << "# profile: " + ProfileName << "\n"; + stream << "" << "\n"; + stream << "# AH" << "\n"; + stream << GlobalConfig->pathToIptables << " -I INPUT -p 50 -i " << tmpInterface2 << " -s " << GlobalConfig->TmpGatewayIP << " -j ACCEPT" << "\n"; + stream << GlobalConfig->pathToIptables << " -I OUTPUT -p 50 -d " << GlobalConfig->TmpGatewayIP << " -j ACCEPT" << "\n"; + stream << "" << "\n"; + stream << "# ESP" << "\n"; + stream << GlobalConfig->pathToIptables << " -I INPUT -p 51 -i " << tmpInterface2 << " -s " << GlobalConfig->TmpGatewayIP << " -j ACCEPT" << "\n"; + stream << GlobalConfig->pathToIptables << " -I OUTPUT -p 51 -d " << GlobalConfig->TmpGatewayIP << " -j ACCEPT" << "\n"; + stream << "" << "\n"; + stream << "# IKE" << "\n"; + stream << GlobalConfig->pathToIptables << " -I INPUT -p udp --dport 500 -i " << tmpInterface2 << " -s " << GlobalConfig->TmpGatewayIP << " -j ACCEPT" << "\n"; + stream << GlobalConfig->pathToIptables << " -I OUTPUT -p udp --dport 500 -i " << tmpInterface2 << " -d " << GlobalConfig->TmpGatewayIP << " -j ACCEPT" << "\n"; + + stream << "" << "\n"; + stream << GlobalConfig->pathToIptables << " -I FORWARD -p udp --dport 500 -i " << tmpInterface2 << " -s " << GlobalConfig->TmpGatewayIP << " -j ACCEPT" << "\n"; + stream << GlobalConfig->pathToIptables << " -I FORWARD -p udp --dport 500 -i " << tmpInterface2 << " -d " << GlobalConfig->TmpGatewayIP << " -j ACCEPT" << "\n"; + + if ( GlobalConfig->currentProfile->getUseNat() ) + { + stream << "" << "\n"; + stream << "# NAT-T" << "\n"; + stream << GlobalConfig->pathToIptables << " -I INPUT -p udp --dport 4500 -i " << tmpInterface2 << " -s " << GlobalConfig->TmpGatewayIP << " -j ACCEPT" << "\n"; + stream << GlobalConfig->pathToIptables << " -I OUTPUT -p udp --sport 4500 -i " << tmpInterface2 << " -d " << GlobalConfig->TmpGatewayIP << " -j ACCEPT" << "\n"; + } + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { + stream << "" << "\n"; + stream << "# L2TP" << "\n"; + stream << GlobalConfig->pathToIptables << " -I INPUT -p udp --dport 1701 -i " << tmpInterface2 << " -s " << GlobalConfig->TmpGatewayIP << " -j ACCEPT" << "\n"; + stream << GlobalConfig->pathToIptables << " -I OUTPUT -p udp --sport 1701 -i " << tmpInterface2 << " -d " << GlobalConfig->TmpGatewayIP << " -j ACCEPT" << "\n"; + } + file.close(); + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" write failed!" ).arg ( file.name() ), GlobalConfig->error ); + setGuiStatus ( disconnected ); + return; + } + + stream.unsetDevice(); + + QFile file1 ( tmpPath + "iptables." + GlobalConfig->currentProfile->getName() + ".remove_racoon.sh" ); + QTextStream stream1 ( &file1 ); + if ( file1.open ( IO_WriteOnly ) ) + { + stream1 << "#!"<< GlobalConfig->InterpreterShell << "\n"; + stream1 << "# generated by kvpnc. Do not edit it." << "\n"; + stream1 << "# profile: " + ProfileName << "\n"; + stream1 << "" << "\n"; + stream1 << "# AH" << "\n"; + stream1 << GlobalConfig->pathToIptables << " -D INPUT -p 50 -i " << tmpInterface2 << " -s " << GlobalConfig->TmpGatewayIP << " -j ACCEPT" << "\n"; + stream1 << GlobalConfig->pathToIptables << " -D OUTPUT -p 50 -d " << GlobalConfig->TmpGatewayIP << " -j ACCEPT" << "\n"; + stream1 << "" << "\n"; + stream1 << "# ESP" << "\n"; + stream1 << GlobalConfig->pathToIptables << " -D INPUT -p 51 -i " << tmpInterface2 << " -s " << GlobalConfig->TmpGatewayIP << " -j ACCEPT" << "\n"; + stream1 << GlobalConfig->pathToIptables << " -D OUTPUT -p 51 -d " << GlobalConfig->TmpGatewayIP << " -j ACCEPT" << "\n"; + stream1 << "" << "\n"; + stream1 << "# IKE" << "\n"; + stream1 << GlobalConfig->pathToIptables << " -D INPUT -p udp --dport 500 -i " << tmpInterface2 << " -s " << GlobalConfig->TmpGatewayIP << " -j ACCEPT" << "\n"; + stream1 << GlobalConfig->pathToIptables << " -D OUTPUT -p udp --dport 500 -i " << tmpInterface2 << " -d " << GlobalConfig->TmpGatewayIP << " -j ACCEPT" << "\n"; + + stream1 << "" << "\n"; + stream1 << GlobalConfig->pathToIptables << " -D FORWARD -p udp --dport 500 -i " << tmpInterface2 << " -s " << GlobalConfig->TmpGatewayIP << " -j ACCEPT" << "\n"; + stream1 << GlobalConfig->pathToIptables << " -D FORWARD -p udp --dport 500 -i " << tmpInterface2 << " -d " << GlobalConfig->TmpGatewayIP << " -j ACCEPT" << "\n"; + + if ( GlobalConfig->currentProfile->getUseNat() ) + { + stream1 << "" << "\n"; + stream1 << "# NAT-T" << "\n"; + stream1 << GlobalConfig->pathToIptables << " -D INPUT -p udp --dport 4500 -i " << tmpInterface2 << " -s " << GlobalConfig->TmpGatewayIP << " -j ACCEPT" << "\n"; + stream1 << GlobalConfig->pathToIptables << " -D OUTPUT -p udp --sport 4500 -i " << tmpInterface2 << " -d " << GlobalConfig->TmpGatewayIP << " -j ACCEPT" << "\n"; + } + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { + stream1 << "" << "\n"; + stream1 << "# L2TP" << "\n"; + stream1 << GlobalConfig->pathToIptables << " -D INPUT -p udp --dport 1701 -i " << tmpInterface2 << " -s " << GlobalConfig->TmpGatewayIP << " -j ACCEPT" << "\n"; + stream1 << GlobalConfig->pathToIptables << " -D OUTPUT -p udp --sport 1701 -i " << tmpInterface2 << " -d " << GlobalConfig->TmpGatewayIP << " -j ACCEPT" << "\n"; + } + file1.close(); + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" write failed!" ).arg ( file1.name() ), GlobalConfig->error ); + setGuiStatus ( disconnected ); + return; + } + + + QFile upfile ( tmpPath+"racoon-"+ProfileName+".phase1-up.sh" ); + QTextStream upstream ( &upfile ); + if ( upfile.open ( IO_WriteOnly ) ) + { + upstream << "#!"<< GlobalConfig->InterpreterShell << "\n"; + upstream << "# generated by kvpnc. Do not edit it." << "\n"; + upstream << "# profile: " + ProfileName << "\n"; + upstream << "" << "\n"; + upstream << "echo \"STATE: phase1 up\"" << "\n"; + if ( GlobalConfig->currentProfile->getUseModeConfig() ) + { + upstream << "echo \"# modecfg data\" > "<< tmpPath << "/racoon-" << ProfileName << ".modecfg" << "\n"; + upstream << "\n"; + // An IPv4 internal address obtained by ISAKMP mode config + upstream << "echo \"INTERNAL_ADDR4=$INTERNAL_ADDR4\" >> " << tmpPath << "/racoon-" << ProfileName << ".modecfg" << "\n"; + upstream << "\n"; + // An IPv4 internal netmask obtained by ISAKMP mode config + upstream << "echo \"INTERNAL_NETMASK4=$INTERNAL_NETMASK4\" >> "<< tmpPath << "/racoon-" << ProfileName << ".modecfg" << "\n"; + upstream << "\n"; + // An IPv4 internal netmask obtained by ISAKMP mode config, in CIDR notation + upstream << "echo \"INTERNAL_CIDR4=$INTERNAL_CIDR4\" >> "<< tmpPath << "/racoon-" << ProfileName << ".modecfg" << "\n"; + upstream << "\n"; + // The first internal DNS server IPv4 address obtained by ISAKMP mode config. + upstream << "echo \"INTERNAL_DNS4=$INTERNAL_DNS4\" >> "<< tmpPath << "/racoon-" << ProfileName << ".modecfg" << "\n"; + upstream << "\n"; + // A list of internal DNS servers IPv4 address obtained by ISAKMP mode config, separated by spaces + upstream << "echo \"INTERNAL_DNS4_LIST=$INTERNAL_DNS4_LIST\" >> "<< tmpPath << "/racoon-" << ProfileName << ".modecfg" << "\n"; + upstream << "\n"; + // The first internal WINS server IPv4 address obtained by ISAKMP mode config + upstream << "echo \"INTERNAL_WINS4=$INTERNAL_WINS4\" >> "<< tmpPath << "/racoon-" << ProfileName << ".modecfg" << "\n"; + upstream << "\n"; + // A list of internal WINS servers IPv4 address obtained by ISAKMP mode config, separated by spaces + upstream << "echo \"INTERNAL_WINS4_LIST=$INTERNAL_WINS4_LIST\" >> "<< tmpPath << "/racoon-" << ProfileName << ".modecfg" << "\n"; + upstream << "\n"; + // The space separated list of IPv4 addresses and masks (address slash mask) that define the networks to be encrypted (as opposed to the default where all the traffic should be encrypted) ; obtained by ISAKMP mode config ; SPLIT_INCLUDE and SPLIT_LOCAL are mutually exclusive + upstream << "echo \"SPLIT_INCLUDE=$SPLIT_INCLUDE\" >> "<< tmpPath << "/racoon-" << ProfileName << ".modecfg" << "\n"; + upstream << "\n"; + // The space separated list of IPv4 addresses and masks (address slash mask) that define the networks to be considered local, and thus excluded from the tunnels ; obtained by ISAKMP mode config + upstream << "echo \"SPLIT_LOCAL=$SPLIT_LOCAL\" >> "<< tmpPath << "/racoon-" << ProfileName << ".modecfg" << "\n"; + upstream << "\n"; + // The DNS default domain name obtained by ISAKMP mode config + upstream << "echo \"DEFAULT_DOMAIN=$DEFAULT_DOMAIN\" >> "<< tmpPath << "/racoon-" << ProfileName << ".modecfg" << "\n"; + + + // listing known IP addresses and setting PATH environment variable + // internal address in local network + upstream << "echo \"internal address: ${INTERNAL_ADDR4}\"" << "\n"; + + // current global IP address + upstream << "echo \"local address: ${LOCAL_ADDR}\"" << "\n"; + + // VPN gateway IP address + upstream << "echo \"remote address: $REMOTE_ADDR\"" << "\n"; + upstream << "PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin" << "\n"; + + if ( GlobalConfig->currentProfile->getUseModeConfig() ) + { + // defining variable to hold the name of virtual network interface + upstream << "if="+tmpInterface << "\n"; + + // adding internal IP address to virtual network interface + upstream << "" << GlobalConfig->pathToIp << " address add dev ${if} ${INTERNAL_ADDR4}" << "\n"; + } + + // deleting default route +// upstream << "" << GlobalConfig->pathToIp << " route del default" << "\n"; + + // adding route to VPN gateway + upstream << "" << GlobalConfig->pathToIp << " route add ${REMOTE_ADDR} via " << GlobalConfig->TmpGatewayIP << "\n"; + + // adding default route with new source address +// upstream << "ip route add default via " << GlobalConfig->TmpGatewayIP << " src ${INTERNAL_ADDR4}" << "\n"; + + // deleting existing route towards local network +// upstream << "ip route delete 192.168.112.0/24 via " << GlobalConfig->TmpGatewayIP << " dev "+tmpInterface+"" << "\n"; + + // deleting existing route towards Internet +// upstream << "ip route delete 192.168.111.0/24 dev "+tmpInterface+"" << "\n"; + + // setting SPs form local network address towards all other IP addresses through tunnel + // from roadwarrior client to VPN gateway, and vice verse, and also deleting the forwarding SP + upstream << "echo \"\"" << "\n"; +// upstream << "spdadd ${INTERNAL_ADDR4}/32[any] 0.0.0.0/0[any] any" << "\n"; +// upstream << " -P out ipsec esp/tunnel/${LOCAL_ADDR}-${REMOTE_ADDR}/require;" << "\n"; +// upstream << "spdadd 0.0.0.0/0[any] ${INTERNAL_ADDR4}[any] any" << "\n"; +// upstream << " -P in ipsec esp/tunnel/${REMOTE_ADDR}-${LOCAL_ADDR}/require;" << "\n"; +// upstream << "\" | " << GlobalConfig->pathToSetkey << " -c" << "\n"; +// upstream << "echo \"" << "\n"; +// upstream << "spddelete 0.0.0.0/0[any] ${INTERNAL_ADDR4}[any] any" << "\n"; +// upstream << " -P fwd ipsec esp/tunnel/${REMOTE_ADDR}-${LOCAL_ADDR}/require;" << "\n"; +// upstream << "\" | setkey -c" << "\n"; + + upstream << "echo \"STATE: upscript finished\"" << "\n"; + + + } + + upfile.close(); + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" write failed!" ).arg ( upfile.name() ), GlobalConfig->error ); + setGuiStatus ( disconnected ); + return; + } + + + QFile downfile ( tmpPath+"racoon-"+ProfileName+".phase1-down.sh" ); + QTextStream downstream ( &downfile ); + if ( downfile.open ( IO_WriteOnly ) ) + { + downstream << "#!"<< GlobalConfig->InterpreterShell << "\n"; + downstream << "# generated by kvpnc. Do not edit it." << "\n"; + downstream << "# profile: " + ProfileName << "\n"; + downstream << "" << "\n"; + downstream << "echo \"STATE: phase1 down\"" << "\n"; + + // listing known IP addresses and setting PATH environment variable + downstream << "echo \"----------------\"" << "\n"; + downstream << "echo \"internal address: ${INTERNAL_ADDR4}\"" << "\n"; + downstream << "echo \"local address: ${LOCAL_ADDR}\"" << "\n"; + downstream << "echo \"remote address: $REMOTE_ADDR\"" << "\n"; + downstream << "PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin" << "\n"; + + if ( GlobalConfig->currentProfile->getUseModeConfig() ) + { + // defining variable to hold the name of virtual network interface + downstream << "if="+tmpInterface << "\n"; + + // deleting internal IP address from virtual network interface + downstream << "ip address delete ${INTERNAL_ADDR4} dev ${if}" << "\n"; + } + + // deleting route towards VPN gateway" << "\n"; + downstream << "ip route delete ${REMOTE_ADDR} via " << GlobalConfig->TmpGatewayIP << "" << "\n"; + + // adding default route through network interface + //downstream << "ip route add default dev "+tmpInterface+"" << "\n"; + + // adding routes towards local network and Internet + // downstream << "ip route add 192.168.112.0/24 via " << GlobalConfig->TmpGatewayIP << " dev "+tmpInterface+"" << "\n"; + //downstream << "ip route add 192.168.111.0/24 dev "+tmpInterface+" src ${LOCAL_ADDR}" << "\n"; + + // flushing SPD and SAD + downstream << GlobalConfig->pathToSetkey << " -F" << "\n"; + downstream << GlobalConfig->pathToSetkey << " -FP" << "\n"; + + downstream << "echo \"STATE: downscript finished\"" << "\n"; + + + downfile.close(); + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" write failed!" ).arg ( downfile.name() ), GlobalConfig->error ); + setGuiStatus ( disconnected ); + return; + } + + Utils ( GlobalConfig, this ).doChmod ( tmpPath+"racoon-"+ProfileName+".phase1-up.sh","a+x" ); + Utils ( GlobalConfig, this ).doChmod ( tmpPath+"racoon-"+ProfileName+".phase1-down.sh" ,"a+x" ); + + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::psk ) + { + // write iptables..sh + file.setName ( tmpPath + "psk." + GlobalConfig->currentProfile->getName() + ".key" ); + stream.setDevice ( &file ); + if ( file.open ( IO_WriteOnly ) ) + { + stream << "# generated by kvpnc. Do not edit it." << "\n"; + stream << "# profile: " + ProfileName << "\n"; + + } + if ( GlobalConfig->currentProfile->getPskIsInFile() ) + { + stream << GlobalConfig->TmpGatewayIP + "\t" + GlobalConfig->TmpGroupPassword << "\n"; + } + else + { + if ( GlobalConfig->currentProfile->getSavePsk() && !GlobalConfig->currentProfile->getPreSharedKey().isEmpty() ) + stream << GlobalConfig->TmpGatewayIP + "\t" + GlobalConfig->currentProfile->getPreSharedKey() << "\n"; + else + stream << GlobalConfig->TmpGatewayIP + "\t" + GlobalConfig->TmpGroupPassword << "\n"; + } + + file.close(); + stream.unsetDevice(); + } + + // if (GlobalConfig->currentProfile->useVirtualIP()){ + // if (!setVirtualIP()){ + // setGuiStatus(disconnected); + // return; + // } + // + // } + + setenv ( "DNS_UPDATE", ( GlobalConfig->currentProfile->getUseDnsUpdate() ? "Yes" : "NO" ), 1 ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Setting DNS_UPDATE \"%1\"." ).arg ( getenv ( "DNS_UPDATE" ) ), GlobalConfig->debug ); + + if ( useL2tpAfterFirstConnection ) + prepareL2tpd(); + + Utils ( GlobalConfig ).doChmod ( tmpPath + "psk." + GlobalConfig->currentProfile->getName() + ".key", "go-rwx" ); + + OpenL2tpProcess=0L; + L2tpdProcess=0L; + + RacoonHelperProcess = new QProcess ( this ); + // + RacoonHelperProcess->addArgument ( GlobalConfig->InterpreterShell ); + RacoonHelperProcess->addArgument ( tmpPath + "/setkey." + GlobalConfig->currentProfile->getName() + ".sh" ); + + connect ( RacoonHelperProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_racoon_helper() ) ); + connect ( RacoonHelperProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_racoon_helper() ) ); + connect ( RacoonHelperProcess, SIGNAL ( processExited () ), this, SLOT ( doRacoon() ) ); + + if ( !RacoonHelperProcess->start ( env ) ) + { + disconnect ( RacoonHelperProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_racoon_helper() ) ); + disconnect ( RacoonHelperProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_racoon_helper() ) ); + disconnect ( RacoonHelperProcess, SIGNAL ( processExited () ), this, SLOT ( doRacoon() ) ); + delete RacoonHelperProcess; + RacoonHelperProcess =0L; + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "setkey" ), GlobalConfig->error ); + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( "setkey." + GlobalConfig->currentProfile->getName() + ".sh" ) ); + setGuiStatus ( disconnected ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( "setkey" ), GlobalConfig->debug ); + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) + ConnectingProcess = VpnAccountData::racoon; + else + ConnectingProcess = VpnAccountData::l2tpd_racoon; + GlobalConfig->status = GlobalConfig->connecting; + mw->buttonDisconnect->setEnabled ( true ); + this->DisconnectAction->setEnabled ( true ); + mw->buttonConnect->setEnabled ( false ); + this->ConnectAction->setEnabled ( false ); + +// doRacoon(); + } + } + else + { + disconnectClicked(); + } + } // racoon + + /* ============ ipsec ================ */ + else if ( GlobalConfig->currentProfile != 0 && GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan || + GlobalConfig->currentProfile != 0 && GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { + + if ( GlobalConfig->currentConnectRetry > GlobalConfig->maxConnectRetry ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Max connect retries (%1) reached, stopping." ).arg ( QString().setNum ( GlobalConfig->maxConnectRetry ) ), GlobalConfig->debug ); + return; + } + + //setGuiStatus(connecting); + + // looking for ipsec + + if ( Utils ( GlobalConfig ).getToolInfo ( "ipsec" )->found == false ) + { + KMessageBox::error ( this, i18n ( "Unable to find \"%1\" at \"%2\"!" ).arg ( "ipsec (" + IpsecType + ")" ).arg ( GlobalConfig->pathToIpsec ) ); + GlobalConfig->appendLogEntry ( i18n ( "Unable to find \"%1\" at \"%2\"!" ).arg ( "ipsec (" + IpsecType + ")" ).arg ( GlobalConfig->pathToIpsec ), GlobalConfig->error ); + ok = false; + setGuiStatus ( disconnected ); + return ; + } + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { + if ( Utils ( GlobalConfig ).getToolInfo ( "l2tpd" )->found == false && Utils ( GlobalConfig ).getToolInfo ( "xl2tpd" )->found == false ) + { + KMessageBox::error ( this, i18n ( "Unable to find \"%1\" or \"%2\"!" ).arg ( "l2tpd" ).arg ( "xl2tpd" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Unable to find \"%1\" or \"%2\"!" ).arg ( "l2tpd" ).arg ( "xl2tpd" ), GlobalConfig->error ); + ok = false; + setGuiStatus ( disconnected ); + return ; + } + } + + + GlobalConfig->TmpGatewayIP = Utils ( GlobalConfig, parent ).resolveName ( GlobalConfig->currentProfile->getGateway() ); + if ( GlobalConfig->TmpGatewayIP == "0.0.0.0" ) + { + KMessageBox::error ( this, i18n ( "Host \"%1\" could not be resolved!" ).arg ( GlobalConfig->currentProfile->getGateway() ) ); + GlobalConfig->appendLogEntry ( i18n ( "Host \"%1\" could not be resolved!" ).arg ( GlobalConfig->currentProfile->getGateway() ), GlobalConfig->error ) ; + ok = false; + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "Gateway hostname (%1) resolved to \"%2\"." ).arg ( GlobalConfig->currentProfile->getGateway() ).arg ( GlobalConfig->TmpGatewayIP ), GlobalConfig->info ); + } + + if ( GlobalConfig->currentProfile->authtype == VpnAccountData::cert ) + { + if ( !GlobalConfig->currentProfile->getUseSmartcard() ) + { + QFile CertTmpFile; + CertTmpFile.setName ( GlobalConfig->currentProfile->getX509Certificate() ); + if ( !CertTmpFile.exists() ) + { + KMessageBox::error ( 0, i18n ( "Certificate file (%1) could not be found. Please check the path of it." ).arg ( GlobalConfig->currentProfile->getCertPath() ), i18n ( "File Not Found" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Certificate file (%1) could not be found. Please check the path of it." ).arg ( GlobalConfig->currentProfile->getX509Certificate() ), GlobalConfig->error ); + ok = false; + } + } + + QFile CertTmpFile; + CertTmpFile.setName ( GlobalConfig->currentProfile->getCaCertificate() ); + if ( !CertTmpFile.exists() ) + { + KMessageBox::error ( 0, i18n ( "CA certificate file (%1) could not be found. Please check the path of it." ).arg ( GlobalConfig->currentProfile->getCaCertificate() ), i18n ( "File Not Found" ) ); + GlobalConfig->appendLogEntry ( i18n ( "CA certificate file (%1) could not be found. Please check the path of it." ).arg ( GlobalConfig->currentProfile->getCaCertificate() ), GlobalConfig->error ); + ok = false; + } + } + + // if ( !Utils( GlobalConfig, parent ).loadKernelModule( "esp4", parent ) ) + // { + // KMessageBox::information( this, i18n( "Loading of module \"%1\" failed!" ).arg( "esp4" ) ); + // GlobalConfig->appendLogEntry( i18n( "Loading module \"%1\" has failed: stop." ).arg( "esp4" ), GlobalConfig->error ); + // ok = false; + // } + // + // if ( !Utils( GlobalConfig, parent ).loadKernelModule( "ah4", parent ) ) + // { + // KMessageBox::information( this, i18n( "Loading of module \"%1\" failed!" ).arg( "ah4" ) ); + // GlobalConfig->appendLogEntry( i18n( "Loading module \"%1\" has failed: stop." ).arg( "ah4" ), GlobalConfig->error ); + // ok = false; + // } + + + + + bool askUsernamePass = false; + bool askPsk = false; + + if ( !GlobalConfig->haveUserData ) + { + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::psk && ( GlobalConfig->currentProfile->getSavePsk() == false || GlobalConfig->currentProfile->getPreSharedKey().isEmpty() ) && GlobalConfig->currentProfile->getAllowEmptyPrivateKeyPassword() == false ) + { + askUsernamePass = false; + askPsk = true; + } + } + + // L2TP/XAUTH + if ( GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) + { + GlobalConfig->TmpUsername = GlobalConfig->currentProfile->getUserName(); + GlobalConfig->TmpPassword = GlobalConfig->currentProfile->getUserPassword(); + + if ( GlobalConfig->TmpPassword.isEmpty() || GlobalConfig->TmpUsername.isEmpty() ) + askUsernamePass=true; + + if ( !GlobalConfig->currentProfile->getPskIsInFile() ) + GlobalConfig->TmpGroupPassword = GlobalConfig->currentProfile->getPreSharedKey(); + else + { + QFile PskFile ( GlobalConfig->currentProfile->getPreSharedKeyFile() ); + if ( PskFile.open ( IO_ReadOnly ) ) + { + QString PskFileContent = QString ( PskFile.readAll() ); + PskFile.close(); + GlobalConfig->TmpGroupPassword = PskFileContent; + } + } + GlobalConfig->WaitingForXauth=false; + } + + + + if ( AuthRetry ) + askUsernamePass = true; + + if ( !GlobalConfig->haveUserData ) + { + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan && ( !GlobalConfig->currentProfile->getSaveUserPassword() && GlobalConfig->currentProfile->getUserName().isEmpty() || GlobalConfig->currentProfile->getUserPassword().isEmpty() ) ) + askUsernamePass = true; + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 4 ) + GlobalConfig->appendLogEntry ( i18n ( "User data already collected." ), GlobalConfig->debug ); + } + + if ( GlobalConfig->currentProfile->getAskUserPasswordOnEachConnect() ) + { + if ( GlobalConfig->KvpncDebugLevel > 4 ) + GlobalConfig->appendLogEntry ( i18n ( "User password on each connect forced." ), GlobalConfig->debug ); + + askUsernamePass = true; + } + + + if ( askUsernamePass || askPsk ) + { + bool requestUsername = false; + EnterUsernamePasswordDialog dlg ( this, i18n ( "Enter Account Data" ), askPsk, askUsernamePass ); + if ( askUsernamePass ) + { + requestUsername = GlobalConfig->TmpUsername.isEmpty(); + + if ( !GlobalConfig->TmpUsername.isEmpty() ) + { + dlg.main->UsernameEdit->setText ( GlobalConfig->TmpUsername ); + if ( !GlobalConfig->currentProfile->getDontSaveUsername() ) + dlg.main->SaveUsernameCheckBox->setChecked ( true ); + } + else + dlg.main->UsernameEdit->setFocus(); + dlg.main->LabelGroupPassword->setText ( i18n ( "PSK:" ) ); + + if ( !GlobalConfig->TmpPassword.isEmpty() ) + { + dlg.main->PasswordEdit->setText ( GlobalConfig->TmpPassword ); + if ( GlobalConfig->currentProfile->getSaveUserPassword() ) + dlg.main->SaveUsernameCheckBox->setChecked ( true ); + } + else + if ( !GlobalConfig->TmpUsername.isEmpty() ) + dlg.main->PasswordEdit->setFocus(); + } + else + { + GlobalConfig->TmpUsername = GlobalConfig->currentProfile->getUserName(); + GlobalConfig->TmpPassword = GlobalConfig->currentProfile->getUserName(); + } + if ( askPsk ) + { + if ( !GlobalConfig->currentProfile->getPreSharedKey().isEmpty() ) + { + dlg.main->PSKLineEdit->setText ( GlobalConfig->currentProfile->getPreSharedKey() ); + if ( GlobalConfig->currentProfile->getSavePsk() ) + dlg.main->SavePskCheckBox->setChecked ( true ); + } + else + if ( !GlobalConfig->currentProfile->getUserPassword().isEmpty() ) + dlg.main->PSKLineEdit->setFocus(); + if ( !askUsernamePass ) + { + dlg.main->PasswordEdit->hide(); + dlg.main->UsernameEdit->hide(); + dlg.main->LabelPassword->hide(); + dlg.main->LabelUsername->hide(); + dlg.main->SavePasswordCheckBox->hide(); + dlg.main->SaveUsernameCheckBox->hide(); + } + else + { + GlobalConfig->TmpUsername = GlobalConfig->currentProfile->getUserName(); + GlobalConfig->TmpPassword = GlobalConfig->currentProfile->getUserName(); + } + } + else + { + dlg.main->LabelGroupPassword->hide(); + dlg.main->PSKLineEdit->hide(); + } + + // dlg.main->SaveValuesCheckBox->setChecked( GlobalConfig->currentProfile->getSaveUserPassword() || !GlobalConfig->currentProfile->getDontSaveUsername() ); + + if ( dlg.exec() ) + { + bool needSave = false; + GlobalConfig->TmpGroupPassword = dlg.main->PSKLineEdit->text(); + GlobalConfig->TmpUsername = dlg.main->UsernameEdit->text(); + GlobalConfig->TmpPassword = dlg.main->PasswordEdit->text(); + + // FIXME + if ( askPsk || AuthRetry ) + { + if ( ( GlobalConfig->currentProfile->getSavePsk() && GlobalConfig->currentProfile->getPreSharedKey().isEmpty() ) && GlobalConfig->TmpGroupPassword.isEmpty() ) + { + GlobalConfig->appendLogEntry ( i18n ( "PSK is empty!" ), GlobalConfig->error ); + ok = false; + } + } + if ( askUsernamePass ) + { + if ( dlg.main->SavePasswordCheckBox->isChecked() ) + { + GlobalConfig->currentProfile->setSaveUserPassword ( true ); + GlobalConfig->currentProfile->setUserPassword ( GlobalConfig->TmpPassword ); + needSave = true; + } + else + { + GlobalConfig->currentProfile->setSaveUserPassword ( false ); + needSave = true; + } + } + if ( askPsk ) + { + if ( dlg.main->SavePskCheckBox->isChecked() ) + { + GlobalConfig->currentProfile->setSavePsk ( true ); + + if ( !GlobalConfig->currentProfile->getPskIsInFile() ) + { + GlobalConfig->currentProfile->setPreSharedKey ( GlobalConfig->TmpGroupPassword ); + needSave = true; + } + else + { + QFile PskFile ( GlobalConfig->currentProfile->getPreSharedKeyFile() ); + if ( PskFile.open ( IO_WriteOnly ) ) + { + QTextStream stream; + stream.setDevice ( &PskFile ); + stream << GlobalConfig->TmpGroupPassword; + PskFile.close(); + } + } + + } + else + { + GlobalConfig->currentProfile->setSavePsk ( false ); + needSave = true; + } + } + + if (needSave) + GlobalConfig->saveOptions(true, GlobalConfig->currentProfile->getName()); + + // if ( /*GlobalConfig->currentProfile->getAuthType() == VpnAccountData::cert && */GlobalConfig->currentProfile->getUseMailAddressAsIdentifier() && Utils( GlobalConfig ).getEmailAddressOfCert( GlobalConfig->currentProfile->getX509Certificate()).isEmpty()) + // { + // GlobalConfig->appendLogEntry( i18n( "Mail address could not read from certificate!" ), GlobalConfig->error ); + // ok = false; + // } + + if ( ok ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Some account data which is needed got from password enter dialog." ), GlobalConfig->debug ); + // saveSessionClicked(); + } + GlobalConfig->haveUserData=true; + } + else + { + ok = false; + AuthRetry = false; + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Connect canceled because account data dialog aborted." ), GlobalConfig->debug ); + } + } + + + if ( GlobalConfig->currentProfile->getPskIsInFile() ) + { + QFile f ( GlobalConfig->currentProfile->getPreSharedKeyFile() ); + if ( f.open ( IO_ReadOnly ) ) + { + QTextStream stream ( &f ); + QString line = ""; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' + if ( !line.find ( '#', 0 ) < 0 ) + { + GlobalConfig->TmpGroupPassword = line; + break; + } + } + f.close(); + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "PSK could not read from file because PSK key file %1 could not be read." ).arg ( GlobalConfig->currentProfile->getPreSharedKeyFile() ), GlobalConfig->error ); + ok = false; + } + if ( GlobalConfig->TmpGroupPassword.isEmpty() ) + { + GlobalConfig->appendLogEntry ( i18n ( "PSK could not read from file because PSK key file %1 contains no key." ).arg ( GlobalConfig->currentProfile->getPreSharedKeyFile() ), GlobalConfig->error ); + ok = false; + } + } + + QString leftid = ""; + QString rightid = ""; + + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::cert && GlobalConfig->currentProfile->getUseSmartcard() ) + { + GlobalConfig->TmpPassword = ""; + QCString password; + QString pass = ""; + Pkcs11PIN = ""; + + GlobalConfig->TmpPrivateKeyPass = ""; + EnterXauthInteractivePasscodeDialog dlg ( 0); + dlg.setCaption(i18n ( "Enter smartcard PIN" ) ); + dlg.main->DescriptionLabel->setText ( i18n ( "Enter PIN for unlocking smartcard \"%1\":" ).arg ( GlobalConfig->currentProfile->getPkcs11Slot() ) ); + dlg.main->LabelPassword->setText ( i18n ( "PIN:" ) ); + dlg.main->SavePasswordCheckBox->hide(); + dlg.main->adjustSize(); + dlg.adjustSize(); + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( "[ipsec] " + i18n ( "PIN for unlocking smartcard requested...\n" ), GlobalConfig->debug ); + if ( dlg.exec() ) + { + + pass = dlg.main->PasswordEdit->text(); + if ( !pass.isEmpty() ) + { + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( "[ipsec]: " + i18n ( "PIN got from user" ), GlobalConfig->debug ); + + + GlobalConfig->TmpPrivateKeyPass = QString ( pass ); + Pkcs11PIN = GlobalConfig->TmpPrivateKeyPass; + } + else + { + GlobalConfig->appendLogEntry ( "[ipsec]: PIN empty, stop.", GlobalConfig->error ); + ok = false; + } + } + else + { + GlobalConfig->appendLogEntry ( "[ipsec]: password dialog canceled and password empty, stop.", GlobalConfig->info ); + ok = false; + } + } + + // // here we go + if ( ok ) + { + + backupDefaultRoute(); + + if ( GlobalConfig->currentProfile->getExecuteCmdBeforeConnect() ) + executeCommandBeforeConnect(); + + QString tmpInterface; + QString LocalIP; + NetworkInterface iface ( GlobalConfig, parent ); + if ( GlobalConfig->currentProfile->getNetworkDevice() == "default" || GlobalConfig->currentProfile->getNetworkDevice() == "" ) + { + tmpInterface = iface.getDefaultInterface(); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Default interface: \"%1\"." ).arg ( tmpInterface ) , GlobalConfig->debug ); + LocalIP = iface.getInterfaceIP ( iface.getDefaultInterface() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "IP address of default interface: \"%1\"." ).arg ( LocalIP ) , GlobalConfig->debug ); + } + else + { + tmpInterface = GlobalConfig->currentProfile->getNetworkDevice(); + LocalIP = iface.getInterfaceIP ( GlobalConfig->currentProfile->getNetworkDevice() ); + } + if ( tmpInterface.isEmpty() ) + tmpInterface = "lo"; // no default interface found :( + + if ( LocalIP.isEmpty() ) + LocalIP = "127.0.0.1"; // no IP for default interface found :( + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + { + GlobalConfig->appendLogEntry ( "default interface: " + tmpInterface, GlobalConfig->debug ); + GlobalConfig->appendLogEntry ( "LocalIP: " + LocalIP, GlobalConfig->debug ); + } + + QString Gateway = GlobalConfig->currentProfile->getGateway(); + QString RemoteNetAddr = GlobalConfig->currentProfile->getRemoteNetAddr(); + QString RemoteNetMask = GlobalConfig->currentProfile->getRemoteNetMask(); + QString RemoteNet=""; + if ( !RemoteNetAddr.isEmpty() ) + RemoteNet = RemoteNetAddr + "/" + RemoteNetMask; + QString LocalNetAddr = LocalIP; + QString LocalNetMask = "/32"; + QString LocalNet=""; + + tmpPath = locateLocal ( "data", "kvpnc/" ); // should be + // KTempDir tmpdir; + // tmpPath = tmpdir.name(); + // if (GlobalConfig->KvpncDebugLevel > 0) + // GlobalConfig->appendLogEntry( "tmppath: " + tmpPath, GlobalConfig->debug ); + + QString ProfileName = GlobalConfig->currentProfile->getName(); + QString CertPath = GlobalConfig->currentProfile->getCertPath(); + QString PrivateKeyPass = GlobalConfig->currentProfile->getPrivateKeyPass(); + QString PrivateKey = GlobalConfig->currentProfile->getPrivateKey(); + + startStopIpsec ( true ); + backupIpsecSystemConfig(); + + QString IpsecPrefix = "/etc"; + + // write /etc/ipsec.secrets + QFile IpsecSecretsFile ( IpsecPrefix + "/ipsec.secrets" ); // warning: static + QTextStream stream ( &IpsecSecretsFile ); + if ( IpsecSecretsFile.open ( IO_WriteOnly ) ) + { + // cert + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::cert ) + { + stream << "# generated by kvpnc. Do not edit it." << "\n"; + stream << "# profile: " + ProfileName << "\n"; + if ( !GlobalConfig->currentProfile->getUseSmartcard() ) + stream << ": RSA " + GlobalConfig->currentProfile->getPrivateKey() + " \"" + GlobalConfig->currentProfile->getPrivateKeyPass() + "\"\n"; + else + { + stream << ": PIN %smartcard \"" << Pkcs11PIN << "\"" << "\n"; + // stream << ": PIN %smartcard \"123456\"" << "\n"; + // stream << ": PIN %smartcard %prompt" << "\n"; + + } + + // mw->DebugOutput->append( "cert: private key: : RSA " + PrivateKey + " \"" + PrivateKeyPass ); + } + // PSK + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::psk ) + { + stream << "# generated by kvpnc. Do not edit it." << "\n"; + stream << "# profile: " + ProfileName << "\n"; + + if ( !GlobalConfig->currentProfile->getPskIsInFile() ) + { + GlobalConfig->appendLogEntry ( QString("ipsec: "+ IpsecToolInfo->Version ),GlobalConfig->debug ); + if ( !GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) + { +// if ( !GlobalConfig->currentProfile->getUseSpecialLocalID()) +// stream << "" << GlobalConfig->TmpGatewayIP << " : PSK \"" + GlobalConfig->currentProfile->getPreSharedKey() + "\"\n"; +// else + stream << "" << GlobalConfig->TmpGatewayIP << " " << GlobalConfig->currentProfile->getSpecialLocalID() << " : PSK \"" + GlobalConfig->currentProfile->getPreSharedKey() + "\"\n"; + } + else if ( ( IpsecToolInfo->Version.contains ( "Openswan", false ) && GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan && GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) ) + { + // XAUTH openswan + stream << GlobalConfig->TmpGatewayIP <<" @" << GlobalConfig->currentProfile->getID() << " : PSK \""+GlobalConfig->currentProfile->getPreSharedKey() +"\"\n"; + } + else if ( ( IpsecToolInfo->Version.contains ( "strongSwan", false ) && GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan && GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) ) + { + // XAUTH strongSwan + stream << ": PSK \"" + GlobalConfig->currentProfile->getPreSharedKey() + "\"\n"; + stream << ": XAUTH \""+GlobalConfig->TmpUsername+"\" \""+GlobalConfig->TmpPassword+"\""+"\n"; + } + } + else + { + QFile PskFile ( GlobalConfig->currentProfile->getPreSharedKeyFile() ); + if ( PskFile.open ( IO_ReadOnly ) ) + { + QString PskFileContent = QString ( PskFile.readAll() ); + PskFile.close(); + if ( !GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) + { + // normal + stream << ": PSK \"" + PskFileContent + "\"\n"; + } + else if ( ( IpsecToolInfo->Version.contains ( "Openswan", false ) && GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan && GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) ) + { + // XAUTH + stream << GlobalConfig->TmpGatewayIP <<" @" << GlobalConfig->currentProfile->getID() << " : PSK \""+PskFileContent+"\"\n"; + } + else if ( ( IpsecToolInfo->Version.contains ( "strongSwan", false ) && GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan && GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) ) + { + // XAUTH strongSwan + stream << ": PSK \"" + PskFileContent + "\"\n"; + stream << ": XAUTH \""+GlobalConfig->TmpUsername+"\" \""+GlobalConfig->TmpPassword+"\""+"\n"; + } + } + } + + } + IpsecSecretsFile.close(); + + if ( GlobalConfig->KvpncDebugLevel > 6 ) + { + GlobalConfig->appendLogEntry ( i18n ( "---- %1 ---" ).arg ( IpsecSecretsFile.name() ),GlobalConfig->debug ); + if ( IpsecSecretsFile.open ( IO_ReadOnly ) ) + { + QTextStream stream ( &IpsecSecretsFile ); + QString line; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' + GlobalConfig->appendLogEntry ( line,GlobalConfig->debug ); + } + IpsecSecretsFile.close(); + } + else + GlobalConfig->appendLogEntry ( i18n ( "%1 could not opened. Stop." ).arg ( IpsecSecretsFile.name() ),GlobalConfig->error ); + GlobalConfig->appendLogEntry ( i18n ( "---- end ---" ),GlobalConfig->debug ); + } + + ToolInfo *tool = Utils ( GlobalConfig ).getToolInfo ( "ipsec" ); + QString realversion = tool->Version.section ( ' ', 1, 1 ).section ( '/', 0, 0 ).right ( tool->Version.section ( ' ', 1, 1 ).section ( '/', 0, 0 ).length() - 1 ); + int IpsecMajor= realversion.section ( '.',0,0 ).toInt(); + int IpsecMinor= realversion.section ( '.',1,1 ).toInt(); + int IpsecSubMinor= realversion.section ( '.',2,2 ).toInt(); + QString realtype = tool->Version.section ( ' ', 0, 0 ).lower(); + + // write /etc/ipsec.conf + //file.setName( tmpPath + "freeswan." + ProfileName + ".conf" ) + QFile IpsecConfigFile ( IpsecPrefix + "/ipsec.conf" ); // warning: static + if ( IpsecConfigFile.open ( IO_WriteOnly ) ) + { + + stream.setDevice ( &IpsecConfigFile ); + stream << "# generated by kvpnc. Do not edit it." << "\n"; + stream << "# profile: " + ProfileName << "\n"; + stream << "# right: remote" << "\n"; + stream << "# left: local" << "\n"; + stream << "" << "\n"; + + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "IPSec version: %1.%2.%3" ).arg ( QString::number ( IpsecMajor ) ).arg ( QString::number ( IpsecMinor ) ).arg ( QString::number ( IpsecSubMinor ) ),GlobalConfig->debug ); + +// if ( realversion.find ( "2.", 0, -1 ) > -1 ) + if ( !IpsecType.contains ( "free", false ) ) // only version 2 + { + stream << "version 2" << "\n"; + } + + stream << "config setup" << "\n"; + if ( GlobalConfig->currentProfile->getNetworkDevice() == "default" ) + stream << " interfaces=%defaultroute" << "\n"; + else + stream << " interfaces=\"ipsec0=" << tmpInterface << "\"" << "\n"; + + if ( GlobalConfig->currentProfile->getUseSmartcard() /*&& IpsecType.contains( "strongSwan", false )*/ ) + stream << " pkcs11module=" + GlobalConfig->currentProfile->getPkcs11Providers() + "\n"; + + if ( GlobalConfig->currentProfile->getUseVirtualSubnetworks() ) + { + if ( !GlobalConfig->currentProfile->getVirtualSubnetworks().isEmpty() ) + stream << " virtual_private=" << GlobalConfig->currentProfile->getVirtualSubnetworks().replace ( " virtual_private=","" ) << "\n"; + } + + stream << " klipsdebug=\""; + for ( QStringList::Iterator it = GlobalConfig->KlipsDebug.begin(); it != GlobalConfig->KlipsDebug.end(); ++it ) + { + stream << *it << " "; + + } + if (GlobalConfig->KlipsDebug.isEmpty()) + stream << "none"; + stream << "\"" << "\n"; + + stream << " plutodebug=\""; + for ( QStringList::Iterator it = GlobalConfig->PlutoDebug.begin(); it != GlobalConfig->PlutoDebug.end(); ++it ) + { + stream << *it << " "; + + } + if (GlobalConfig->PlutoDebug.isEmpty()) + stream << "none"; + stream << "\"" << "\n"; + + // FIXME add detection for nat-t + if ( GlobalConfig->currentProfile->getUseNat() ) + stream << " nat_traversal=yes" << "\n"; + else + stream << " nat_traversal=no" << "\n"; + + if ( realversion.find ( "1.", 0, -1 ) > -1 ) + { + if ( !IpsecToolInfo->Version.contains ( "strongSwan", false ) ) + stream << " plutoload=%search" << "\n"; + if ( !IpsecToolInfo->Version.contains ( "strongSwan", false ) ) + stream << " plutostart=%search" << "\n"; + if ( IpsecToolInfo->Version.contains ( "strongSwan", false ) ) + stream << " plutostart=yes" << "\n"; + } + stream << "" << "\n"; + stream << "conn %default" << "\n"; + stream << " keyingtries=" << GlobalConfig->currentProfile->getMaxConnectTries() << "\n"; + stream << " keylife=1200s" << "\n"; + stream << " ikelifetime=1200s" << "\n"; + stream << "\n"; + + // our connection + stream << "conn " << GlobalConfig->currentProfile->getName() << "\n"; + // x509 + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::cert ) + { + stream << " authby=rsasig" << "\n"; + stream << " leftrsasigkey=%cert" << "\n"; + stream << " rightrsasigkey=%cert" << "\n"; + } + else if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::psk ) + { + // FIXME maybe we should store rightrsasigkey at better place + if (GlobalConfig->currentProfile->getUseSpecialServerCertificate()) + { + stream << " rightrsasigkey=" << GlobalConfig->currentProfile->getSpecialServerCertificate() << "\n"; + } + + // FIXME maybe we should store leftrsasigkey at better place + if (GlobalConfig->currentProfile->getPskIsInFile()) + { + stream << " leftrsasigkey=" << GlobalConfig->currentProfile->getPreSharedKeyFile() << "\n"; + } + + + if ( ( IpsecToolInfo->Version.contains ( "strongSwan", false ) && GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan && GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) ) + { + stream << " authby=xauthpsk" << "\n"; + } + else + { + stream << " authby=secret" << "\n"; + } + } + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { + stream << " type=transport" << "\n"; // we have to use tunnel mode + + if ( GlobalConfig->currentProfile->getIpsecVpnMode() == "tunnel" ) + { + GlobalConfig->currentProfile->setIpsecVpnMode ( "transport" ); + GlobalConfig->appendLogEntry ( i18n ( "IPsec vpn mode was set to \"tunnel\" but must be \"transport\" for use with L2TP. This was temporary fixed." ), GlobalConfig->info ); + } + } + else + { + stream << " type=" << GlobalConfig->currentProfile->getIpsecVpnMode() << "\n"; + } + if ( GlobalConfig->currentProfile->getExchangeMode() == "aggressive" ) + { + if ( IpsecToolInfo->Version.contains ( "Openswan" , false ) ) + stream << " aggrmode=yes" << "\n"; + + /* strongSwan does not support agressive mode :( */ + + } + + if ( GlobalConfig->currentProfile != 0 && GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { + // udp/l2tp + stream << " rightprotoport=17/1701" << "\n"; + stream << " leftprotoport=17/1701" << "\n"; + } + + stream << " keyexchange=ike" << "\n"; + if ( GlobalConfig->currentProfile->getUseCustomIke() ) + stream << " ike=" << GlobalConfig->currentProfile->getIpsecIke() << "\n"; + + if ( GlobalConfig->currentProfile->getUseCustomEsp() ) + stream << " esp=" << GlobalConfig->currentProfile->getIpsecEsp() << "\n"; + +// if ( GlobalConfig->currentProfile->getUseMtu() ) +// stream << " overridemtu=" << GlobalConfig->currentProfile->getMtu() << "\n"; + + if ( GlobalConfig->currentProfile->getUsePerfectForwardSecrety() ) + { + stream << " pfs=yes" << "\n"; + QString pfs_group = GlobalConfig->currentProfile->getPerfectForwardSecrety(); + +// QString PFSGroupNumber = "2"; +// if (pfs_group== "modp768") +// PFSGroupNumber = "1"; +// else if (pfs_group== "modp1024") +// PFSGroupNumber = "2"; +// else if (pfs_group== "modp1536") +// PFSGroupNumber = "5"; +// else if (pfs_group== "modp2048") +// PFSGroupNumber = "14"; +// else if (pfs_group== "modp3072") +// PFSGroupNumber = "15"; +// else if (pfs_group== "modp4096") +// PFSGroupNumber = "16"; +// else if (pfs_group== "modp6144") +// PFSGroupNumber = "17"; +// else if (pfs_group== "modp8192") +// PFSGroupNumber = "18"; + if ( !pfs_group.isEmpty() ) +// stream << " pfsgroup=" << PFSGroupNumber << "\n"; + stream << " pfsgroup=" << pfs_group << "\n"; + } + else + { + stream << " pfs=no" << "\n"; + } + + //stream << " auto=start" << "\n"; + stream << " left=" + LocalIP << "\n"; // local ip + //stream << " left=%defaultroute" << "\n"; // iface to default route + // stream << " leftnexthop = "+LocalNet << "\n"; + // stream << " leftsubnet = " << "\n"; // local network + + if ( !GlobalConfig->currentProfile->getLeftNextHop().isEmpty() ) + stream << " leftnexthop=" + GlobalConfig->currentProfile->getLeftNextHop() << "\n"; + // stream << " rightnexthop = " << "192.168.1.1" << "\n"; + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::cert ) + { + if ( !GlobalConfig->currentProfile->getUseSmartcard() ) + stream << " leftcert=\"" + GlobalConfig->currentProfile->getX509Certificate() << "\""<< "\n"; + else + { + // we have to split slot id and name ("0 : foobar") => 0 + QString Pkcs11Slot = GlobalConfig->currentProfile->getPkcs11Slot().section ( ':', 0, 0 ).stripWhiteSpace(); + stream << " leftcert=%smartcard" << Pkcs11Slot << ":" << GlobalConfig->currentProfile->getPkcs11Id() << "\n"; + } + + if ( GlobalConfig->currentProfile->getUseSpecialServerCertificate() ) + stream << " rightcert=\"" + GlobalConfig->currentProfile->getSpecialServerCertificate() << "\"" << "\n"; + // else + // stream << " rightcert=\"" + rightcert + "\"" << "\n"; + + if ( GlobalConfig->currentProfile->getUseSpecialRemoteID() ) + stream << " rightid=\"" + GlobalConfig->currentProfile->getSpecialRemoteID() << "\""<< "\n"; + //stream << " rightid=\"/C=DE/ST=Sachsen-Anhalt/O=Powersoft/OU=IT/CN=212.100.100.212\"" << "\n"; +// else +// { +// if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::cert ) +// rightid = getX509CertificateID ( GlobalConfig->currentProfile->getX509Certificate(), false ); // remote +// } + +// if ( !GlobalConfig->currentProfile->getUseSpecialLocalID() ) + if ( GlobalConfig->currentProfile->getLocalIDType() == i18n ( "Certificate ID" ) ) + { + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::cert && !GlobalConfig->currentProfile->getUseSmartcard() ) + leftid = getX509CertificateID ( GlobalConfig->currentProfile->getX509Certificate(), true ); // local + else + leftid = "asn1dn"; + stream << " leftid=\"" + leftid + "\""<< "\n"; + } + else + { + stream << " leftid=\"" + GlobalConfig->currentProfile->getSpecialLocalID() << "\""<< "\n"; + } + + } + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::psk ) + { + if ( GlobalConfig->currentProfile->getUseSpecialRemoteID() ) + { + if ( GlobalConfig->currentProfile->getRemoteIDType() == "asn1dn" ) + { + stream << " rightid=@" << GlobalConfig->TmpGatewayIP << "\n"; + } + else + { + if (GlobalConfig->currentProfile->getRemoteIDType() == "address" && !Utils(GlobalConfig).isValidIPv4Address( GlobalConfig->currentProfile->getSpecialRemoteID() ) ) + { + QString resolvedIp = Utils(GlobalConfig).resolveName(GlobalConfig->currentProfile->getSpecialRemoteID()); + if (resolvedIp.isEmpty()) + { + GlobalConfig->appendLogEntry( i18n("Remote ID \"%1\" (type: address) could not resolved, ommiting right id.").arg(GlobalConfig->currentProfile->getSpecialRemoteID()), GlobalConfig->error ); + + } + else + { + if (GlobalConfig->KvpncDebugLevel > 3) + GlobalConfig->appendLogEntry( i18n("Remote ID \"%1\" (type: address) resolved to: %2").arg(GlobalConfig->currentProfile->getSpecialRemoteID()).arg(resolvedIp), GlobalConfig->debug ); + stream << " rightid=" + resolvedIp << "\n"; + } + } + + else + stream << " rightid=" + GlobalConfig->currentProfile->getSpecialRemoteID() << ""<< "\n"; + } + } + //stream << " rightid=\"/C=DE/ST=Sachsen-Anhalt/O=Powersoft/OU=IT/CN=212.100.100.212\"" << "\n"; + //if ( GlobalConfig->currentProfile->getUseSpecialLocalID() && !GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) + if ( GlobalConfig->currentProfile->getUseSpecialLocalID() ) + { + + if ( GlobalConfig->currentProfile->getLocalIDType() == "asn1dn" ) + stream << " leftid=" << GlobalConfig->TmpGatewayIP << "\n"; + else + { + if (GlobalConfig->currentProfile->getLocalIDType() == "address" && !Utils(GlobalConfig).isValidIPv4Address( GlobalConfig->currentProfile->getSpecialLocalID() ) ) + { + QString resolvedIp = Utils(GlobalConfig).resolveName(GlobalConfig->currentProfile->getSpecialLocalID()); + if (resolvedIp.isEmpty()) + { + GlobalConfig->appendLogEntry( i18n("Local ID \"%1\" (type: address) could not resolved, ommiting left id.").arg(GlobalConfig->currentProfile->getSpecialLocalID()), GlobalConfig->error ); + + } + else + { + if (GlobalConfig->KvpncDebugLevel > 3) + GlobalConfig->appendLogEntry( i18n("Local ID \"%1\" (type: address) resolved to: %2").arg(GlobalConfig->currentProfile->getSpecialLocalID()).arg(resolvedIp), GlobalConfig->debug ); + stream << " leftid=" + resolvedIp << "\n"; + } + } + + else + stream << " leftid=" + GlobalConfig->currentProfile->getSpecialLocalID() << ""<< "\n"; + } + } + } + + //stream << " right=" + GlobalConfig->currentProfile->getGateway() << "\n"; + stream << " right=" + GlobalConfig->TmpGatewayIP << "\n"; + + if ( !GlobalConfig->currentProfile->getRightNextHop().isEmpty() ) + { + stream << " rightnexthop=" + GlobalConfig->currentProfile->getRightNextHop() << "\n"; + } + + + if ( GlobalConfig->currentProfile->getUseVirtualIP() ) + { + if ( !GlobalConfig->currentProfile->getRemoteVirtualIP().isEmpty() ) + stream << " rightsubnet=" << GlobalConfig->currentProfile->getRemoteVirtualIP() << "\n"; + } + else + { + if ( GlobalConfig->currentProfile->getUseRemoteNetwork() && !RemoteNetAddr.isEmpty() ) + stream << " rightsubnet=" << RemoteNet << "\n"; + } + + if ( !LocalNet.isEmpty() ) + stream << " leftsubnet=" << LocalNet << "\n"; + + if ( GlobalConfig->currentProfile->getUseLeftSourceIp() ) + { + if ( !GlobalConfig->currentProfile->getLeftSourceIp().isEmpty() ) + { + stream << " leftsourceip=" << GlobalConfig->currentProfile->getLeftSourceIp() << "" << "\n"; + stream << " leftsubnet=" << GlobalConfig->currentProfile->getLeftSourceIp() << "/32" << "\n"; + } + } + if ( GlobalConfig->currentProfile->getUseRightSourceIp() ) + { + if ( !GlobalConfig->currentProfile->getRightSourceIp().isEmpty() ) + stream << " rightsourceip=" << GlobalConfig->currentProfile->getRightSourceIp() << "\n"; + } + + + + + // XAUTH + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan && GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) + { + QString LocalID = GlobalConfig->currentProfile->getSpecialLocalID(); +// if (!LocalID.find( "@", 0 , FALSE ) > -1) +// LocalID="@"+LocalID; + if ( IpsecToolInfo->Version.contains ( "Openswan" , false ) ) + { + stream << " leftxauthclient=yes" << "\n"; + stream << " rightxauthserver=yes" << "\n"; + } + if ( IpsecToolInfo->Version.contains ( "strongSwan", false ) ) + { + stream << " xauth=client" << "\n"; + } + stream << " leftid=" << LocalID << "\n"; + + // later +// stream << " modecfgpull=no" << "\n"; + } + + stream << " auto=add" << "\n"; + + if ( GlobalConfig->currentProfile->getDisableOpportunisticEncryption() ) + { + stream << "\n"; + stream << "# disable opportunistic encryption" << "\n"; + stream << "conn block" << "\n"; + stream << " auto=ignore" << "\n\n"; + + stream << "conn private" << "\n"; + stream << " auto=ignore" << "\n\n"; + + stream << "conn private-or-clear" << "\n"; + stream << " auto=ignore" << "\n\n"; + + stream << "conn clear-or-private" << "\n"; + stream << " auto=ignore" << "\n"; + + stream << "conn clear" << "\n"; + stream << " auto=ignore" << "\n\n"; + + stream << "conn packetdefault" << "\n"; + stream << " auto=ignore" << "\n"; + } + + IpsecConfigFile.close(); + if ( GlobalConfig->KvpncDebugLevel > 6 ) + { + GlobalConfig->appendLogEntry ( i18n ( "---- %1 ---" ).arg ( IpsecPrefix + "/ipsec.conf" ),GlobalConfig->debug ); + GlobalConfig->appendLogEntry ( "---------------------",GlobalConfig->debug ); + QString IpsecContent=""; + QFile file ( IpsecPrefix + "/ipsec.conf" ); + if ( file.open ( IO_ReadOnly ) ) + { + QTextStream stream ( &file ); + QString line; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' + GlobalConfig->appendLogEntry ( line,GlobalConfig->debug ); + } + file.close(); + } + GlobalConfig->appendLogEntry ( "---------------------",GlobalConfig->debug ); + } + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "%1 could not opened. Stop." ).arg ( IpsecConfigFile.name() ),GlobalConfig->error ); + setGuiStatus ( disconnected ); + return; + } + + stream.unsetDevice(); + + + + // iptables need the right interface (eth0:1 => eth0) + QString tmpInterface2 = ""; + int pointPos = tmpInterface.find ( ':', 0, FALSE ); + if ( pointPos > 1 ) + { + tmpInterface2 = tmpInterface.left ( pointPos ); + } + else + tmpInterface2 = tmpInterface; + + // write iptables._add_ipsec_freeswan.sh + QFile file ( tmpPath + "iptables." + GlobalConfig->currentProfile->getName() + ".add_ipsec_freeswan.sh" ); + stream.setDevice ( &file ); + if ( file.open ( IO_WriteOnly ) ) + { + stream << "#!"<< GlobalConfig->InterpreterShell << "\n"; + stream << "# generated by kvpnc. Do not edit it." << "\n"; + stream << "# profile: " + ProfileName << "\n"; + stream << "" << "\n"; + stream << "# AH" << "\n"; + stream << GlobalConfig->pathToIptables << " -I INPUT -p 50 -i " << tmpInterface2 << " -s " << GlobalConfig->currentProfile->getGateway() << " -j ACCEPT" << "\n"; + stream << GlobalConfig->pathToIptables << " -I OUTPUT -p 50 -d " << GlobalConfig->currentProfile->getGateway() << " -j ACCEPT" << "\n"; + stream << "" << "\n"; + stream << "# ESP" << "\n"; + stream << GlobalConfig->pathToIptables << " -I INPUT -p 51 -i " << tmpInterface2 << " -s " << GlobalConfig->currentProfile->getGateway() << " -j ACCEPT" << "\n"; + stream << GlobalConfig->pathToIptables << " -I OUTPUT -p 51 -d " << GlobalConfig->currentProfile->getGateway() << " -j ACCEPT" << "\n"; + stream << "" << "\n"; + stream << "# IKE" << "\n"; + stream << GlobalConfig->pathToIptables << " -I INPUT -p udp --dport 500 -i " << tmpInterface2 << " -s " << GlobalConfig->currentProfile->getGateway() << " -j ACCEPT" << "\n"; + stream << "" << "\n"; + stream << "# NAT-T" << "\n"; + stream << GlobalConfig->pathToIptables << " -I INPUT -p udp --dport 4500 -i " << tmpInterface2 << " -s " << GlobalConfig->currentProfile->getGateway() << " -j ACCEPT" << "\n"; + if ( GlobalConfig->currentProfile != 0 && GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { + stream << "# L2TP" << "\n"; + stream << GlobalConfig->pathToIptables << " -I OUTPUT -p udp --sport 1701 -o " << tmpInterface2 << " -s " << LocalIP << " -j ACCEPT" << "\n"; + stream << GlobalConfig->pathToIptables << " -I INPUT -p udp --dport 1701 -i " << tmpInterface2 << " -d " << GlobalConfig->currentProfile->getGateway() << " -j ACCEPT" << "\n"; + } + file.close(); + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "%1 could not opened. Stop." ).arg ( tmpPath + "iptables." + GlobalConfig->currentProfile->getName() + ".add_ipsec_freeswan.sh" ),GlobalConfig->error ); + setGuiStatus ( disconnected ); + return; + } + stream.unsetDevice(); + + QFile file1 ( tmpPath + "iptables." + GlobalConfig->currentProfile->getName() + ".remove_ipsec_freeswan.sh" ); + QTextStream stream1 ( &file1 ); + if ( file1.open ( IO_WriteOnly ) ) + { + stream1 << "#!"<< GlobalConfig->InterpreterShell << "\n"; + stream1 << "# generated by kvpnc. Do not edit it." << "\n"; + stream1 << "# profile: " + GlobalConfig->currentProfile->getName() << "\n"; + stream1 << "" << "\n"; + stream1 << "# AH" << "\n"; + stream1 << GlobalConfig->pathToIptables << " -D INPUT -p 50 -i " << tmpInterface2 << " -s " << GlobalConfig->currentProfile->getGateway() << " -j ACCEPT" << "\n"; + stream1 << GlobalConfig->pathToIptables << " -D OUTPUT -p 50 -d " << GlobalConfig->currentProfile->getGateway() << " -j ACCEPT" << "\n"; + stream1 << "" << "\n"; + stream1 << "# ESP" << "\n"; + stream1 << GlobalConfig->pathToIptables << " -D INPUT -p 51 -i " << tmpInterface2 << " -s " << GlobalConfig->currentProfile->getGateway() << " -j ACCEPT" << "\n"; + stream1 << GlobalConfig->pathToIptables << " -D OUTPUT -p 51 -d " << GlobalConfig->currentProfile->getGateway() << " -j ACCEPT" << "\n"; + stream1 << "" << "\n"; + stream1 << "# IKE" << "\n"; + stream1 << GlobalConfig->pathToIptables << " -D INPUT -p udp --dport 500 -i " << tmpInterface2 << " -s " << GlobalConfig->currentProfile->getGateway() << " -j ACCEPT" << "\n"; + stream1 << "" << "\n"; + stream1 << "# NAT-T" << "\n"; + stream1 << GlobalConfig->pathToIptables << " -D INPUT -p udp --dport 4500 -i " << tmpInterface2 << " -s " << GlobalConfig->currentProfile->getGateway() << " -j ACCEPT" << "\n"; + if ( GlobalConfig->currentProfile != 0 && GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { + stream1 << "# L2TP" << "\n"; + stream1 << GlobalConfig->pathToIptables << " -D OUTPUT -p udp --sport 1701 -o " << tmpInterface2 << " -s " << LocalIP << " -j ACCEPT" << "\n"; + stream1 << GlobalConfig->pathToIptables << " -D INPUT -p udp --dport 1701 -i " << tmpInterface2 << " -d " << GlobalConfig->currentProfile->getGateway() << " -j ACCEPT" << "\n"; + } + + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "%1 could not opened. Stop." ).arg ( tmpPath + "iptables." + GlobalConfig->currentProfile->getName() + ".remove_ipsec_freeswan.sh" ),GlobalConfig->error ); + setGuiStatus ( disconnected ); + return; + } + + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::psk ) + { + // write psk..key + QFile Pskfile ( tmpPath + "psk." + ProfileName + ".key" ); + stream.setDevice ( &Pskfile ); + if ( Pskfile.open ( IO_WriteOnly ) ) + { + stream << GlobalConfig->currentProfile->getPreSharedKey() << "\n"; + Pskfile.close(); + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "%1 could not opened. Stop." ).arg ( Pskfile.name() ),GlobalConfig->error ); + } + + stream.unsetDevice(); + } + + setenv ( "DNS_UPDATE", ( GlobalConfig->currentProfile->getUseDnsUpdate() ? "Yes" : "NO" ), 1 ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Setting DNS_UPDATE \"%1\"." ).arg ( getenv ( "DNS_UPDATE" ) ), GlobalConfig->debug ); + + // if (GlobalConfig->currentProfile->useVirtualIP()){ + // if (!setVirtualIP()){ + // setGuiStatus(disconnected); + // return; + // } + // } + + + + if ( useL2tpAfterFirstConnection ) + prepareL2tpd(); + + IpsecPhase1Up=false; + IpsecPhase2Up=false; + + +// startStopIpsec(false); + + IpsecStartProcess = new QProcess ( this ); + // + IpsecStartProcess->addArgument ( GlobalConfig->pathToIpsec ); + + if ( IpsecToolInfo->Version.contains ( "Openswan" , false ) ) + { + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[" + IpsecType + "] " + i18n ( "Starting ipsec setup..." ), GlobalConfig->debug ); + + IpsecStartProcess->addArgument ( "setup" ); + IpsecStartProcess->addArgument ( "start" ); + } + if ( IpsecToolInfo->Version.contains ( "strongSwan", false ) /*&& ( (IpsecMajor >= 4 && IpsecMinor >= 2 && IpsecSubMinor >=2 ) || IpsecMajor > 4 )*/ ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) +// GlobalConfig->appendLogEntry ( "[" + IpsecType + "] " + i18n ( "Starting [strongswan] starter in foreground..." ), GlobalConfig->debug ); + GlobalConfig->appendLogEntry ( "[" + IpsecType + "] " + i18n ( "Starting ipsec..." ), GlobalConfig->debug ); + + +// IpsecStartProcess->addArgument ( "starter" ); +// IpsecStartProcess->addArgument ( "--nofork"); +// QFile("/var/run/pluto.pid").remove(); +// QFile("/var/run/starter.pid").remove(); +// IpsecStartProcess->addArgument ( "setup" ); + IpsecStartProcess->addArgument ( "start" ); + } + + IpsecGotError = false; + + connect ( IpsecStartProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_ipsec() ) ); + connect ( IpsecStartProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsec() ) ); + connect ( IpsecStartProcess, SIGNAL ( normalExit () ), this, SLOT ( ipsecStarted() ) ); + + if ( !IpsecStartProcess->start ( env ) ) + { + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( "ipsec (" + IpsecType + "): setup" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "ipsec (" + IpsecType + "): setup" ) , GlobalConfig->error ); + disconnect ( IpsecStartProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_ipsec() ) ); + disconnect ( IpsecStartProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsec() ) ); + //disconnect ( IpsecStartProcess, SIGNAL ( processExited () ), this, SLOT ( ipsecStarted() ) ); + delete IpsecStartProcess; + IpsecStartProcess = 0L; + disconnectClicked(); + setGuiStatus ( disconnected ); + } + else + { + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "IPsec daemon (%1) started." ).arg ( IpsecType ), GlobalConfig->debug ); + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan ) + ConnectingProcess = VpnAccountData::freeswan; + else + ConnectingProcess = VpnAccountData::l2tpd_freeswan; + GlobalConfig->status = GlobalConfig->connecting; + mw->buttonDisconnect->setEnabled ( true ); + this->DisconnectAction->setEnabled ( true ); + mw->buttonConnect->setEnabled ( false ); + this->ConnectAction->setEnabled ( false ); + stopContinue = false; + + GlobalConfig->currentConnectRetry++; + + int currentConnectCounter=0; + while ( IpsecStartProcess != 0 && IpsecStartProcess->isRunning() /*&& currentConnectCounter <= 500*/ ) + { + if ( GlobalConfig->KvpncDebugLevel > 8 ) + { + if ( IpsecToolInfo->Version.contains ( "strongSwan", false ) ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" still running, waiting" ).arg ( "ipsec start" ) , GlobalConfig->debug ); + else + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" still running, waiting" ).arg ( "ipsec setup start" ) , GlobalConfig->debug ); + } + currentConnectCounter++; + if ( GlobalConfig->appPointer->hasPendingEvents () ) + GlobalConfig->appPointer->processEvents(); + usleep ( 500 ); + } + disconnect ( IpsecStartProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_ipsec() ) ); + disconnect ( IpsecStartProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsec() ) ); + disconnect ( IpsecStartProcess, SIGNAL ( processExited () ), this, SLOT ( ipsecStarted() ) ); + delete IpsecStartProcess; + IpsecStartProcess = 0L; + +// if (currentConnectCounter > 500) +// { +// if ( GlobalConfig->KvpncDebugLevel >3 ) +// if (IpsecToolInfo->Version.contains ( "strongSwan", false )) +// GlobalConfig->appendLogEntry ( i18n ( "\"%1\" still running but needs too long, stopping" ).arg ( "ipsec start" ) , GlobalConfig->debug ); +// else +// GlobalConfig->appendLogEntry ( i18n ( "\"%1\" still running but needs too long, stopping" ).arg ( "ipsec setup start" ) , GlobalConfig->debug ); +// disconnectClicked(); +// return; +// } + //ipsecStarted(); + } + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "%1 could not opened. Stop." ).arg ( IpsecSecretsFile.name() ),GlobalConfig->error ); + setGuiStatus ( disconnected ); + return; + } + + } + else + { + setGuiStatus ( disconnected ); + } + } // freeswan + /* ============ pptp ================ */ + else if ( GlobalConfig->currentProfile != 0 && GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::pptp ) + { + //setGuiStatus(connecting); + + // looking for pppd + if ( Utils ( GlobalConfig ).getToolInfo ( "pppd" )->found == false ) + { + KMessageBox::error ( this, i18n ( "Unable to find \"%1\" at \"%2\"!" ).arg ( "pppd" ).arg ( GlobalConfig->pathToPppd ) ); + GlobalConfig->appendLogEntry ( i18n ( "Unable to find \"%1\" at \"%2\"!" ).arg ( "pppd" ).arg ( GlobalConfig->pathToPppd ), GlobalConfig->error ); + ok = false; + setGuiStatus ( disconnected ); + return ; + } + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "pppd: %1" ) .arg ( GlobalConfig->pathToPppd ), GlobalConfig->debug ); + + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Checking gre support" ), GlobalConfig->debug ); + bool gresupportfound = false; + QString procnetdev = ""; + QFile f ( "/proc/net/dev" ); + if ( f.open ( IO_ReadOnly ) ) + { + QTextStream procnetdevstream ( &f ); + QString procnetdevcontent = QString(procnetdevstream.read()); + QStringList procnetdev_content_list = QStringList::split("\n", procnetdevcontent); + QString line = ""; + for ( QStringList::Iterator it = procnetdev_content_list.begin(); it != procnetdev_content_list.end(); ++it ) + { + line = *it; // line of text excluding '\n' + if ( line.contains ( "gre0", false ) ) + { + gresupportfound = true; + break; + } + } + f.close(); + } + if ( !gresupportfound ) + { + QString procmodules = ""; + QFile f2 ( "/proc/modules" ); + if ( f2.open ( IO_ReadOnly ) ) + { + QTextStream procmodulesstream ( &f2 ); + QString procmodulescontent = QString(procmodulesstream.read()); + QStringList procmodules_content_list = QStringList::split("\n", procmodulescontent); + QString line = ""; + for ( QStringList::Iterator it2 = procmodules_content_list.begin(); it2 != procmodules_content_list.end(); ++it2 ) + { + line = *it2; // line of text excluding '\n' + if ( line.contains ( "ip_gre", false ) ) + { + gresupportfound = true; + break; + } + } + f2.close(); + } + } + if ( gresupportfound ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Support for %1 found (compiled into kernel or kernel module already loaded)." ).arg("GRE"), GlobalConfig->debug ); + } + else + { + if ( !Utils ( GlobalConfig, parent ).loadKernelModule ( "ip_gre", parent ) ) + { + KMessageBox::information ( this, i18n ( "Loading of module \"%1\" failed!" ).arg ( "ip_gre" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Tunnel device is missing, loading module \"%1\" has failed: stop." ).arg ( "ip_gre" ), GlobalConfig->error ); + disconnectClicked(); + setGuiStatus ( disconnected ); + GlobalConfig->status = GlobalConfig->disconnected; + return ; + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Loading of module \"%1\" was successful." ).arg ( "ip_gre" ), GlobalConfig->debug ); + } + } + + + // if ( GlobalConfig->currentProfile->getRemoteNetAddr().isEmpty() || GlobalConfig->currentProfile->getRemoteNetMask() .isEmpty() ) + // { + // GlobalConfig->appendLogEntry( i18n( "Remote network is missing, please fill in in profile dialog." ), GlobalConfig->error ); + // ok = false; + // setGuiStatus(disconnected); + // return; + // } + + + Utils::PppdCapabilities pppdcap = Utils ( GlobalConfig ).checkPppdCapabilities(); + pppdHasReplacedefaultrouteSupport = pppdcap.pppdHasReplacedefaultrouteSupport; + + if ( GlobalConfig->currentProfile->getRequireMppe() ) + { + if ( !pppdcap.pppdHasMppeRequiredSupport && !pppdcap.pppdHasRequireMppeSupport ) + { + GlobalConfig->appendLogEntry ( i18n ( "pppd: (%1) has no MPPE support. STOP." ) .arg ( GlobalConfig->pathToPppd ), GlobalConfig->error ); + ok=false; + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + { + if ( pppdcap.pppdHasMppeRequiredSupport ) + GlobalConfig->appendLogEntry ( i18n ( "pppd: (%1) has MPPE support: %2" ) .arg ( GlobalConfig->pathToPppd ).arg ( "mppe required" ), GlobalConfig->debug ); + else if ( pppdcap.pppdHasRequireMppeSupport ) + GlobalConfig->appendLogEntry ( i18n ( "pppd: (%1) has MPPE support: %2" ) .arg ( GlobalConfig->pathToPppd ).arg ( "require-mppe" ), GlobalConfig->debug ); + } + } + } + + bool askUsernamePass=false; + bool requestUsername = false; + if ( AuthRetry ) + { + askUsernamePass = true; + requestUsername = true; + } + + if ( GlobalConfig->currentProfile->getAskUserPasswordOnEachConnect() ) + { + if ( GlobalConfig->KvpncDebugLevel > 4 ) + GlobalConfig->appendLogEntry ( i18n ( "User password on each connect forced." ), GlobalConfig->debug ); + + askUsernamePass = true; + requestUsername = true; + } + + if ( !GlobalConfig->haveUserData || GlobalConfig->currentProfile->getAskUserPasswordOnEachConnect() ) + { + if ( !GlobalConfig->currentProfile->getSaveUserPassword() || GlobalConfig->currentProfile->getUserPassword().isEmpty() || GlobalConfig->currentProfile->getUserName().isEmpty() || askUsernamePass ) + { + + EnterUsernamePasswordDialog dlg ( this, i18n ( "Enter Account Data" ), false, requestUsername ); // only password + + if ( !GlobalConfig->currentProfile->getSaveUserPassword() ) + { + dlg.main->PasswordEdit->setText ( GlobalConfig->currentProfile->getUserPassword() ); + dlg.main->SavePasswordCheckBox->setChecked ( true ); + } + + dlg.main->UsernameEdit->setText ( GlobalConfig->currentProfile->getUserName() ); + if ( !dlg.main->UsernameEdit->text().isEmpty() ) //go straight to pw if username present + { + dlg.main->PasswordEdit->setFocus(); + dlg.main->SaveUsernameCheckBox->setChecked ( true ); + } + + if ( dlg.exec() ) + { + GlobalConfig->TmpUsername = dlg.main->UsernameEdit->text(); + GlobalConfig->TmpPassword = dlg.main->PasswordEdit->text(); + bool needSave=false; + + if ( GlobalConfig->TmpPassword.isEmpty() ) + { + GlobalConfig->appendLogEntry ( i18n ( "Password is empty" ), GlobalConfig->error ); + ok = false; + } + + if ( !GlobalConfig->currentProfile->getDontSaveUsername() && ( requestUsername && GlobalConfig->TmpUsername.isEmpty() ) ) + { + GlobalConfig->appendLogEntry ( i18n ( "Username is empty!" ), GlobalConfig->error ); + ok = false; + } + + if ( dlg.main->SaveUsernameCheckBox->isChecked() ) + { + GlobalConfig->currentProfile->setDontSaveUsername ( false ); + GlobalConfig->currentProfile->setUserName ( dlg.main->UsernameEdit->text() ); + needSave=true; + } + else + { + GlobalConfig->TmpUsername = dlg.main->UsernameEdit->text(); + GlobalConfig->currentProfile->setDontSaveUsername ( true ); + needSave = true; + } + + if ( dlg.main->SavePasswordCheckBox->isChecked() ) + { + GlobalConfig->currentProfile->setSaveUserPassword ( true ); + GlobalConfig->currentProfile->setUserPassword ( GlobalConfig->TmpPassword ); + needSave=true; + } + else + { + GlobalConfig->currentProfile->setSaveUserPassword ( false ); + needSave=true; + } + if ( needSave) + GlobalConfig->saveOptions(true, GlobalConfig->currentProfile->getName()); + + + if ( GlobalConfig->KvpncDebugLevel > 0 && ok ) + GlobalConfig->appendLogEntry ( i18n ( "Some passwords which are need got from password enter dialog." ), GlobalConfig->debug ); + } + else + { + ok = false; + + AuthRetry = false; + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Connect canceled because password enter dialog aborted." ), GlobalConfig->debug ); + } + } + else + { + if ( !GlobalConfig->currentProfile->getSaveUserPassword() && ! GlobalConfig->currentProfile->getUserPassword().isEmpty() ) + { + GlobalConfig->TmpPassword = GlobalConfig->currentProfile->getUserPassword() ; + } + + + if ( !GlobalConfig->currentProfile->getDontSaveUsername() && ! GlobalConfig->currentProfile->getUserName().isEmpty() ) //go straight to pw if username present + { + GlobalConfig->TmpUsername = GlobalConfig->currentProfile->getUserName(); + } + } + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 4 ) + GlobalConfig->appendLogEntry ( i18n ( "User data already collected." ), GlobalConfig->debug ); + } + // here we go + if ( ok ) + { + + PppdDevice = "ppp0"; + if ( GlobalConfig->currentProfile->getExecuteCmdBeforeConnect() ) + executeCommandBeforeConnect(); + + tmpPath = locateLocal ( "data", "kvpnc/" ); + + QString tmpInterface; + QString LocalIP; + NetworkInterface iface ( GlobalConfig, parent ); + if ( GlobalConfig->currentProfile->getNetworkDevice() == "default" ) + { + tmpInterface = iface.getDefaultInterface(); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Default interface: \"%1\"." ).arg ( tmpInterface ) , GlobalConfig->debug ); + LocalIP = iface.getInterfaceIP ( iface.getDefaultInterface() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "IP address of default interface: \"%1\"." ).arg ( LocalIP ) , GlobalConfig->debug ); + } + else + { + // QString device = GlobalConfig->currentProfile->getNetworkDevice() + // QString device = PppdDevice; + // tmpInterface = GlobalConfig->currentProfile->getNetworkDevice(); + // LocalIP = iface.getInterfaceIP( device ); + } + if ( tmpInterface.isEmpty() ) + { + tmpInterface = iface.getDefaultInterface(); + LocalIP = iface.getInterfaceIP ( iface.getDefaultInterface() ); + if ( tmpInterface.isEmpty() ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + { + GlobalConfig->appendLogEntry ( i18n ( "No default interface found, using \"lo\"." ), GlobalConfig->debug ); + tmpInterface = "lo"; // no default interface found :( + } + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "No default interface given, tried default interface, got success, using \"%1\"." ).arg ( tmpInterface ), GlobalConfig->debug ); + } + } + + if ( LocalIP.isEmpty() ) + { + if ( GlobalConfig->PppdDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "No IP for default interface found, using \"127.0.0.1\"." ), GlobalConfig->debug ); + LocalIP = "127.0.0.1"; // no IP for default interface found :( + } + + GlobalConfig->OldDefaultDev = iface.getDefaultInterface(); + GlobalConfig->OldDefaultGw = iface.getGatewayOfDefaultInterface(); + + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Old default device: %1, old default gw: %2" ).arg ( GlobalConfig->OldDefaultDev ).arg ( GlobalConfig->OldDefaultGw ), GlobalConfig->debug ); + + + OldDefaultroute = tmpPath + "default-route." + GlobalConfig->currentProfile->getName(); // default-route. + PptpGateway = tmpPath + "gateway." + GlobalConfig->currentProfile->getName(); // gateway. + GlobalConfig->Pppd_pid_file = "/var/run/ppp-" + GlobalConfig->currentProfile->getName() + ".pid"; // /var/run/ppp-.pid + + // write pppd peer script + QString PppdPeerScript = "/etc/ppp/peers/kvpnc." + GlobalConfig->currentProfile->getName(); // /etc/ppp/peers/ + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "pppd peer script: " + PppdPeerScript + "\n", GlobalConfig->debug ); + + QFile file ( PppdPeerScript ); + QTextStream stream ( &file ); + if ( file.open ( IO_WriteOnly ) ) + { + stream << "# generated by kvpnc. Do not edit it." << "\n"; + stream << "# profile: " + GlobalConfig->currentProfile->getName() << "\n"; + stream << "" << "\n"; + stream << "\n"; + stream << "# name of tunnel, used to select lines in secrets files\n"; + stream << "remotename " + GlobalConfig->currentProfile->getName() + "\n"; + stream << "\n"; + stream << "# name of tunnel, used to name /var/run pid file\n"; + stream << "linkname kvpnc." + GlobalConfig->currentProfile->getName() + "\n"; + stream << "\n"; + stream << "# name of tunnel, passed to ip-up scripts\n"; + stream << "ipparam kvpnc." + GlobalConfig->currentProfile->getName() + "\n"; + stream << "\n"; + stream << "# data stream for pppd to use\n"; + QString pptpdebug=""; + if ( GlobalConfig->enableDebugPptpd == true ) + { + pptpdebug=" --debug "; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Enabling debug for pptpd." ), GlobalConfig->debug ); + } + stream << "pty \"" << GlobalConfig->pathToPptp << " " << pptpdebug << "--loglevel " << QString().setNum ( GlobalConfig->PptpLogLevel ) << " " << GlobalConfig->currentProfile->getGateway() << " --nolaunchpppd\"\n"; + stream << "\n"; + + stream << "# domain and username, used to select lines in secrets files\n"; + if ( GlobalConfig->currentProfile->getUseNtDomainName() && !GlobalConfig->currentProfile->getNtDomainName().isEmpty() ) + { + stream << "name \"" + GlobalConfig->currentProfile->getNtDomainName() + "\\\\" + GlobalConfig->currentProfile->getUserName() + "\"\n"; + GlobalConfig->appendLogEntry ( i18n ( "Using (NT) domain name \"%1\"." ).arg ( GlobalConfig->currentProfile->getNtDomainName() ), GlobalConfig->debug ); + } + else + stream << "name \"" + GlobalConfig->currentProfile->getUserName() + "\"\n"; + stream << "\n"; + + if ( GlobalConfig->currentProfile->getUseDnsServer() && !GlobalConfig->currentProfile->getDnsServer().isEmpty() ) + { + stream << "# set own dns server\n"; + stream << "ms-dns " + GlobalConfig->currentProfile->getDnsServer() + "\n"; + stream << "\n"; + } + else + { + if ( GlobalConfig->currentProfile->getUseDnsUpdate() ) + { + stream << "# retrieve DNS from peer\n"; + stream << "usepeerdns\n"; + stream << "\n"; + } + } + + if ( GlobalConfig->currentProfile->getRequireMppe() ) + { + stream << "# use MPPE encryption\n"; + + stream << pppdcap.RequireMppeOption; + if ( !pppdcap.MppeOptionsInALine ) + stream << "\n"; + + if ( GlobalConfig->currentProfile->getAllowStatefulMode() ) + { + stream << pppdcap.RequireStatefulOption; + if ( !pppdcap.MppeOptionsInALine ) + stream << "\n"; + } + else + { + stream << pppdcap.RequireStatelessOption; + if ( !pppdcap.MppeOptionsInALine ) + stream << "\n"; + } + + + + if ( GlobalConfig->currentProfile->getRefuse128BitEncryption() ) + { + stream << pppdcap.Refuse128BitMppeOption; + if ( !pppdcap.MppeOptionsInALine ) + stream << "\n"; + } + else + { + stream << pppdcap.Require128BitMppeOption; + if ( !pppdcap.MppeOptionsInALine ) + stream << "\n"; + } + + + if ( GlobalConfig->currentProfile->getRefuse40BitEncryption() ) + { + stream << pppdcap.Refuse40BitMppeOption; + if ( !pppdcap.MppeOptionsInALine ) + stream << "\n"; + } + + + stream << "\n"; + } + else + { + stream << "# disable MPPE encryption\n"; + stream << pppdcap.RefuseMppeOption; + if ( !pppdcap.MppeOptionsInALine ) + stream << "\n"; + stream << "\n"; + } + + stream << "# we do not require the peer to authenticate itself\n"; + stream << "noauth\n"; + stream << "\n"; + + if ( GlobalConfig->enableDebugPppd ) + { + stream << "# enable debug\n"; + stream << "debug\n"; + stream << "\n"; + } + + stream << "# we want to see what happen\n"; + stream << "nodetach\n"; + stream << "\n"; + + stream << "# lock the device\n"; + stream << "lock\n"; + stream << "\n"; + + if ( GlobalConfig->currentProfile->getUseNoBsdComp() ) + { + stream << "# Dont use BSD compression\n"; + stream << "nobsdcomp\n"; + stream << "\n"; + } + else + { + stream << "# Use BSD compression\n"; + stream << "bsdcomp 9\n"; + stream << "\n"; + } + + if ( GlobalConfig->currentProfile->getUseNoDeflate() ) + { + stream << "# Dont use deflate method\n"; + stream << "nodeflate\n"; + stream << "\n"; + } + else + { + stream << "# Use deflate method\n"; + // FIXME make values dynamiclly + stream << "deflate 9\n"; + stream << "\n"; + } + + if ( !GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + { + stream << "# dont replace defaultroute\n"; + stream << "defaultroute"; + stream << "\n"; + } + else + { + if ( GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + { + stream << "# replace defaultroute\n"; + stream << "defaultroute\n"; + if ( pppdcap.pppdHasReplacedefaultrouteSupport ) + stream << "replacedefaultroute\n"; + } + stream << "\n"; + } + + + if ( GlobalConfig->currentProfile->getUseMtu() ) + { + stream << "# userdefined MTU\n"; + stream << "mtu " + QString().setNum ( GlobalConfig->currentProfile->getMtu() ) + "\n"; + stream << "\n"; + } + else + { + stream << "# default MTU\n"; + stream << "mtu 1500" << "\n"; + stream << "\n"; + } + + if ( GlobalConfig->currentProfile->getUseMru() ) + { + stream << "# userdefined MRU\n"; + stream << "mru " + QString().setNum ( GlobalConfig->currentProfile->getMru() ) + "\n"; + stream << "\n"; + } + else + { + stream << "# default MRU\n"; + stream << "mru 1500" << "\n"; + stream << "\n"; + } + + if ( GlobalConfig->currentProfile->getUseNoIpDefault() ) + { + stream << "# Use no IP by default\n"; + stream << "noipdefault\n"; + stream << "\n"; + } + + if ( GlobalConfig->currentProfile->getDisableMPPEComp() ) + { + stream << "# disable Microsoft Point-to-Point Compression (MPPC) (i.e. for compatibility with watchguard firebox)\n"; +// if ( !pppdcap.oldPppdStyle || pppdcap.pppdHasRequireMppe128Support ) + stream << "nopcomp\n"; +// else +// stream << "nomppc\n"; + stream << "\n"; + } + + if ( GlobalConfig->currentProfile->getDisableCcp() ) + { + stream << "# Disable CCP (Compression Control Protocol) negotiation\n"; + stream << "noccp\n"; + stream << "\n"; + } + + if ( GlobalConfig->currentProfile->getDisableHeaderCompression() ) + { + stream << "# disable TCP header compression\n"; + stream << "novj\n"; + stream << "\n"; + } + + if ( GlobalConfig->currentProfile->getDisableMagicNumberNegotiation() ) + { + stream << "# disable magic number negotiation\n"; + stream << "nomagic\n"; + stream << "\n"; + } + + if ( GlobalConfig->currentProfile->getDisableIpx() ) + { + stream << "# disable IPX\n"; + stream << "noipx\n"; + stream << "\n"; + } + + if ( GlobalConfig->currentProfile->getDisableProtocolFieldCompression() ) + { + stream << "# disable protocol field compression\n"; + stream << "nopcomp\n"; + stream << "\n"; + } + + if ( GlobalConfig->currentProfile->getDisableAdressControlCompression() ) + { + stream << "# disable adress control compression\n"; + stream << "noaccomp\n"; + stream << "\n"; + } + + if ( GlobalConfig->currentProfile->getUseVirtualIP() ) + { + stream << "# use virtual IP addresses\n"; + stream << "# :\n"; + stream << GlobalConfig->currentProfile->getLocalVirtualIP() << ":" << GlobalConfig->currentProfile->getRemoteVirtualIP() << "\n"; + } + + stream << "# kernel level debug\n"; + stream << "kdebug " << GlobalConfig->PppdKernelLogLevel << "\n"; + + + if ( GlobalConfig->currentProfile->getRequireEap() ) + { + stream << "# force EAP\n"; + stream << "require-eap\n"; + } + else + { + stream << "# refuse EAP\n"; + stream << "refuse-eap\n"; + } + + if ( GlobalConfig->currentProfile->getAuthMethod() == "chap" || GlobalConfig->currentProfile->getAuthMethod() == "mschap" || GlobalConfig->currentProfile->getAuthMethod() == "mschap-v2" ) + { + + //GlobalConfig->appendLogEntry ( i18n ( "Creating of %1 failed!" ).arg ( "pppd secrets file" ), GlobalConfig->error ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Authentication method: %1" ).arg ( GlobalConfig->currentProfile->getAuthMethod() ), GlobalConfig->debug ); + + if ( GlobalConfig->currentProfile->getAuthMethod() == "chap" ) + { + stream << "# use chap" << "\n"; + stream << pppdcap.RequireAuthChapOption << "\n"; + } + + if ( GlobalConfig->currentProfile->getAuthMethod() == "mschap" ) + { + stream << "# use mschap" << "\n"; + stream << pppdcap.RequireAuthMschapOption << "\n"; + } + + if ( GlobalConfig->currentProfile->getAuthMethod() == "mschap-v2" ) + { + stream << "# use mschap-v2" << "\n"; + stream << pppdcap.RequireAuthMschapv2Option << "\n"; + } + + + stream << "\n"; + + Utils ( GlobalConfig, this ).doChmod ( "/etc/ppp/pap-secrets", "go-rwx" ); + + // write pppd /etc/ppp/chap-secrets + QString ChapSecrets = "/etc/ppp/chap-secrets"; // /etc/ppp/chap-secrets + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "pppd secrets file: %1" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + file.setName ( ChapSecrets ); + stream.setDevice ( &file ); + if ( file.open ( IO_WriteOnly | IO_Append ) ) + { + stream << "# +++ generated by kvpnc. Do not edit it." << "\n"; + stream << "# profile: " + GlobalConfig->currentProfile->getName() << "\n"; + + if ( GlobalConfig->currentProfile->getSaveUserPassword() ) + GlobalConfig->TmpPassword = GlobalConfig->currentProfile->getUserPassword(); + + QString UsernameStr; + if ( !GlobalConfig->currentProfile->getDontSaveUsername() ) + UsernameStr = GlobalConfig->currentProfile->getUserName(); + else + UsernameStr = GlobalConfig->TmpUsername; + + GlobalConfig->appendLogEntry ( i18n ( "Username: %1" ).arg ( UsernameStr ), GlobalConfig->debug ); + + if ( GlobalConfig->currentProfile->getUseNtDomainName() && !GlobalConfig->currentProfile->getNtDomainName().isEmpty() ) + { + // stream << GlobalConfig->currentProfile->getName() + " " << GlobalConfig->currentProfile->getNtDomainName() << "\\\\" << UsernameStr + " " << GlobalConfig->TmpPassword << " *\n"; + stream << "\"" << GlobalConfig->currentProfile->getNtDomainName() << "\\\\" << UsernameStr << "\" " + GlobalConfig->currentProfile->getName() + " \"" << GlobalConfig->TmpPassword << "\" *\n"; + } + else + { + // stream << GlobalConfig->currentProfile->getName() + " " << UsernameStr + " " << GlobalConfig->TmpPassword << " *\n"; + stream << "\"" << UsernameStr + "\" " << GlobalConfig->currentProfile->getName() + " \"" << GlobalConfig->TmpPassword << "\" *\n"; + } + stream << "# --- generated by kvpnc. Do not edit it." << "\n"; + file.close(); + + + Utils ( GlobalConfig, this ).doChmod ( "/etc/ppp/chap-secrets", "go-rwx" ); + } + } + if ( GlobalConfig->currentProfile->getAuthMethod() == "pap" ) + { + +// GlobalConfig->appendLogEntry ( i18n ( "Creating of %1 failed!" ).arg ( "pppd secrets file" ), GlobalConfig->error ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Authentication method: %1" ).arg ( GlobalConfig->currentProfile->getAuthMethod() ), GlobalConfig->debug ); + + + Utils ( GlobalConfig, this ).doChmod ( "/etc/ppp/chap-secrets", "go-rwx" ); + + stream << "# use pap" << "\n"; + stream << pppdcap.RequireAuthPapOption << "\n"; + + + // write pppd /etc/ppp/pap-secrets + QString papSecrets = "/etc/ppp/pap-secrets"; // /etc/ppp/pap-secrets + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "pppd secrets file: %1" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + file.setName ( papSecrets ); + stream.setDevice ( &file ); + if ( file.open ( IO_WriteOnly | IO_Append ) ) + { + stream << "# +++ generated by kvpnc. Do not edit it." << "\n"; + stream << "# profile: " + GlobalConfig->currentProfile->getName() << "\n"; + + if ( GlobalConfig->currentProfile->getSaveUserPassword() ) + GlobalConfig->TmpPassword = GlobalConfig->currentProfile->getUserPassword(); + + QString UsernameStr; + if ( !GlobalConfig->currentProfile->getDontSaveUsername() ) + UsernameStr = GlobalConfig->currentProfile->getUserName(); + else + UsernameStr = GlobalConfig->TmpUsername; + + GlobalConfig->appendLogEntry ( i18n ( "Username: %1" ).arg ( UsernameStr ), GlobalConfig->debug ); + + if ( GlobalConfig->currentProfile->getUseNtDomainName() && !GlobalConfig->currentProfile->getNtDomainName().isEmpty() ) + { + // stream << GlobalConfig->currentProfile->getName() + " " << GlobalConfig->currentProfile->getNtDomainName() << "\\\\" << UsernameStr + " " << GlobalConfig->TmpPassword << " *\n"; + stream << "\"" << GlobalConfig->currentProfile->getNtDomainName() << "\\\\" << UsernameStr << "\" " + GlobalConfig->currentProfile->getName() + " " << GlobalConfig->TmpPassword << " *\n"; + } + else + { + // stream << GlobalConfig->currentProfile->getName() + " " << UsernameStr + " " << GlobalConfig->TmpPassword << " *\n"; + stream << UsernameStr + " " << GlobalConfig->currentProfile->getName() + " " << GlobalConfig->TmpPassword << " *\n"; + } + stream << "# --- generated by kvpnc. Do not edit it." << "\n"; + file.close(); + + + Utils ( GlobalConfig, this ).doChmod ( "/etc/ppp/pap-secrets", "go-rwx" ); + } + } + file.close(); + /* + if (GlobalConfig->currentProfile->getAuthMethod() != "chap" && GlobalConfig->currentProfile->getAuthMethod() != "chap") + GlobalConfig->currentProfile->setAuthMethod("chap");*/ + Utils::PppdCapabilities pppdcap = Utils ( GlobalConfig ).checkPppdCapabilities(); + pppdHasReplacedefaultrouteSupport = pppdcap.pppdHasReplacedefaultrouteSupport; + + + QFile pppdbackupdefaultroutefile ( tmpPath + "pppd." + GlobalConfig->currentProfile->getName() + ".backup_default_route.sh" ); + QTextStream pppdbackupdefaultroutestream ( &pppdbackupdefaultroutefile ); + if ( pppdbackupdefaultroutefile.open ( IO_WriteOnly ) ) + { + pppdbackupdefaultroutestream << "#!"<< GlobalConfig->InterpreterShell << "\n"; + pppdbackupdefaultroutestream << "# generated by kvpnc. Do not edit it." << "\n"; + pppdbackupdefaultroutestream << "# profile: " + GlobalConfig->currentProfile->getName() << "\n\n"; + pppdbackupdefaultroutestream << GlobalConfig->pathToIp << " route show | grep default | head -n1 > " << OldDefaultroute << "\n"; + pppdbackupdefaultroutefile.close(); + } + + + + QProcess *backupDefaultRouteProcess = new QProcess ( this ); + backupDefaultRouteProcess->addArgument ( GlobalConfig->InterpreterShell ); + backupDefaultRouteProcess->addArgument ( tmpPath + "pppd." + GlobalConfig->currentProfile->getName() + ".backup_default_route.sh" ); + + if ( !backupDefaultRouteProcess->start ( env ) ) + { + KMessageBox::sorry ( this, i18n ( "\"%1\" (%2) start failed!" ).arg ( "PppdBackupDefaultRouteScript" ).arg ( tmpPath + "pppd." + GlobalConfig->currentProfile->getName() + ".backup_default_route.sh" ) ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" (%2) started." ).arg ( "PppdBackupDefaultRouteScript" ).arg ( tmpPath + "pppd." + GlobalConfig->currentProfile->getName() + ".backup_default_route.sh" ) , GlobalConfig->debug ); + while ( backupDefaultRouteProcess->isRunning() ) + parent->QApplication::processEvents(); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" (%2) finished." ).arg ( "PppdBackupDefaultRouteScript" ).arg ( tmpPath + "pppd." + GlobalConfig->currentProfile->getName() + ".up" ) , GlobalConfig->debug ); + } + delete backupDefaultRouteProcess; + backupDefaultRouteProcess=0L; + + + + // load the module 'ppp_mppe' + QFile modprobe_confFile ( "/etc/modprobe.conf" ); + if ( modprobe_confFile.exists() ) + { + QString modprobe_confFileContent = ""; + bool ppp_compress_18_found = false; + if ( modprobe_confFile.open ( IO_ReadOnly ) ) + { + QTextStream stream ( &modprobe_confFile ); + QString line = ""; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' + if ( line.contains ( "ppp-compress-18", false ) ) + { + ppp_compress_18_found = true; + break; + } + } + modprobe_confFile.close(); + if ( !ppp_compress_18_found ) + { + if ( !modprobe_confFile.open ( IO_WriteOnly | IO_Append ) ) + { + GlobalConfig->appendLogEntry ( i18n ( "%1 cannot be opened for append!" ).arg ( "/etc/modprobe.conf" ) , GlobalConfig->error ); + } + else + { + + stream.setDevice ( &modprobe_confFile ); + if ( !Utils ( GlobalConfig, parent ).loadKernelModule ( "ppp_mppe", parent ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Loading module \"%1\" failed, adding \"ppp_mppe_mppc\" to %2." ).arg ( "ppp_mppe" ).arg ( "/etc/modprobe.conf" ), GlobalConfig->debug ); + stream << "\n" << "# added by kvpnc, do not edit it.\n" << "alias ppp-compress-18 ppp_mppe_mppc\n"; + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Loading module \"%1\" succeded, adding \"ppp_mppe\" to %2." ).arg ( "ppp_mppe" ).arg ( "/etc/modprobe.conf" ), GlobalConfig->debug ); + stream << "\n" << "# added by kvpnc, do not edit it.\n" << "alias ppp-compress-18 ppp_mppe\n"; + } + + modprobe_confFile.close(); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "%1 found \"%2\" alias missing. KVpnc has been added it." ).arg ( "/etc/modprobe.conf" ).arg ( "ppp-compress-18" ), GlobalConfig->debug ); + } + } + } + } + + bool load_module_ok=true; + if ( !Utils ( GlobalConfig, parent ).loadKernelModule ( "ppp-compress-18", parent ) ) + { + //KMessageBox::information( this, i18n( "Loading of module \"%1\" failed!" ).arg("\"ppp-compress-18\" (ppp_mppe)")); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Loading module \"%1\" has been failed, trying \"%2\"..." ).arg ( "ppp-compress-18" ).arg ( "ppp_mppe" ), GlobalConfig->debug ); + + if ( !Utils ( GlobalConfig, parent ).loadKernelModule ( "ppp_mppe", parent ) ) + { + GlobalConfig->appendLogEntry ( i18n ( "Loading module \"%1\" and \"%2\" has been failed: stop." ).arg ( "ppp-compress-18" ).arg ( "ppp_mppe" ), GlobalConfig->error ); + setGuiStatus ( disconnected ); + disconnectClicked(); + load_module_ok=false; + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Loading module \"%1\" has been failed, but \"%2\" succeded." ).arg ( "ppp-compress-18" ).arg ( "ppp_mppe" ), GlobalConfig->debug ); + load_module_ok=true; + } + } + + if ( load_module_ok ) + { + + } + //sleep(2); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "pppd: " + GlobalConfig->pathToPppd + "\n", GlobalConfig->debug ); + PptpProcess = new QProcess ( this ); + + PptpProcess->addArgument ( GlobalConfig->pathToPppd ); + PptpProcess->addArgument ( "call" ); + PptpProcess->addArgument ( QString ( "kvpnc." + GlobalConfig->currentProfile->getName() ) ); + + // PptpProcess->addArgument( GlobalConfig->InterpreterShell ); + // PptpProcess->addArgument( "/home/crissi/pppd.sh" ); + + connect ( PptpProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_pptp() ) ); + connect ( PptpProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_pptp() ) ); + + + + GlobalConfig->appendLogEntry ( i18n ( "Trying to connect to server \"%1\" with user \"%2\"...\n" ).arg ( GlobalConfig->currentProfile->getGateway() ).arg ( GlobalConfig->currentProfile->getUserName() ), GlobalConfig->debug ); + + setenv ( "DNS_UPDATE", ( GlobalConfig->currentProfile->getUseDnsUpdate() ? "Yes" : "NO" ), 1 ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Setting DNS_UPDATE \"%1\"." ).arg ( getenv ( "DNS_UPDATE" ) ), GlobalConfig->debug ); + + if ( !PptpProcess->start ( env ) ) + { + KMessageBox::sorry ( this, i18n ( "\"%1\" start failed!" ).arg ( "pppd" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "pppd" ), GlobalConfig->error ); + disconnect ( PptpProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_pptp() ) ); + disconnect ( PptpProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_pptp() ) ); + disconnectClicked(); + setGuiStatus ( disconnected ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( "pppd" ), GlobalConfig->debug ); + ConnectingProcess = VpnAccountData::pptp; + GlobalConfig->status = GlobalConfig->connecting; + mw->buttonDisconnect->setEnabled ( true ); + this->DisconnectAction->setEnabled ( true ); + mw->buttonConnect->setEnabled ( false ); + this->ConnectAction->setEnabled ( false ); + //connect ( PptpProcess, SIGNAL( processExited () ), this, SLOT( pppdStarted() ) ); + + // connect( &timer, SIGNAL( timeout() ), this, SLOT( slotConnectTimedOut() ) ); + // timer.start( tryConnectTimeout * 1000, FALSE ); + + //connect ( PptpProcess, SIGNAL ( processExited() ), this, SLOT ( pptpProcessExited() ) ); + + } + + + } + } + else + { + if (AuthRetry) + disconnectClicked(); + setGuiStatus ( disconnected ); + return ; + } + } // pptp + + /* ============ openvpn ================ */ + else if ( GlobalConfig->currentProfile != 0 && GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::openvpn ) + { + //setGuiStatus(connecting); + tmpPath = locateLocal ( "data", "kvpnc/" ); + QString OpenvpnSecrectPath = tmpPath + "openvpn." + GlobalConfig->currentProfile->getName() + ".secret"; + + // looking for openvpn + if ( Utils ( GlobalConfig ).getToolInfo ( "openvpn" )->found == false ) + { + KMessageBox::error ( this, i18n ( "Unable to find \"%1\" at \"%2\"!" ).arg ( "openvpn" ).arg ( GlobalConfig->pathToOpenvpn ) ); + GlobalConfig->appendLogEntry ( i18n ( "Unable to find \"%1\" at \"%2\"!" ).arg ( "openvpn" ).arg ( GlobalConfig->pathToOpenvpn ), GlobalConfig->error ); + ok = false; + setGuiStatus ( disconnected ); + return ; + } + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "openvpn: %1" ) .arg ( GlobalConfig->pathToOpenvpn ) , GlobalConfig->debug ); + + { + + if ( GlobalConfig->currentProfile->authtype == VpnAccountData::cert ) + { + + if ( GlobalConfig->currentProfile->getUseSmartcard() ) + { + /* use cert on smartcard */ + // Utils(GlobalConfig).getSmartcardInfo(); + // if ( GlobalConfig->pathToPkcs11Tool.isEmpty() || KStandardDirs::findExe( GlobalConfig->pathToPkcs11Tool.section( '/', -1, -1 ), GlobalConfig->pathTopathToPkcs11Tool.section( '/', 0, -2 ) ).isEmpty() ) + // { + // KMessageBox::error( this, i18n( "Unable to find \"%1\" at \"%2\"!" ).arg( "pkcs11-tool" ).arg( GlobalConfig->pathToPkcs11Tool) ); + // GlobalConfig->appendLogEntry( i18n( "Unable to find \"%1\" at \"%2\"!" ).arg( "pkcs11-tool" ).arg( GlobalConfig->pathToPkcs11Tool ), GlobalConfig->error ); + // ok = false; + // setGuiStatus( disconnected ); + // return ; + // } + + if ( GlobalConfig->currentProfile->getPkcs11Slot().isEmpty() ) + { + KMessageBox::error ( this, i18n ( "Pkcs11 slot cant be empty!" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Pkcs11 slot cant be empty!" ), GlobalConfig->error ); + ok = false; + setGuiStatus ( disconnected ); + return ; + } + if ( GlobalConfig->currentProfile->getPkcs11Id().isEmpty() ) + { + KMessageBox::error ( this, i18n ( "Pkcs11 id cant be empty!" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Pkcs11 id cant be empty!" ), GlobalConfig->error ); + ok = false; + setGuiStatus ( disconnected ); + return ; + } + if ( GlobalConfig->currentProfile->getUsePkcs11Providers() && GlobalConfig->currentProfile->getPkcs11Providers().isEmpty() ) + { + KMessageBox::error ( this, i18n ( "Pkcs11 providers cant be empty!" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Pkcs11 providers cant be empty!" ), GlobalConfig->error ); + ok = false; + setGuiStatus ( disconnected ); + return ; + } + } + else + { + /* use cert on filesystem */ + QFile CertTmpFile; + if ( ! GlobalConfig->currentProfile->getUseOnlyCaCertAndUserAuth() ) + { + CertTmpFile.setName ( GlobalConfig->currentProfile->getX509Certificate() ); + if ( !CertTmpFile.exists() ) + { + // KMessageBox::error( 0, i18n( "Certificate file (%1) could not be found. Please check the path of it." ).arg( GlobalConfig->currentProfile->getX509Certificate() ), i18n( "File Not Found" ) ); + // GlobalConfig->appendLogEntry( i18n( "Certificate file (%1) could not be found. Please check the path of it." ).arg( GlobalConfig->currentProfile->getX509Certificate() ), GlobalConfig->error ); + // ok = false; + // setGuiStatus( disconnected ); + // return ; + } + else + { + CertTmpFile.setName ( GlobalConfig->currentProfile->getPrivateKey() ); + if ( !CertTmpFile.exists() ) + { + KMessageBox::error ( 0, i18n ( "Private key file (%1) could not be found. Please check the path of it." ).arg ( GlobalConfig->currentProfile->getPrivateKey() ), i18n ( "File Not Found" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Private key file (%1) could not be found. Please check the path of it." ).arg ( GlobalConfig->currentProfile->getPrivateKey() ) , GlobalConfig->error ); + ok = false; + setGuiStatus ( disconnected ); + return ; + } + } + } // only if real certificate + + CertTmpFile.setName ( GlobalConfig->currentProfile->getCaCertificate() ); + if ( !CertTmpFile.exists() ) + { + KMessageBox::error ( 0, i18n ( "CA certificate file (%1) could not be found. Please check the path of it." ).arg ( GlobalConfig->currentProfile->getCaCertificate() ), i18n ( "File Not Found" ) ); + GlobalConfig->appendLogEntry ( i18n ( "CA certificate file (%1) could not be found. Please check the path of it." ).arg ( GlobalConfig->currentProfile->getCaCertificate() ) , GlobalConfig->error ); + ok = false; + setGuiStatus ( disconnected ); + return ; + } + } + } + + bool tunsupportfound = false; + QString procmisc = ""; + QFile f ( "/proc/misc" ); + if ( f.open ( IO_ReadOnly ) ) + { + QTextStream stream ( &f ); + QString line = ""; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' + if ( line.contains ( "tun", false ) ) + { + tunsupportfound = true; + break; + } + } + } + f.close(); + if ( tunsupportfound ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Support for TUN/TAP found (compiled into kernel or kernel module already loaded)." ), GlobalConfig->debug ); + + QFile tundevfile ( "/dev/net/tun" ); + if ( !tundevfile.exists() ) + { + if ( !Utils ( GlobalConfig, parent ).createTunDev() ) + { + KMessageBox::error ( this, i18n ( "Creating of \"%1\" has been failed!" ).arg ( "/dev/net/tun" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Tunnel device is missing, creating has been failed: stop." ), GlobalConfig->error ); + disconnectClicked(); + setGuiStatus ( disconnected ); + GlobalConfig->status = GlobalConfig->disconnected; + return ; + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Tunnel device is missing, creating has been succeded." ), GlobalConfig->debug ); + } + } + } + else + { + // load the module 'tun' + if ( !Utils ( GlobalConfig, parent ).loadKernelModule ( "tun", parent ) ) + { + KMessageBox::information ( this, i18n ( "Loading of module \"%1\" failed!" ).arg ( "tun" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Tunnel device is missing, loading module \"%1\" has failed: stop." ).arg ( "tun" ), GlobalConfig->error ); + disconnectClicked(); + setGuiStatus ( disconnected ); + GlobalConfig->status = GlobalConfig->disconnected; + return ; + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Loading of module \"%1\" was successful." ).arg ( "tun" ), GlobalConfig->debug ); + } + } + + // GlobalConfig->TmpGatewayIP = Utils( GlobalConfig, parent ).resolveName(GlobalConfig->currentProfile->getGateway()); + // if (GlobalConfig->TmpGatewayIP=="0.0.0.0" || GlobalConfig->TmpGatewayIP.isEmpty()) + // { + // KMessageBox::error( this, i18n( "Host \"%1\" could not be resolved!" ).arg(GlobalConfig->currentProfile->getGateway()) ); + // GlobalConfig->appendLogEntry(i18n( "Host \"%1\" could not be resolved!" ).arg(GlobalConfig->currentProfile->getGateway()),GlobalConfig->error); + // ok =false; + // } + // else + // { + // GlobalConfig->appendLogEntry( i18n( "Gateway hostname (%1) resolved to \"%2\"." ).arg(GlobalConfig->currentProfile->getGateway()).arg(GlobalConfig->TmpGatewayIP), GlobalConfig->info ); + // } + + bool askUsernamePass = false; + bool requestUsername = false; + bool requestGrouppassword = false; + bool needSave=false; + + if ( GlobalConfig->currentProfile->getAskUserPasswordOnEachConnect() ) + { + if ( GlobalConfig->KvpncDebugLevel > 4 ) + GlobalConfig->appendLogEntry ( i18n ( "User password on each connect forced." ), GlobalConfig->debug ); + + askUsernamePass = true; + requestUsername = true; + } + + if ( !GlobalConfig->haveUserData ) + { + + + if ( GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) + { + + if ( GlobalConfig->currentProfile->getSaveUserPassword() && GlobalConfig->currentProfile->getUserPassword().isEmpty()) + { + askUsernamePass = true; + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Empty user password" ), GlobalConfig->debug ); + } + if ( !GlobalConfig->currentProfile->getSaveUserPassword() && GlobalConfig->TmpPassword.isEmpty()) + { + askUsernamePass = true; + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Empty tmp user password" ), GlobalConfig->debug ); + } + + if ( !GlobalConfig->currentProfile->getDontSaveUsername() ) + { + requestUsername = GlobalConfig->currentProfile->getUserName().isEmpty(); + } + else + { + requestUsername = GlobalConfig->TmpUsername.isEmpty(); + } + + if ( AuthRetry ) + { + askUsernamePass = true; + requestUsername = true; + } + } + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::psk ) + { + if ( !GlobalConfig->currentProfile->getPskIsInFile() && GlobalConfig->currentProfile->getPreSharedKey().isEmpty() ) + askUsernamePass = true; + + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Psk is empty" ), GlobalConfig->debug ); + } + } + + if ( AuthRetry ) + { + askUsernamePass = true; + requestUsername = true; + } + + if ( askUsernamePass ) + { + + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::psk && !GlobalConfig->currentProfile->getPskIsInFile() && GlobalConfig->currentProfile->getPreSharedKey().isEmpty() ) + requestGrouppassword = true; + + EnterUsernamePasswordDialog dlg ( this, i18n ( "Enter Account Data" ), requestGrouppassword, requestUsername ); + dlg.main->SaveUsernameCheckBox->setChecked(!GlobalConfig->currentProfile->getDontSaveUsername()); + dlg.main->SavePasswordCheckBox->setChecked(GlobalConfig->currentProfile->getSaveUserPassword()); + + if ( ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::psk && !GlobalConfig->currentProfile->getPskIsInFile() && GlobalConfig->currentProfile->getPreSharedKey().isEmpty() ) && !GlobalConfig->currentProfile->getUseTlsAuth() ) + { + dlg.main->UsernameEdit->hide(); + dlg.main->PasswordEdit->hide(); + + if ( dlg.exec() ) + { + GlobalConfig->TmpGroupPassword = dlg.main->PSKLineEdit->text(); + + if ( GlobalConfig->TmpGroupPassword.isEmpty() ) + { + GlobalConfig->appendLogEntry ( i18n ( "PSK is empty" ), GlobalConfig->error ); + ok = false; + } + + if ( dlg.main->SavePskCheckBox->isChecked() && requestGrouppassword ) + { + GlobalConfig->currentProfile->setSavePsk ( true ); + GlobalConfig->currentProfile->setPreSharedKey ( GlobalConfig->TmpGroupPassword ); + needSave=true; + } + else + { + GlobalConfig->currentProfile->setSavePsk ( false ); + needSave = true; + } + + } + else + { + ok = false; + AuthRetry = false; + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Connect canceled because password enter dialog aborted." ), GlobalConfig->debug ); + } + } + else + { + if ( GlobalConfig->currentProfile->getSaveUserPassword() ) + dlg.main->PasswordEdit->setText ( GlobalConfig->currentProfile->getUserPassword() ); + + dlg.main->UsernameEdit->setText ( GlobalConfig->currentProfile->getUserName() ); + if ( !dlg.main->UsernameEdit->text().isEmpty() ) //go straight to pw if username present + dlg.main->PasswordEdit->setFocus(); + + if ( dlg.exec() ) + { + GlobalConfig->TmpUsername = dlg.main->UsernameEdit->text(); + GlobalConfig->TmpPassword = dlg.main->PasswordEdit->text(); + + + if ( GlobalConfig->TmpPassword.isEmpty() ) + { + GlobalConfig->appendLogEntry ( i18n ( "Password is empty" ), GlobalConfig->error ); + ok = false; + } + + if ( requestUsername && GlobalConfig->TmpUsername.isEmpty() ) + { + GlobalConfig->appendLogEntry ( i18n ( "Username is empty!" ), GlobalConfig->error ); + ok = false; + } + + if ( dlg.main->SaveUsernameCheckBox->isChecked() && requestUsername ) + { + GlobalConfig->currentProfile->setDontSaveUsername ( false ); + GlobalConfig->currentProfile->setUserName ( dlg.main->UsernameEdit->text() ); + needSave=true; + } + if ( dlg.main->SaveUsernameCheckBox->isChecked()) + { + GlobalConfig->TmpUsername = dlg.main->UsernameEdit->text(); + GlobalConfig->currentProfile->setDontSaveUsername ( false ); + needSave = true; + } + + + if ( dlg.main->SavePskCheckBox->isChecked() && requestGrouppassword ) + { + GlobalConfig->currentProfile->setSavePsk ( true ); + GlobalConfig->currentProfile->setPreSharedKey ( GlobalConfig->TmpGroupPassword ); + needSave=true; + } + else + { + GlobalConfig->currentProfile->setSavePsk ( false ); + } + + if ( dlg.main->SavePasswordCheckBox->isChecked() ) + { + GlobalConfig->currentProfile->setSaveUserPassword ( true ); + GlobalConfig->currentProfile->setUserPassword ( GlobalConfig->TmpPassword ); + needSave = true; + } + else + { + GlobalConfig->currentProfile->setSaveUserPassword ( false ); + needSave = true; + } + + } + else + { + ok = false; + AuthRetry = false; + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Connect canceled because password enter dialog aborted." ), GlobalConfig->debug ); + } + + } + + if ( needSave ) + GlobalConfig->saveOptions(true, GlobalConfig->currentProfile->getName()); + + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Some passwords which are need got from password enter dialog." ), GlobalConfig->debug ); + + AuthRetry = false; + GlobalConfig->haveUserData=true; + + // QFile OpenvpnSecrectFile (OpenvpnSecrectPath); + // QTextStream openvpn_secret_stream( &OpenvpnSecrectFile); + // if ( OpenvpnSecrectFile.open( IO_WriteOnly ) ) + // { + // if (GlobalConfig->TmpUsername.isEmpty()) + // openvpn_secret_stream << GlobalConfig->currentProfile->getUserName() << "\n"; + // else + // openvpn_secret_stream << GlobalConfig->TmpUsername << "\n"; + // if (GlobalConfig->TmpPassword.isEmpty()) + // openvpn_secret_stream << GlobalConfig->currentProfile->getUserPassword() << "\n"; + // else + // openvpn_secret_stream << GlobalConfig->TmpPassword<< "\n"; + // } + + } + + // here we go + if ( ok ) + { + if ( GlobalConfig->currentProfile->getTunnelDeviceType() == "tun" ) + OpenvpnDevice = "tun0"; + else + OpenvpnDevice = "tap0"; + + if ( GlobalConfig->currentProfile->getExecuteCmdBeforeConnect() ) + executeCommandBeforeConnect(); + + mw->buttonConnect->setEnabled ( false ); + tmpPath = locateLocal ( "data", "kvpnc/" ); + + QString tmpInterface; + QString LocalIP; + NetworkInterface iface ( GlobalConfig, parent ); + if ( GlobalConfig->currentProfile->getNetworkDevice() == "default" ) + { + tmpInterface = iface.getDefaultInterface(); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Default interface: \"%1\"." ).arg ( tmpInterface ) , GlobalConfig->debug ); + LocalIP = iface.getInterfaceIP ( iface.getDefaultInterface() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "IP address of default interface: \"%1\"." ).arg ( LocalIP ) , GlobalConfig->debug ); + } + else + { + tmpInterface = GlobalConfig->currentProfile->getNetworkDevice(); + LocalIP = iface.getInterfaceIP ( GlobalConfig->currentProfile->getNetworkDevice() ); + } + if ( tmpInterface.isEmpty() ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "No default interface found, using \"lo\"." ) , GlobalConfig->debug ); + tmpInterface = "lo"; // no default interface found :( + } + + if ( LocalIP.isEmpty() ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "No IP for default interface found, using \"127.0.0.1\"." ), GlobalConfig->debug ); + LocalIP = "127.0.0.1"; // no IP for default interface found :( + } + + //if (GlobalConfig->KvpncDebugLevel > 0) + // { + // GlobalConfig->appendLogEntry( "debug: local virtual ip: "+GlobalConfig->currentProfile->getLocalVirtualIP(),GlobalConfig->debug ); + // GlobalConfig->appendLogEntry( "debug: remote virtual ip: "+GlobalConfig->currentProfile->getRemoteVirtualIP(),GlobalConfig->debug ); + // } + // write openvpn..conf + QFile openvpn_file ( tmpPath + "openvpn." + GlobalConfig->currentProfile->getName() + ".conf" ); + QTextStream openvpn_stream ( &openvpn_file ); + if ( openvpn_file.open ( IO_WriteOnly ) ) + { + openvpn_stream << "# generated by kvpnc. Do not edit it." << "\n"; + openvpn_stream << "# profile: " + GlobalConfig->currentProfile->getName() << "\n\n"; + openvpn_stream << "# verbosity" << "\n"; + openvpn_stream << "verb " << GlobalConfig->OpenvpnDebugLevel << "\n\n"; + + QString certPath = "/etc/openvpn"; + if ( !GlobalConfig->currentProfile->getCertPath().isEmpty() ) + certPath = GlobalConfig->currentProfile->getCertPath(); + + openvpn_stream << "# change to prefix" << "\n"; + openvpn_stream << "cd " << certPath << "\n\n"; + + if ( GlobalConfig->currentProfile->getTunnelDeviceType() == "tun" ) + { + openvpn_stream << "# use tun device" << "\n"; + openvpn_stream << "dev tun" << "\n\n"; + } + else + { + openvpn_stream << "# use tap device" << "\n"; + openvpn_stream << "dev tap" << "\n\n"; + } + + if ( GlobalConfig->currentProfile->getDisableBind() ) + { + openvpn_stream << "# dont listen" << "\n"; + openvpn_stream << "nobind" << "\n\n"; + } + + // openvpn > 2.1-rc9 we need script security parameter (http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=494998) + ToolInfo *OpenvpnToolInfo = Utils ( GlobalConfig ).getToolInfo ( "openvpn" ) ; + int OpenvpnMajor = OpenvpnToolInfo->Version.section ( ".",0,0 ).toInt(); + int OpenvpnMinor = OpenvpnToolInfo->Version.section ( ".",1,1 ).section ( "_",0,0 ).toInt(); + QString OpenvpnExtra=""; + int OpenvpnExtraVer=0; + if ( OpenvpnToolInfo->Version.section ( ".",1,1 ).find ( "_", 0, FALSE ) > -1 ) + { + if ( OpenvpnToolInfo->Version.section ( ".",1,1 ).section ( "_",1,1 ).find ( "beta", 0, FALSE ) > -1 ) + { + OpenvpnExtra = "beta"; + OpenvpnExtraVer = OpenvpnToolInfo->Version.section ( ".",1,1 ).section ( "_",1,1 ).section ( "beta",1,1 ).toInt(); + } + if ( OpenvpnToolInfo->Version.section ( ".",1,1 ).section ( "_",1,1 ).find ( "rc", 0, FALSE ) > -1 ) + { + OpenvpnExtra = "rc"; + OpenvpnExtraVer = OpenvpnToolInfo->Version.section ( ".",1,1 ).section ( "_",1,1 ).section ( "rc",1,1 ).toInt(); + } + } + if ( GlobalConfig->KvpncDebugLevel > 4 ) + { + GlobalConfig->appendLogEntry ( i18n ( "OpenVPN major: %1, minor: %2, extra: %3, extra ver: %4" ).arg ( QString().setNum ( OpenvpnMajor ) ).arg ( QString().setNum ( OpenvpnMinor ) ).arg ( OpenvpnExtra ).arg ( QString().setNum ( OpenvpnExtraVer ) ),GlobalConfig->debug ); + } + + + if ( GlobalConfig->OpenvpnNeedSecurityParameter || ( OpenvpnMajor == 2 && OpenvpnMinor == 1 && OpenvpnExtraVer > 8 && OpenvpnExtra == "rc" ) || ( OpenvpnMajor == 2 && OpenvpnMinor == 1 ) || ( OpenvpnMajor > 2 && OpenvpnMinor >= 2 ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "OpenVPN >= 2.1-rc9 detected, adding script security parameter to config." ),GlobalConfig->info ); + + openvpn_stream << "# script security: allow program exec" << "\n"; + openvpn_stream << "script-security 2" << "\n"; + openvpn_stream << "" << "\n"; + } + + if ( GlobalConfig->currentProfile->getDisableLzoCompression() == false ) + { + openvpn_stream << "# compression" << "\n"; + openvpn_stream << "comp-lzo" << "\n\n"; + } + openvpn_stream << "" << "\n"; + + openvpn_stream << "# try to resolve names infinite" << "\n"; + openvpn_stream << "resolv-retry infinite" << "\n\n"; + + openvpn_stream << "" << "\n"; + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::cert ) + { + openvpn_stream << "" << "\n"; + openvpn_stream << "# ca" << "\n"; + openvpn_stream << "ca " << GlobalConfig->currentProfile->getCaCertificate() << "\n\n"; + if ( GlobalConfig->currentProfile->getUseSmartcard() ) + { + /* use cert on smartcard */ + openvpn_stream << "# use smartcard" << "\n"; + if ( !GlobalConfig->currentProfile->getPkcs11Providers().isEmpty() ) + openvpn_stream << "pkcs11-providers \"" << GlobalConfig->currentProfile->getPkcs11Providers() << "\"\n"; + + openvpn_stream << "pkcs11-id \"" << GlobalConfig->currentProfile->getPkcs11Id() << "\"\n"; + if ( ( OpenvpnMajor == 2 && OpenvpnMinor == 1 && OpenvpnExtraVer < 10 && OpenvpnExtra == "rc" ) || ( OpenvpnMajor < 2 ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "OpenVPN =< 2.1-rc9 detected, adding additional pkcs11 parameters." ),GlobalConfig->info ); + + openvpn_stream << "pkcs11-slot-type \"" << GlobalConfig->currentProfile->getPkcs11SlotType() << "\"\n"; + // we have to split slot id and name ("0 : foobar") => 0 + QString Pkcs11Slot = GlobalConfig->currentProfile->getPkcs11Slot().section ( ':', 0, 0 ).stripWhiteSpace(); + openvpn_stream << "pkcs11-slot \"" << Pkcs11Slot << "\"\n"; + openvpn_stream << "pkcs11-id-type \"" << GlobalConfig->currentProfile->getPkcs11IdType() << "\"\n"; + openvpn_stream << "pkcs11-sign-mode \"" << GlobalConfig->currentProfile->getPkcs11SignMode() << "\"\n"; + } + openvpn_stream << "\n"; + } + else + { + /* use cert on filesystem */ + QFile CertTmpFile; + if ( !GlobalConfig->currentProfile->getUseOnlyCaCertAndUserAuth() ) + { + CertTmpFile.setName ( GlobalConfig->currentProfile->getX509Certificate() ); + if ( CertTmpFile.exists() ) + { + openvpn_stream << "# client cert" << "\n"; + openvpn_stream << "cert " << GlobalConfig->currentProfile->getX509Certificate() << "\n\n"; + openvpn_stream << "" << "\n"; + + QFile PrivateKeyTmpFile ( GlobalConfig->currentProfile->getPrivateKey() ); + // if ( PrivateKeyTmpFile.exists() ) + { + openvpn_stream << "# client private key" << "\n"; + openvpn_stream << "key \"" << GlobalConfig->currentProfile->getPrivateKey() << "\"\n\n"; + + } + } + } // if real cert + } + + openvpn_stream << "# client side" << "\n"; + openvpn_stream << "tls-client" << "\n"; + openvpn_stream << "pull" << "\n\n"; + + openvpn_stream << "# diffie hellman parameters" << "\n"; + openvpn_stream << "dh dh1024.pem" << "\n\n"; + + } + else if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::psk ) + { + openvpn_stream << "# client psk" << "\n"; + if ( GlobalConfig->currentProfile->getPskIsInFile() ) + { + QString direction=""; + if ( GlobalConfig->currentProfile->getAuthenticationDirection() != "none" ) + direction= GlobalConfig->currentProfile->getAuthenticationDirection(); + openvpn_stream << "secret " << GlobalConfig->currentProfile->getPreSharedKeyFile() << " " << direction << "\n\n"; + } + else + { + // write openvpn..secret + QFile openvpn_secretfile ( tmpPath + "openvpn." + GlobalConfig->currentProfile->getName() + ".secret" ); + QTextStream openvpn_secretstream ( &openvpn_secretfile ); + if ( openvpn_secretfile.open ( IO_WriteOnly ) ) + { + openvpn_secretstream << "# generated by kvpnc. Do not edit it." << "\n"; + openvpn_secretstream << "# profile: " + GlobalConfig->currentProfile->getName() << "\n\n"; + openvpn_secretstream << GlobalConfig->currentProfile->getPreSharedKey() << "\n\n"; + } + openvpn_secretfile.close(); + QString direction=""; + if ( GlobalConfig->currentProfile->getAuthenticationDirection() != "none" ) + direction= GlobalConfig->currentProfile->getAuthenticationDirection(); + openvpn_stream << "secret " << tmpPath + "openvpn." + GlobalConfig->currentProfile->getName() + ".secret " << direction << "\n\n"; + } + } + + if ( GlobalConfig->currentProfile->getUseUdp() ) + { + openvpn_stream << "\n"; + openvpn_stream << "# use udp" << "\n"; + openvpn_stream << "proto udp" << "\n\n"; + + + if ( GlobalConfig->currentProfile->getUseMssfix() ) + { + openvpn_stream << "\n"; + openvpn_stream << "# userdefined packet size" << "\n"; + openvpn_stream << "mssfix " << GlobalConfig->currentProfile->getMssfix() << "\n\n"; + } + + } + else + { + openvpn_stream << "" << "\n"; + openvpn_stream << "# use tcp" << "\n"; + openvpn_stream << "proto tcp-client" << "\n\n"; + } + + openvpn_stream << "" << "\n"; + openvpn_stream << "# remote side" << "\n"; + openvpn_stream << "remote " << GlobalConfig->currentProfile->getGateway(); + // openvpn_stream << "remote " << GlobalConfig->TmpGatewayIP;; + if ( GlobalConfig->currentProfile->getUseRemotePort() ) + openvpn_stream << " " << GlobalConfig->currentProfile->getRemotePort(); + openvpn_stream << "\n\n"; + + if ( GlobalConfig->currentProfile->getUseVirtualIP() ) + { + openvpn_stream << "" << "\n"; + openvpn_stream << "# virtual ip addresses" << "\n"; + openvpn_stream << "ifconfig " << GlobalConfig->currentProfile->getLocalVirtualIP() << " " << GlobalConfig->currentProfile->getRemoteVirtualIP() << "\n\n"; + + +// QString RemoteNetAddr = GlobalConfig->currentProfile->getRemoteNetAddr(); +// int RemoteNetMaskNum = GlobalConfig->currentProfile->getRemoteNetMask().toInt(); +// QString RemoteNetMask = "255.255.255.0"; +// if ( RemoteNetMaskNum == 24 ) +// RemoteNetMask = "255.255.255.0"; +// else if ( RemoteNetMaskNum == 25 ) +// RemoteNetMask = "255.255.255.128"; +// else if ( RemoteNetMaskNum == 26 ) +// RemoteNetMask = "255.255.255.192"; +// else if ( RemoteNetMaskNum == 27 ) +// RemoteNetMask = "255.255.255.224"; +// else if ( RemoteNetMaskNum == 28 ) +// RemoteNetMask = "255.255.255.240"; +// else if ( RemoteNetMaskNum == 29 ) +// RemoteNetMask = "255.255.255.248"; +// else if ( RemoteNetMaskNum == 30 ) +// RemoteNetMask = "255.255.255.252"; +// else if ( RemoteNetMaskNum == 31 ) +// RemoteNetMask = "255.255.255.254"; +// else if ( RemoteNetMaskNum == 32 ) +// RemoteNetMask = "255.255.255.255"; +// +// openvpn_stream << "" << "\n"; +// openvpn_stream << "# route to remote network" << "\n"; +// openvpn_stream << "route " << RemoteNetAddr << " " << RemoteNetMask << "\n"; + } + //openvpn_stream << "" << "\n"; + //openvpn_stream << "# permissions" << "\n"; + // openvpn_stream << "user nobody" << "\n"; + // openvpn_stream << "group nogroup" << "\n"; + + openvpn_stream << "" << "\n"; + openvpn_stream << "# port" << "\n"; + if ( GlobalConfig->currentProfile->getUseUserdefinedPort() ) + openvpn_stream << "port " << GlobalConfig->currentProfile->getUserdefinedPort() << "\n\n"; + else + openvpn_stream << "port 1194" << "\n"; + + if ( GlobalConfig->currentProfile->getUseMtu() ) + { + openvpn_stream << "# tunnel mtu size" << "\n"; + openvpn_stream << "tun-mtu " << GlobalConfig->currentProfile->getMtu(); + } + + if ( GlobalConfig->currentProfile->getUseRenegSec() ) + { + openvpn_stream << "# reneg-sec size" << "\n"; + openvpn_stream << "reneg-sec " << GlobalConfig->currentProfile->getRenegSec() << "\n"; + } + + if ( GlobalConfig->currentProfile->getUseTunnelPing() ) + { + openvpn_stream << "# ping through tunnel" << "\n"; + openvpn_stream << "ping " << GlobalConfig->currentProfile->getTunnelPing() << "\n"; + } + + if ( GlobalConfig->currentProfile->getUseTunnelPingRestart() ) + { + openvpn_stream << "# restart after tunnel ping failed" << "\n"; + openvpn_stream << "ping-restart " << GlobalConfig->currentProfile->getTunnelPingRestart(); + } + + + if ( GlobalConfig->currentProfile->getUseFragment() ) + { + openvpn_stream << "\n"; + openvpn_stream << "# userdefined packet size for fragmentation" << "\n"; + openvpn_stream << "fragment " << GlobalConfig->currentProfile->getFragment() << "\n\n"; + } + + openvpn_stream << "" << "\n"; + openvpn_stream << "# don't re-read key files across SIGUSR1 or --ping-restart" << "\n"; + openvpn_stream << "persist-key" << "\n\n"; + + openvpn_stream << "" << "\n"; + openvpn_stream << "# don't close and reopen TUN/TAP device across SIGUSR1 or --ping-restart restarts" << "\n"; + openvpn_stream << "persist-tun" << "\n\n"; + + if ( GlobalConfig->currentProfile->getUseNsCertType() ) + { + openvpn_stream << "" << "\n"; + if ( GlobalConfig->currentProfile->getNsCertType() == "client" ) + { + openvpn_stream << "# Require that peer certificate was signed with an explicit nsCertType designation of \"client\"" << "\n"; + openvpn_stream << "ns-cert-type client" << "\n\n"; + } + else + { + openvpn_stream << "# Require that peer certificate was signed with an explicit nsCertType designation of \"server\"" << "\n"; + openvpn_stream << "ns-cert-type server" << "\n\n"; + } + } + + openvpn_stream << "# disable ping restart\n"; + openvpn_stream << "ping-restart 0\n"; + openvpn_stream << "\n"; + + + + // openvpn_stream << "# keep the connection alive" << "\n"; + + // // TODO make it dynamiclly + // openvpn_stream << "keepalive 10 60" << "\n\n"; + + // openvpn_stream << "# keepalive\n"; + // // openvpn_stream << "keepalive 10000\n"; + + if ( GlobalConfig->currentProfile->getUseUserdefiniedCipher() ) + { + openvpn_stream << "# Use a userdefined cipher\n"; + openvpn_stream << "cipher " << GlobalConfig->currentProfile->getUserdefiniedCipher() << "\n\n"; + } + + if ( GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + { + openvpn_stream << "# Automatically execute routing commands to cause all outgoing IP traffic to be redirected over the VPN\n"; + openvpn_stream << "redirect-gateway\n\n"; + } + + if ( GlobalConfig->currentProfile->getUseTlsAuth() && !GlobalConfig->currentProfile->getTlsAuthFile().isEmpty() ) + { + openvpn_stream << "# Add an additional layer of HMAC authentication on top of the TLS control channel to protect against DoS attacks\n"; + QString direction=""; + if ( GlobalConfig->currentProfile->getAuthenticationDirection() != "none" ) + direction= GlobalConfig->currentProfile->getAuthenticationDirection(); + openvpn_stream << "tls-auth " << GlobalConfig->currentProfile->getTlsAuthFile() << " " << direction << "\n\n"; + + if ( GlobalConfig->currentProfile->getUseTlsRemoteHost() ) + { + openvpn_stream << "# Accept connections only from a host with X509 name or common name equal to host\n"; + openvpn_stream << "tls-remote " << GlobalConfig->currentProfile->getTlsRemoteHost() << "\n\n"; + } + +// if ( GlobalConfig->currentProfile->getUseTlsRemoteHost() && GlobalConfig->currentProfile->getUseTlsAuth() ) + // openvpn_stream << "tls-client" << "\n\n"; + // openvpn_stream << "pull" << "\n\n"; + + + } + + if ( GlobalConfig->currentProfile->getUseHttpProxy() ) + { + openvpn_stream << "# Use a HTTP proxy\n"; + QString HttpProxyAuthType = ""; + + if ( GlobalConfig->currentProfile->getUseHttpProxyAuth() ) + HttpProxyAuthType = GlobalConfig->currentProfile->getHttpProxyAuthType(); + else + HttpProxyAuthType = "none"; + + openvpn_stream << "http-proxy " << GlobalConfig->currentProfile->getHttpProxy() << " " << GlobalConfig->currentProfile->getHttpProxyPort() << " " << "auto" << " " << HttpProxyAuthType << "\n"; + + openvpn_stream << "http-proxy-timeout " << GlobalConfig->currentProfile->getHttpProxyTimeout() << "\n\n"; + } + + openvpn_stream << "up " << tmpPath << "openvpn." << GlobalConfig->currentProfile->getName() << ".up" << "\n"; + openvpn_stream << "down " << tmpPath + "openvpn." << GlobalConfig->currentProfile->getName() << ".down" << "\n"; +// openvpn_stream << "up-restart" << "\n"; + openvpn_stream << "\n"; + + openvpn_stream << "# Use management interface\n"; + openvpn_stream << "management 127.0.0.1 " << GlobalConfig->OpenvpnManagementPort << "\n"; + openvpn_stream << "management-query-passwords" << "\n"; + openvpn_stream << "\n"; + if ( GlobalConfig->currentProfile->getUseSmartcard() || GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) + { + + // GlobalConfig->appendLogEntry( "use auth with pass: ", GlobalConfig->debug ); + // openvpn_stream << "management-hold\n"; +// openvpn_stream << "management-query-passwords\n"; + + openvpn_stream << "# What happen if auth fails\n"; + // TODO made option for other types + openvpn_stream << "auth-retry none\n\n"; + + if ( GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) + { + openvpn_stream << "# we want to authenticate with username and password\n"; + openvpn_stream << "auth-user-pass" << "\n"; + // openvpn_stream << "auth-user-pass " << OpenvpnSecrectPath << "\n\n"; + + //if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::psk ) + openvpn_stream << "pull" << "\n\n"; + } + + } + if ( GlobalConfig->currentProfile->getUseAuthenticationAlgorithm() ) + openvpn_stream << "auth " << GlobalConfig->currentProfile->getAuthenticationAlgorithm() << "\n"; + + if ( GlobalConfig->currentProfile->getAllowIpAddressChangeOfPeer() ) + openvpn_stream << "float" << "\n"; + openvpn_file.close(); + } + + + tmpPath = locateLocal ( "data", "kvpnc/" ); + + // write openvpn..up + QFile upfile ( tmpPath + "openvpn." + GlobalConfig->currentProfile->getName() + ".up" ); + QTextStream upstream ( &upfile ); + if ( upfile.open ( IO_WriteOnly ) ) + { + upstream << "#!"<< GlobalConfig->InterpreterShell << "\n"; + upstream << "# generated by kvpnc. Do not edit it." << "\n"; + upstream << "# profile: " + GlobalConfig->currentProfile->getName() << "\n\n"; + /* uses parts of http://www.smop.co.uk/node/69 */ + // upstream << "if [ -f /sbin/resolvconf ]; then\n"; + // if [ -x /sbin/resolvconf ] ; then + // ( + // if [ "$CISCO_DEF_DOMAIN" ] ; then + // echo domain "$CISCO_DEF_DOMAIN" + // echo search "$CISCO_DEF_DOMAIN" + // fi + // for ip in "$INTERNAL_IP4_DNS" ; do + // echo nameserver $ip + // done + // ) | /sbin/resolvconf -a $TUNDEV + // return + // fi + // upstream << "else\n"; + upstream << "cat /etc/resolv.conf > "<< tmpPath + "resolv.conf." + GlobalConfig->currentProfile->getName() << "\n"; + + /* update dns? */ + if ( GlobalConfig->currentProfile->getUseDnsUpdate() ) + { + upstream << "echo \"# generated by kvpnc. Do not edit it.\" > /etc/resolv.conf" << "\n"; + upstream << "echo \"# profile: " + GlobalConfig->currentProfile->getName() << "\" >> /etc/resolv.conf" << "\n"; + + upstream << "# init variables" << "\n"; + upstream << "" << "\n"; + upstream << "i=1" << "\n"; + upstream << "j=1" << "\n"; + upstream << "unset fopt" << "\n"; + upstream << "unset dns" << "\n"; + upstream << "unset opt" << "\n"; + upstream << "" << "\n"; + upstream << "dns_found=0" << "\n"; + upstream << "domain_found=0" << "\n"; + upstream << "" << "\n"; + upstream << "# Convert ENVs to an array" << "\n"; + upstream << "" << "\n"; + // upstream << "export > /tmp/a.txt" << "\n"; + // upstream << "echo \"-------\" >> /tmp/a.txt" << "\n"; + // upstream << "set >> /tmp/a.txt" << "\n"; + // upstream << "echo $foreign_option_0 > /tmp/a.txt" << "\n"; + // upstream << "echo $foreign_option_1 >> /tmp/a.txt" << "\n"; + // upstream << "echo $foreign_option_2 >> /tmp/a.txt" << "\n"; + // upstream << "echo $foreign_option_3 >> /tmp/a.txt" << "\n"; + + upstream << "while fopt=\"foreign_option_$i\"; [ -n \"${!fopt}\" ]; do" << "\n"; + upstream << "{" << "\n"; + upstream << " opt[i-1]=${!fopt}" << "\n"; + upstream << " case ${opt[i-1]} in" << "\n"; + upstream << " *DOMAIN* ) domain=`echo ${opt[i-1]} | \\" << "\n"; + upstream << " sed -e 's/dhcp-option DOMAIN //g'` ;;" << "\n"; + upstream << " *DNS* ) dns[j-1]=`echo ${opt[i-1]} | \\" << "\n"; + upstream << " sed -e 's/dhcp-option DNS //g'`" << "\n"; + upstream << " let j++ ;;" << "\n"; + upstream << " esac" << "\n"; + upstream << " let i++" << "\n"; + upstream << "}" << "\n"; + upstream << "done" << "\n"; + upstream << "" << "\n"; + + upstream << "# Now, do the work" << "\n"; + upstream << "" << "\n"; + upstream << "dns_found=0" << "\n"; + upstream << "if [ -n \"${dns[*]}\" ]; then" << "\n"; + upstream << "if [ -x /sbin/resolvconf ] ; then\n"; + upstream << " echo > "+tmpPath + "/openvpn.resolvconf.tmp." + GlobalConfig->currentProfile->getName() << "\n"; + upstream << " echo \"# nameservers\" >> "+tmpPath + "/openvpn.resolvconf.tmp." + GlobalConfig->currentProfile->getName() << "\n"; + upstream << " nameserver_found=0" << "\n"; + upstream << " for i in \"${dns[@]}\"; do" << "\n"; + upstream << " echo \"nameserver ${i}\" >> "+tmpPath + "/openvpn.resolvconf.tmp." + GlobalConfig->currentProfile->getName() << "\n"; + upstream << " nameserver_found=1" << "\n"; + upstream << " dns_found=1" << "\n"; + upstream << " done" << "\n"; + upstream << " if [ \"$nameserver_found\" = \"0\" ]; then" << "\n"; + upstream << " echo \"# old nameserver\" >> "+tmpPath + "/openvpn.resolvconf.tmp." + GlobalConfig->currentProfile->getName() << "\n"; + upstream << " cat "+tmpPath + "/resolv.conf.before.kvpnc_" + GlobalConfig->currentProfile->getName() +" | grep nameserver >> "+tmpPath + "/openvpn.resolvconf.tmp." + GlobalConfig->currentProfile->getName() << "\n"; + upstream << " fi" << "\n"; + upstream << "else" << "\n"; + upstream << " nameserver_found=0" << "\n"; + upstream << " for i in \"${dns[@]}\"; do" << "\n"; + upstream << " nameserver_found=1" << "\n"; + upstream << " sed -i -e \"1,1 i nameserver ${i}\" /etc/resolv.conf || die" << "\n"; + upstream << " done" << "\n"; + upstream << " if [ \"$nameserver_found\" = \"0\" ]; then" << "\n"; + upstream << " echo \"# old nameserver\" >> "+tmpPath + "/openvpn.resolvconf.tmp." + GlobalConfig->currentProfile->getName() << "\n"; + upstream << " cat "+tmpPath + "/resolv.conf.before.kvpnc_" + GlobalConfig->currentProfile->getName() +" | grep nameserver >> "+tmpPath + "/openvpn.resolvconf.tmp." + GlobalConfig->currentProfile->getName() << "\n"; + upstream << " fi" << "\n"; + upstream << "fi" << "\n"; + upstream << "fi" << "\n"; + upstream << "" << "\n"; + upstream << " echo \"# domains\" >> "+tmpPath + "/openvpn.resolvconf.tmp." + GlobalConfig->currentProfile->getName() << "\n"; + upstream << "if [ -n \"${domain}\" ]; then" << "\n"; + upstream << "if [ -x /sbin/resolvconf ] ; then\n"; + upstream << " echo domain \"${domain}\n\" >> "+tmpPath + "/openvpn.resolvconf.tmp." + GlobalConfig->currentProfile->getName() << "\n"; + upstream << "else" << "\n"; + upstream << " sed -i -e \"$j,1 i search ${domain}\" /etc/resolv.conf || die" << "\n"; + upstream << "fi" << "\n"; + upstream << "domain_found=1" << "\n"; + upstream << "fi" << "\n"; + upstream << "if [ \"$dns_found\" = \"0\" ]; then" << "\n"; + upstream << "if [ -x /sbin/resolvconf ] ; then\n"; + upstream << " echo \"# old nameserver\" >> "+tmpPath + "/openvpn.resolvconf.tmp." + GlobalConfig->currentProfile->getName() << "\n"; + upstream << " cat "+tmpPath + "/resolv.conf.before.kvpnc_" + GlobalConfig->currentProfile->getName() +" | grep nameserver >> "+tmpPath + "/openvpn.resolvconf.tmp." + GlobalConfig->currentProfile->getName() << "\n"; + upstream << "else" << "\n"; + upstream << " echo \"# old nameserver\" >> "+tmpPath + "/openvpn.resolvconf.tmp." + GlobalConfig->currentProfile->getName() << "\n"; + upstream << " cat "+tmpPath + "/resolv.conf.before.kvpnc_" + GlobalConfig->currentProfile->getName() +" | grep nameserver >> /etc/resolv.conf" <<"\n"; + upstream << "fi" << "\n"; + upstream << "fi" << "\n"; + upstream << "if [ \"$domain_found\" = \"0\" ]; then" << "\n"; + upstream << "if [ -x /sbin/resolvconf ] ; then\n"; + upstream << " echo > /dev/null\n"; + upstream << " echo \"# old domain\" >> "+tmpPath + "/openvpn.resolvconf.tmp." + GlobalConfig->currentProfile->getName() << "\n"; + upstream << " cat "+tmpPath + "/resolv.conf.before.kvpnc_" + GlobalConfig->currentProfile->getName() +" | grep domain >> "+tmpPath + "/openvpn.resolvconf.tmp." + GlobalConfig->currentProfile->getName() << "\n"; + upstream << "else" << "\n"; + upstream << " echo \"# old domain\" >> "+tmpPath + "/openvpn.resolvconf.tmp." + GlobalConfig->currentProfile->getName() << "\n"; + upstream << " cat "+tmpPath + "/resolv.conf.before.kvpnc_" + GlobalConfig->currentProfile->getName() +" | grep domain >> /etc/resolv.conf" <<"\n"; + upstream << "fi" << "\n"; + upstream << "fi" << "\n"; + + upstream << "if [ -x /sbin/resolvconf ] ; then\n"; + upstream << " cat "+tmpPath + "/openvpn.resolvconf.tmp." + GlobalConfig->currentProfile->getName() << " | /sbin/resolvconf -a $dev\n"; + + /* crissi: -u seems not nessesary */ + //upstream << " cat "+tmpPath + "/openvpn.resolvconf.tmp." + GlobalConfig->currentProfile->getName() << " | /sbin/resolvconf -u\n"; + // upstream << " cat "+tmpPath + "/openvpn.resolvconf.tmp." + GlobalConfig->currentProfile->getName() << " > /tmp/resolv "<< "\n"; + + // upstream << "echo \"dev: ${dev}\" > /tmp/resolvup.txt" << "\n"; + // upstream << "cat "+tmpPath + "/openvpn.resolvconf.tmp >> "+tmpPath + "+resolvconf." + GlobalConfig->currentProfile->getName()+ "\n"; + if (!GlobalConfig->holdGeneratedScripts) + upstream << " rm -f "+tmpPath + "/openvpn.resolvconf.tmp." + GlobalConfig->currentProfile->getName() <<"\n"; + upstream << "fi" << "\n"; + + // upstream << "if [ -f " << tmpPath + "resolv.conf." + GlobalConfig->currentProfile->getName() << " ]; then" << "\n"; + // upstream << " cat " << tmpPath + "resolv.conf." + GlobalConfig->currentProfile->getName() << " | grep nameserver >> /etc/resolv.conf" << "\n"; + // upstream << " cat " << tmpPath + "resolv.conf." + GlobalConfig->currentProfile->getName() << " | grep domain >> /etc/resolv.conf" << "\n"; + // upstream << "fi" << "\n"; + upstream << "" << "\n"; + +// upstream << "chmod u-w /etc/resolv.conf\n"; + } + else + { + /* dont update dns */ + setenv ( "DNS_UPDATE", "NO",1 ); + } + upstream << "exit 0\n"; + } + upfile.close(); + + Utils ( GlobalConfig, this ).doChmod ( tmpPath + "openvpn." + GlobalConfig->currentProfile->getName() + ".up", "a+x" ); + + // write openvpn..down + QFile downfile ( tmpPath + "openvpn." + GlobalConfig->currentProfile->getName() + ".down" ); + QTextStream downstream ( &downfile ); + if ( downfile.open ( IO_WriteOnly ) ) + { + downstream << "#!"<< GlobalConfig->InterpreterShell << "\n"; + downstream << "# generated by kvpnc. Do not edit it." << "\n"; + downstream << "# profile: " + GlobalConfig->currentProfile->getName() << "\n\n"; + + /* update dns? */ + if ( GlobalConfig->currentProfile->getUseDnsUpdate() ) + { +// downstream << "chmod u+w /etc/resolv.conf\n"; + downstream << "if [ -x /sbin/resolvconf ] ; then\n"; + downstream << " dev=$1\n"; + downstream << " if [ -z $dev ] ; then\n"; + if ( GlobalConfig->currentProfile->getTunnelDeviceType() == "tun" ) + downstream << " dev=\"tun0\"\n"; + else + downstream << " dev=\"tap0\"\n"; + downstream << " fi\n"; + downstream << " /sbin/resolvconf -d $dev\n"; + downstream << "else" << "\n"; + downstream << " cat " << tmpPath + "resolv.conf." + GlobalConfig->currentProfile->getName() << " > /etc/resolv.conf\n"; + downstream << "fi" << "\n"; + } + else + { + /* dont update dns */ + } + + QString OldDefaultroute = tmpPath + "default-route." + GlobalConfig->currentProfile->getName(); // default-route. + if ( ! pppdHasReplacedefaultrouteSupport && GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + { + downstream << GlobalConfig->pathToIp << " route add $(cat " << OldDefaultroute << ")" << "\n"; + } + if ( ! pppdHasReplacedefaultrouteSupport && GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + { + downstream << GlobalConfig->pathToIp << " route add $(cat " << OldDefaultroute << ")" << "\n"; + } + + + downstream << "exit 0"; + } + downfile.close(); + + Utils ( GlobalConfig, this ).doChmod ( tmpPath + "openvpn." + GlobalConfig->currentProfile->getName() + ".down", "a+x" ); + + OldDefaultroute = tmpPath + "default-route." + GlobalConfig->currentProfile->getName(); // default-route. + + QFile DefaultRouteBackupFile ( OldDefaultroute + ".sh" ); + QTextStream DefaultRouteBackupFileStream ( &DefaultRouteBackupFile ); + if ( DefaultRouteBackupFile.open ( IO_WriteOnly ) ) + { + DefaultRouteBackupFileStream << "# generated by kvpnc. Do not edit it." << "\n"; + DefaultRouteBackupFileStream << "\n"; + DefaultRouteBackupFileStream << GlobalConfig->pathToIp + " route show | grep default > " + OldDefaultroute + "\n"; + DefaultRouteBackupFile.close(); + QProcess backupDefaultRouteProcess ( this ); + backupDefaultRouteProcess.addArgument ( GlobalConfig->InterpreterShell ); + backupDefaultRouteProcess.addArgument ( OldDefaultroute + ".sh" ); + if ( !backupDefaultRouteProcess.start() ) + { + // if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Connect canceled because default route backup process could not be started." ), GlobalConfig->error ); + return ; + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Default route backup process started." ), GlobalConfig->debug ); + + while ( backupDefaultRouteProcess.isRunning() ) + { + if ( GlobalConfig->KvpncDebugLevel > 8 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" still running, waiting" ).arg ( i18n ( "Default route backup process" ) ) , GlobalConfig->debug ); + if ( GlobalConfig->appPointer->hasPendingEvents () ) + GlobalConfig->appPointer->processEvents(); + usleep ( 500 ); + } + + } + } + else + { + // if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Connect canceled because default route could not be backuped." ), GlobalConfig->error ); + return ; + } + + Utils ( GlobalConfig, this ).doChmod ( tmpPath + "openvpn." + GlobalConfig->currentProfile->getName() + ".down", "a+x" ); + if (OpenvpnProcess != 0L) + { + delete OpenvpnProcess; + OpenvpnProcess = 0L; + } + OpenvpnProcess = new QProcess ( this ); + OpenvpnProcess->setCommunication ( QProcess::Stdin|QProcess::Stdout|QProcess::Stderr|QProcess::DupStderr ); + OpenvpnProcess->addArgument ( GlobalConfig->pathToOpenvpn ); + + OpenvpnProcess->addArgument ( "--writepid" ); + OpenvpnProcess->addArgument ( tmpPath + "openvpn." + GlobalConfig->currentProfile->getName() + ".pid" ); + OpenvpnProcess->addArgument ( "--config" ); + OpenvpnProcess->addArgument ( tmpPath + "openvpn." + GlobalConfig->currentProfile->getName() + ".conf" ); // default + + connect ( OpenvpnProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readOutput_openvpn() ) ); +// connect( OpenvpnProcess, SIGNAL( readyReadStderr() ), this, SLOT( readOutput_openvpn() ) ); + connect ( OpenvpnProcess, SIGNAL ( processExited() ), this, SLOT ( openvpn_exited() ) ); + + + GlobalConfig->appendLogEntry ( i18n ( "Trying to connect to server \"%1\" with ...\n" ).arg ( GlobalConfig->currentProfile->getGateway() ) ,GlobalConfig->info ); + slotStatusMsg ( i18n ( "Connecting..." ), ID_CONNECTION_MSG ); + + setenv ( "DNS_UPDATE", ( GlobalConfig->currentProfile->getUseDnsUpdate() ? "Yes" : "NO" ), 1 ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Setting DNS_UPDATE \"%1\"." ).arg ( getenv ( "DNS_UPDATE" ) ), GlobalConfig->debug ); + + if ( !OpenvpnProcess->start ( env ) ) + { + KMessageBox::sorry ( this, i18n ( "\"%1\" start failed!" ).arg ( "openvpn" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "openvpn" ) , GlobalConfig->error ); + disconnectClicked(); + } + else + { + ConnectingProcess = VpnAccountData::openvpn; + GlobalConfig->status = GlobalConfig->connecting; + mw->buttonDisconnect->setEnabled ( true ); + this->DisconnectAction->setEnabled ( true ); + mw->buttonConnect->setEnabled ( false ); + this->ConnectAction->setEnabled ( false ); + + + bool OpenvpnVersionOk = false; + int major = Utils ( GlobalConfig, this ).getToolInfo ( "openvpn" ) ->Version.section ( '.', 0, 0 ).toInt(); + int minor = Utils ( GlobalConfig, this ).getToolInfo ( "openvpn" ) ->Version.section ( '.', 1, 1 ).toInt(); + int subminor = Utils ( GlobalConfig, this ).getToolInfo ( "openvpn" ) ->Version.section ( '.', 2, 2 ).toInt(); + + if ( major >= 2 /* && minor >= 1 */ ) + OpenvpnVersionOk = true; + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Openvpn Version: %1.%2.%3" ).arg ( QString().setNum ( major ) ).arg ( QString().setNum ( minor ) ).arg ( QString().setNum ( subminor ) ), GlobalConfig->debug ); + + + // if (OpenvpnVersionOk && ( GlobalConfig->currentProfile->getUseSmartcard() || GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) ) + // { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Starting Openvpn management handler..." ), GlobalConfig->debug ); + managementhandler = new OpenvpnManagementHandler ( this, GlobalConfig ); + connect ( managementhandler, SIGNAL ( terminate_openvpn() ), this, SLOT ( disconnectClicked() ) ); + if ( managementhandler->doConnect()) + { + + // int maxfailManagementHandlerConnectCheckCount=10; // 10 sec should be enough for connecting to 127.0.0.1 + // int failManagementHandlerConnectCheckCount=0; + // while (!managementhandler->isConnectedToManagementPort() && failManagementHandlerConnectCheckCount < maxfailManagementHandlerConnectCheckCount) + // { + // sleep(1); + // GlobalConfig->appPointer->processEvents(); + // failManagementHandlerConnectCheckCount++; + // if (managementhandler->isConnectedToManagementPort()) + // { + // if (! GlobalConfig->KvpncDebugLevel > 1 ) + // GlobalConfig->appendLogEntry( i18n( "Connect to %1 management handler was sucessful" ).arg( "openvpn" ) , GlobalConfig->debug ); + // break; + // } + // if (! GlobalConfig->KvpncDebugLevel > 1 ) + // GlobalConfig->appendLogEntry( i18n( "Trying to connect to %1 management handler..." ).arg( "openvpn" ) , GlobalConfig->debug ); + // } + // // managementhandler->sendToServer("help"); + // // } + // if (failManagementHandlerConnectCheckCount >= maxfailManagementHandlerConnectCheckCount) + // { + // // KMessageBox::sorry( this, i18n( "Could not connect to %1 management handler!" ).arg( "openvpn" ) ); + // GlobalConfig->appendLogEntry( i18n( "Could not connect to %1 management handler!" ).arg( "openvpn" ) , GlobalConfig->error ); + // if (OpenvpnProcess != 0) + // OpenvpnProcess->kill(); + // setGuiStatus(disconnected); + // return; + // } + + // sleep(5); + + if ( ! GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( "openvpn" ), GlobalConfig->debug ); + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed." ).arg ( "openvpn managementhandler" ), GlobalConfig->error ); + disconnectClicked(); + } + + } + } // openvpn + else + { + setGuiStatus ( disconnected ); + return ; + } + } + } + + /* ============ vtun ================ */ + else if ( GlobalConfig->currentProfile != 0 && GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::vtun ) + { + //setGuiStatus(connecting); + tmpPath = locateLocal ( "data", "kvpnc/" ); + + // looking for vtund + if ( Utils ( GlobalConfig ).getToolInfo ( "vtund" )->found == false ) + { + KMessageBox::error ( this, i18n ( "Unable to find \"%1\" at \"%2\"!" ).arg ( "vtund" ).arg ( GlobalConfig->pathToVtund ) ); + GlobalConfig->appendLogEntry ( i18n ( "Unable to find \"%1\" at \"%2\"!" ).arg ( "vtund" ).arg ( GlobalConfig->pathToVtund ), GlobalConfig->error ); + ok = false; + setGuiStatus ( disconnected ); + return ; + } + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "vtund: %1" ) .arg ( GlobalConfig->pathToVtund ) , GlobalConfig->debug ); + + bool tunsupportfound = false; + QString procmisc = ""; + QFile f ( "/proc/misc" ); + if ( f.open ( IO_ReadOnly ) ) + { + QTextStream stream ( &f ); + QString line = ""; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' + if ( line.contains ( "tun", false ) ) + { + tunsupportfound = true; + break; + } + } + } + f.close(); + if ( tunsupportfound ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Support for TUN/TAP found (compiled into kernel or kernel module already loaded)." ), GlobalConfig->debug ); + + QFile tundevfile ( "/dev/net/tun" ); + if ( !tundevfile.exists() ) + { + if ( !Utils ( GlobalConfig, parent ).createTunDev() ) + { + KMessageBox::error ( this, i18n ( "Creating of \"%1\" has been failed!" ).arg ( "/dev/net/tun" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Tunnel device is missing, creating has been failed: stop." ), GlobalConfig->error ); + disconnectClicked(); + setGuiStatus ( disconnected ); + GlobalConfig->status = GlobalConfig->disconnected; + return ; + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Tunnel device is missing, creating has been succeded." ), GlobalConfig->debug ); + } + } + else + { + // load the module 'tun' + if ( !Utils ( GlobalConfig, parent ).loadKernelModule ( "tun", parent ) ) + { + KMessageBox::information ( this, i18n ( "Loading of module \"%1\" failed!" ).arg ( "tun" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Tunnel device is missing, loading module \"%1\" has failed: stop." ).arg ( "tun" ), GlobalConfig->error ); + disconnectClicked(); + setGuiStatus ( disconnected ); + GlobalConfig->status = GlobalConfig->disconnected; + return ; + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Loading of module \"%1\" was successful." ).arg ( "tun" ), GlobalConfig->debug ); + } + } + } + + // GlobalConfig->TmpGatewayIP = Utils( GlobalConfig, parent ).resolveName(GlobalConfig->currentProfile->getGateway()); + // if (GlobalConfig->TmpGatewayIP=="0.0.0.0" || GlobalConfig->TmpGatewayIP.isEmpty()) + // { + // KMessageBox::error( this, i18n( "Host \"%1\" could not be resolved!" ).arg(GlobalConfig->currentProfile->getGateway()) ); + // GlobalConfig->appendLogEntry(i18n( "Host \"%1\" could not be resolved!" ).arg(GlobalConfig->currentProfile->getGateway()),GlobalConfig->error); + // ok =false; + // } + // else + // { + // GlobalConfig->appendLogEntry( i18n( "Gateway hostname (%1) resolved to \"%2\"." ).arg(GlobalConfig->currentProfile->getGateway()).arg(GlobalConfig->TmpGatewayIP), GlobalConfig->info ); + // } + + bool askUsernamePass = false; + bool requestUsername = false; + bool requestGrouppassword = false; + + if ( !GlobalConfig->haveUserData ) + { + + // if ( GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) + { + if ( GlobalConfig->currentProfile->getUserPassword().isEmpty() ) + askUsernamePass = true; + else + GlobalConfig->TmpPassword = GlobalConfig->currentProfile->getUserPassword(); + + if ( AuthRetry ) + { + askUsernamePass = true; + requestUsername = false; + } + } + } + if ( GlobalConfig->currentProfile->getAskUserPasswordOnEachConnect() ) + { + if ( GlobalConfig->KvpncDebugLevel > 4 ) + GlobalConfig->appendLogEntry ( i18n ( "User password on each connect forced." ), GlobalConfig->debug ); + + askUsernamePass = true; + requestUsername = true; + } + + + if ( askUsernamePass || requestUsername ) + { + EnterUsernamePasswordDialog dlg ( this, i18n ( "Enter Account Data" ), requestGrouppassword, requestUsername ); + + + if ( GlobalConfig->currentProfile->getSaveUserPassword() ) + dlg.main->PasswordEdit->setText ( GlobalConfig->currentProfile->getUserPassword() ); + + dlg.main->UsernameEdit->setText ( GlobalConfig->currentProfile->getUserName() ); + if ( !dlg.main->UsernameEdit->text().isEmpty() ) //go straight to pw if username present + dlg.main->PasswordEdit->setFocus(); + + if ( dlg.exec() ) + { + bool needSave = false; + GlobalConfig->TmpUsername = dlg.main->UsernameEdit->text(); + GlobalConfig->TmpPassword = dlg.main->PasswordEdit->text(); + + + if ( GlobalConfig->TmpPassword.isEmpty() ) + { + GlobalConfig->appendLogEntry ( i18n ( "Password is empty" ), GlobalConfig->error ); + ok = false; + } + + if ( requestUsername && GlobalConfig->TmpUsername.isEmpty() ) + { + GlobalConfig->appendLogEntry ( i18n ( "Username is empty!" ), GlobalConfig->error ); + ok = false; + } + + if ( dlg.main->SaveUsernameCheckBox->isChecked() ) + { + GlobalConfig->currentProfile->setDontSaveUsername ( false ); + GlobalConfig->currentProfile->setUserName ( dlg.main->UsernameEdit->text() ); + needSave = true; + } + else + { + GlobalConfig->TmpUsername = dlg.main->UsernameEdit->text(); + GlobalConfig->currentProfile->setDontSaveUsername ( true ); + needSave = true; + } + + + if ( dlg.main->SavePskCheckBox->isChecked() ) + { + GlobalConfig->currentProfile->setSavePsk ( true ); + GlobalConfig->currentProfile->setPreSharedKey ( GlobalConfig->TmpGroupPassword ); + needSave = true; + } + else + { + GlobalConfig->currentProfile->setSavePsk ( false ); + needSave=true; + } + + if ( dlg.main->SavePasswordCheckBox->isChecked() ) + { + GlobalConfig->currentProfile->setSaveUserPassword ( true ); + GlobalConfig->currentProfile->setUserPassword ( GlobalConfig->TmpPassword ); + needSave = true; + } + else + { + GlobalConfig->currentProfile->setSaveUserPassword ( false ); + needSave = true; + } + if (needSave) + GlobalConfig->saveOptions(true, GlobalConfig->currentProfile->getName()); + + } + else + { + ok = false; + AuthRetry = false; + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Connect canceled because password enter dialog aborted." ), GlobalConfig->debug ); + } + + } + else + { + if ( !GlobalConfig->currentProfile->getSaveUserPassword() && ! GlobalConfig->currentProfile->getUserPassword().isEmpty() ) + { + GlobalConfig->TmpPassword = GlobalConfig->currentProfile->getUserPassword() ; + } + + + if ( !GlobalConfig->currentProfile->getDontSaveUsername() && ! GlobalConfig->currentProfile->getUserName().isEmpty() ) //go straight to pw if username present + { + GlobalConfig->TmpUsername = GlobalConfig->currentProfile->getUserName(); + } + } + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Some passwords which are need got from password enter dialog." ), GlobalConfig->debug ); + + AuthRetry = false; + GlobalConfig->haveUserData=true; + + // here we go + if ( ok ) + { + if ( GlobalConfig->currentProfile->getExecuteCmdBeforeConnect() ) + executeCommandBeforeConnect(); + + // write vtun..conf + QFile vtun_file ( tmpPath + "vtun." + GlobalConfig->currentProfile->getName() + ".conf" ); + QTextStream vtun_stream ( &vtun_file ); + if ( vtun_file.open ( IO_WriteOnly ) ) + { + vtun_stream << "# generated by kvpnc. Do not edit it." << "\n"; + vtun_stream << "# profile: " + GlobalConfig->currentProfile->getName() << "\n\n"; + vtun_stream << "options {" << "\n"; + + if ( GlobalConfig->currentProfile->getUseLocalPort() ) + vtun_stream << " port " << GlobalConfig->currentProfile->getLocalPort() << ";" << "\n"; + else + vtun_stream << " port 5000;" << "\n"; + vtun_stream << "\n"; + vtun_stream << " # path to programs" << "\n"; + vtun_stream << " ifconfig " << GlobalConfig->pathToIfconfig << ";" << "\n"; + vtun_stream << " route " << GlobalConfig->pathToRoute << ";" << "\n"; + vtun_stream << " ppp " << GlobalConfig->pathToPppd << ";" << "\n"; + vtun_stream << "}" << "\n"; + vtun_stream << "" << "\n"; +// vtun_stream << "default {" << "\n"; +// vtun_stream << "}" << "\n"; + vtun_stream << "" << "\n"; + vtun_stream << GlobalConfig->currentProfile->getVtunProfile() << " {" << "\n"; + vtun_stream << "" << "\n"; + vtun_stream << " # Password" << "\n"; + vtun_stream << " passwd "<< GlobalConfig->TmpPassword << ";" << "\n"; + vtun_stream << "" << "\n"; +// vtun_stream << " # IP tunnel" << "\n"; +// vtun_stream << " type tun;" << "\n"; +// vtun_stream << "" << "\n"; + vtun_stream << " up {" << "\n"; + if ( GlobalConfig->currentProfile->getUseVirtualIP() ) + { + vtun_stream << " # use virtual ip addresses" << "\n"; + vtun_stream << " ifconfig \"%% " << GlobalConfig->currentProfile->getLocalVirtualIP() << " pointopoint " << GlobalConfig->currentProfile->getRemoteVirtualIP() << "\";" << "\n"; + } + else + { + vtun_stream << " # IP address will be assigned by the server" << "\n"; + vtun_stream << " ppp \"noauth noipdefault\";" << "\n"; + } + //TODO implement pipe + + vtun_stream << "# route \"add 192.168.10.200 gw 192.168.10.253\";" << "\n"; + vtun_stream << " };" << "\n"; + vtun_stream << "" << "\n"; + vtun_stream << " down {" << "\n"; + vtun_stream << "" << "\n"; + vtun_stream << " };" << "\n"; + + vtun_stream << "}" << "\n"; + + } + vtun_file.close(); + + VtundProcess = new QProcess ( this ); +// VtundProcess->setCommunication ( QProcess::Stdin|QProcess::Stdout|QProcess::Stderr|QProcess::DupStderr ); + VtundProcess->addArgument ( GlobalConfig->pathToVtund ); + VtundProcess->addArgument ( "-n" ); + VtundProcess->addArgument ( "-f" ); + VtundProcess->addArgument ( tmpPath + "vtun." + GlobalConfig->currentProfile->getName() + ".conf" ); // default + VtundProcess->addArgument ( GlobalConfig->currentProfile->getVtunProfile() ); + VtundProcess->addArgument ( GlobalConfig->currentProfile->getGateway() ); + + + connect ( VtundProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_vtun() ) ); + connect ( VtundProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_vtun() ) ); + connect ( VtundProcess, SIGNAL ( processExited() ), this, SLOT ( vtun_exited() ) ); + + + GlobalConfig->appendLogEntry ( i18n ( "Trying to connect to server \"%1\" with ...\n" ).arg ( GlobalConfig->currentProfile->getGateway() ) ,GlobalConfig->info ); + slotStatusMsg ( i18n ( "Connecting..." ), ID_CONNECTION_MSG ); + + + if ( !VtundProcess->start ( env ) ) + { + KMessageBox::sorry ( this, i18n ( "\"%1\" start failed!" ).arg ( "vtund" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "vtund" ) , GlobalConfig->error ); + disconnectClicked(); + } + else + { + ConnectingProcess = VpnAccountData::vtun; + GlobalConfig->status = GlobalConfig->connecting; + mw->buttonDisconnect->setEnabled ( true ); + this->DisconnectAction->setEnabled ( true ); + mw->buttonConnect->setEnabled ( false ); + this->ConnectAction->setEnabled ( false ); + + GlobalConfig->currentConnectRetry++; + + } + + } + else + { + setGuiStatus ( disconnected ); + return ; + } + } + /* ============ ssh ================ */ + else if ( GlobalConfig->currentProfile != 0 && GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ssh ) + { + //setGuiStatus(connecting); + tmpPath = locateLocal ( "data", "kvpnc/" ); + + // looking for ssh + if ( Utils ( GlobalConfig ).getToolInfo ( "ssh" )->found == false ) + { + KMessageBox::error ( this, i18n ( "Unable to find \"%1\" at \"%2\"!" ).arg ( "ssh" ).arg ( GlobalConfig->pathToSsh ) ); + GlobalConfig->appendLogEntry ( i18n ( "Unable to find \"%1\" at \"%2\"!" ).arg ( "ssh" ).arg ( GlobalConfig->pathToSsh ), GlobalConfig->error ); + ok = false; + setGuiStatus ( disconnected ); + return ; + } + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "ssh: %1" ) .arg ( GlobalConfig->pathToSsh ) , GlobalConfig->debug ); + + bool tunsupportfound = false; + QString procmisc = ""; + QFile f ( "/proc/misc" ); + if ( f.open ( IO_ReadOnly ) ) + { + QTextStream stream ( &f ); + QString line = ""; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' + if ( line.contains ( "tun", false ) ) + { + tunsupportfound = true; + break; + } + } + } + f.close(); + if ( tunsupportfound ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Support for TUN/TAP found (compiled into kernel or kernel module already loaded)." ), GlobalConfig->debug ); + + QFile tundevfile ( "/dev/net/tun" ); + if ( !tundevfile.exists() ) + { + if ( !Utils ( GlobalConfig, parent ).createTunDev() ) + { + KMessageBox::error ( this, i18n ( "Creating of \"%1\" has been failed!" ).arg ( "/dev/net/tun" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Tunnel device is missing, creating has been failed: stop." ), GlobalConfig->error ); + disconnectClicked(); + setGuiStatus ( disconnected ); + GlobalConfig->status = GlobalConfig->disconnected; + return ; + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Tunnel device is missing, creating has been succeded." ), GlobalConfig->debug ); + } + } + else + { + // load the module 'tun' + if ( !Utils ( GlobalConfig, parent ).loadKernelModule ( "tun", parent ) ) + { + KMessageBox::information ( this, i18n ( "Loading of module \"%1\" failed!" ).arg ( "tun" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Tunnel device is missing, loading module \"%1\" has failed: stop." ).arg ( "tun" ), GlobalConfig->error ); + disconnectClicked(); + setGuiStatus ( disconnected ); + GlobalConfig->status = GlobalConfig->disconnected; + return ; + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Loading of module \"%1\" was successful." ).arg ( "tun" ), GlobalConfig->debug ); + } + } + } + + GlobalConfig->TmpGatewayIP = Utils ( GlobalConfig, parent ).resolveName ( GlobalConfig->currentProfile->getGateway() ); + if ( GlobalConfig->TmpGatewayIP=="0.0.0.0" || GlobalConfig->TmpGatewayIP.isEmpty() ) + { + KMessageBox::error ( this, i18n ( "Host \"%1\" could not be resolved!" ).arg ( GlobalConfig->currentProfile->getGateway() ) ); + GlobalConfig->appendLogEntry ( i18n ( "Host \"%1\" could not be resolved!" ).arg ( GlobalConfig->currentProfile->getGateway() ),GlobalConfig->error ); + ok =false; + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "Gateway hostname (%1) resolved to \"%2\"." ).arg ( GlobalConfig->currentProfile->getGateway() ).arg ( GlobalConfig->TmpGatewayIP ), GlobalConfig->info ); + } + + bool askUsernamePass = false; + bool requestUsername = false; + bool requestGrouppassword = false; + + if ( !GlobalConfig->haveUserData ) + { + // if ( GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) + { + if ( GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) + { + if ( GlobalConfig->currentProfile->getUserPassword().isEmpty() ) + askUsernamePass = true; + else + GlobalConfig->TmpPassword = GlobalConfig->currentProfile->getUserPassword(); + } + if ( GlobalConfig->currentProfile->getUserName().isEmpty() ) + requestUsername = true; + else + GlobalConfig->TmpUsername = GlobalConfig->currentProfile->getUserName(); + + if ( AuthRetry ) + { + askUsernamePass = true; + requestUsername = false; + } + } + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 4 ) + GlobalConfig->appendLogEntry ( i18n ( "User data already collected." ), GlobalConfig->debug ); + } + + if ( GlobalConfig->currentProfile->getAskUserPasswordOnEachConnect() ) + { + if ( GlobalConfig->KvpncDebugLevel > 4 ) + GlobalConfig->appendLogEntry ( i18n ( "User password on each connect forced." ), GlobalConfig->debug ); + + askUsernamePass = true; + requestUsername = true; + } + + if ( askUsernamePass || requestUsername ) + { + EnterUsernamePasswordDialog dlg ( this, i18n ( "Enter Account Data" ), requestGrouppassword, requestUsername ); + + if ( GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) + { + if ( GlobalConfig->currentProfile->getSaveUserPassword() ) + dlg.main->PasswordEdit->setText ( GlobalConfig->currentProfile->getUserPassword() ); + } + else + { + dlg.main->PasswordEdit->hide(); + dlg.main->LabelPassword->hide(); + dlg.main->SavePasswordCheckBox->hide(); + } + dlg.main->UsernameEdit->setText ( GlobalConfig->currentProfile->getUserName() ); + + if ( GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) + { + if ( !dlg.main->UsernameEdit->text().isEmpty() ) //go straight to pw if username present + dlg.main->PasswordEdit->setFocus(); + } + if ( dlg.exec() ) + { + bool needSave = false; + GlobalConfig->TmpUsername = dlg.main->UsernameEdit->text(); + GlobalConfig->TmpPassword = dlg.main->PasswordEdit->text(); + + if ( GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) + { + if ( GlobalConfig->TmpPassword.isEmpty() ) + { + GlobalConfig->appendLogEntry ( i18n ( "Password is empty" ), GlobalConfig->error ); + ok = false; + } + } + if ( requestUsername && GlobalConfig->TmpUsername.isEmpty() ) + { + GlobalConfig->appendLogEntry ( i18n ( "Username is empty!" ), GlobalConfig->error ); + ok = false; + } + + if ( dlg.main->SaveUsernameCheckBox->isChecked() ) + { + GlobalConfig->currentProfile->setDontSaveUsername ( false ); + GlobalConfig->currentProfile->setUserName ( dlg.main->UsernameEdit->text() ); + needSave = true; + } + else + { + GlobalConfig->TmpUsername = dlg.main->UsernameEdit->text(); + GlobalConfig->currentProfile->setDontSaveUsername ( true ); + } + + + if ( dlg.main->SavePskCheckBox->isChecked() ) + { + GlobalConfig->currentProfile->setSavePsk ( true ); + GlobalConfig->currentProfile->setPreSharedKey ( GlobalConfig->TmpGroupPassword ); + needSave = true; + } + else + { + GlobalConfig->currentProfile->setSavePsk ( false ); + needSave = true; + } + + if ( dlg.main->SavePasswordCheckBox->isChecked() ) + { + GlobalConfig->currentProfile->setSaveUserPassword ( true ); + GlobalConfig->currentProfile->setUserPassword ( GlobalConfig->TmpPassword ); + needSave = true; + } + else + { + GlobalConfig->currentProfile->setSaveUserPassword ( false ); + needSave = true; + } + if (needSave) + GlobalConfig->saveOptions(true, GlobalConfig->currentProfile->getName()); + + } + else + { + ok = false; + AuthRetry = false; + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Connect canceled because password enter dialog aborted." ), GlobalConfig->debug ); + } + + } + else + { + if ( !GlobalConfig->currentProfile->getSaveUserPassword() && ! GlobalConfig->currentProfile->getUserPassword().isEmpty() ) + { + GlobalConfig->TmpPassword = GlobalConfig->currentProfile->getUserPassword() ; + } + + + if ( !GlobalConfig->currentProfile->getDontSaveUsername() && ! GlobalConfig->currentProfile->getUserName().isEmpty() ) //go straight to pw if username present + { + GlobalConfig->TmpUsername = GlobalConfig->currentProfile->getUserName(); + } + } + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Some passwords which are need got from password enter dialog." ), GlobalConfig->debug ); + + AuthRetry = false; + GlobalConfig->haveUserData=true; + + // here we go + if ( ok ) + { + if ( GlobalConfig->currentProfile->getExecuteCmdBeforeConnect() ) + executeCommandBeforeConnect(); + + SshProcess = new KProcess; + *SshProcess << GlobalConfig->pathToSsh ; + // SshProcess->setExecutable(GlobalConfig->pathToSsh); + /* + connect(m_process, SIGNAL(processExited(KProcess*)), + this, SLOT(slotProcessExited(KProcess*)));*/ + +// QString AskPassScript= tmpPath+"ssh."+GlobalConfig->currentProfile->getName()+".askpass.sh"; +// +// QFile askpassfile (AskPassScript ); +// QTextStream stream ( &askpassfile ); +// if ( askpassfile.open ( IO_WriteOnly ) ) +// { +// stream << "#!"<< GlobalConfig->InterpreterShell << "\n"; +// stream << "# generated by kvpnc. Do not edit it." << "\n"; +// stream << "# profile: " + GlobalConfig->currentProfile->getName() << "\n"; +// stream << "echo $1" << "\n"; +// stream << "echo " << GlobalConfig->TmpPassword << "\n"; +// stream << "" << "\n"; +// +// askpassfile.close(); +// } +// else +// { +// GlobalConfig->appendLogEntry ( i18n ( "\"%1\" write failed!" ).arg ( askpassfile.name() ), GlobalConfig->error ); +// setGuiStatus ( disconnected ); +// return; +// } +// +// Utils ( GlobalConfig, this ).doChmod (AskPassScript,"a+x" ); +// Utils ( GlobalConfig, this ).doChmod (AskPassScript,"go-rw" ); + + SshDevice = ""; + if ( GlobalConfig->currentProfile->getTunnelDeviceType() == "tun" ) + SshDevice = "tun0"; + else + SshDevice ="tap0"; + + // FIXME make it dynamiclly + if ( GlobalConfig->currentProfile->getUseSshConfigRemoteScript() && !GlobalConfig->currentProfile->getSshConfigRemoteScript().isEmpty() ) + { + *SshProcess << "-w0" ; + } + else + { + *SshProcess << "-w0:0" ; + } + + if ( GlobalConfig->SshDebugLevel > 0 ) + { + QString SshDebug="-"; + for ( int i=0;iSshDebugLevel;i++ ) + SshDebug+="v"; + *SshProcess << SshDebug; + } + + // using ssh key + if ( ! GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) + { + if ( GlobalConfig->currentProfile->getPreSharedKey().isEmpty() ) + { + KMessageBox::error ( this, i18n ( "No SSH key file specified!" ) ); + GlobalConfig->appendLogEntry ( i18n ( "No SSH key file specified!" ),GlobalConfig->error ); + disconnectClicked(); + return; + } + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Using keyfile: %1" ).arg ( GlobalConfig->currentProfile->getPreSharedKey() ), GlobalConfig->debug ); + *SshProcess << " -i" ; + *SshProcess << GlobalConfig->currentProfile->getPreSharedKey(); + } + + /* + *SshProcess << "-t" ; + *SshProcess << "-t" ;*/ + + *SshProcess << "-n" ; + + // login name + *SshProcess << "-l" ; + *SshProcess << GlobalConfig->TmpUsername ; + + + + if ( GlobalConfig->currentProfile->getTunnelDeviceType() == "tun" ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Using tunnel device type: %1" ).arg ( "TUN" ), GlobalConfig->debug ); + } + if ( GlobalConfig->currentProfile->getTunnelDeviceType() == "tap" ) + { + *SshProcess << "-o" << "Tunnel=ethernet"; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Using tunnel device type: %1" ).arg ( "TAP" ), GlobalConfig->debug ); + } + + + if ( GlobalConfig->currentProfile->getUseRemotePort() ) + { + *SshProcess << "-p" ; + *SshProcess << QString().setNum ( GlobalConfig->currentProfile->getRemotePort() ); + } + + *SshProcess << GlobalConfig->TmpGatewayIP ; + + + // FIXME add detection on server and make it dynamiclly + if ( GlobalConfig->currentProfile->getTunnelDeviceType() == "tun" ) + { + if ( !GlobalConfig->currentProfile->getUseSshConfigRemoteScript() ) + { + *SshProcess << "/sbin/ifconfig "+SshDevice+" " + GlobalConfig->currentProfile->getRemoteVirtualIP() + " pointopoint " + GlobalConfig->currentProfile->getLocalVirtualIP() + " up ; /bin/echo ssh_is_up" ; + } + else + { + if ( !GlobalConfig->currentProfile->getSshConfigRemoteScript().isEmpty() ) + { + *SshProcess << GlobalConfig->currentProfile->getSshConfigRemoteScript() + " tun "+GlobalConfig->currentProfile->getRemoteVirtualIP() +" "+GlobalConfig->currentProfile->getLocalVirtualIP() +" ; /bin/echo ssh_is_up" ; + + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Using %1 as %2." ).arg ( GlobalConfig->currentProfile->getSshConfigRemoteScript() ).arg ( i18n ( "ssh config remote script" ) ),GlobalConfig->debug ); + } + else + { + KMessageBox::error ( this, i18n ( "%1 is empty!" ).arg ( i18n ( "ssh config remote script" ) ) ); + GlobalConfig->appendLogEntry ( i18n ( "%1 is empty!" ).arg ( i18n ( "ssh config remote script" ) ),GlobalConfig->error ); + disconnectClicked(); + return; + } + } + } + + if ( GlobalConfig->currentProfile->getTunnelDeviceType() == "tap" ) + { + if ( !GlobalConfig->currentProfile->getUseSshConfigRemoteScript() ) + { + *SshProcess << "/sbin/ifconfig "+SshDevice+" " + GlobalConfig->currentProfile->getLocalVirtualIP() + " netmask "+GlobalConfig->currentProfile->getRemoteVirtualIP() +" up ; /bin/echo ssh_is_up" ; + } + else + { + if ( !GlobalConfig->currentProfile->getSshConfigRemoteScript().isEmpty() ) + { + *SshProcess << GlobalConfig->currentProfile->getSshConfigRemoteScript() + " tap ; /bin/echo ssh_is_up" ; + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Using %1 as %2." ).arg ( GlobalConfig->currentProfile->getSshConfigRemoteScript() ).arg ( i18n ( "ssh config remote script" ) ),GlobalConfig->debug ); + } + else + { + KMessageBox::error ( this, i18n ( "%1 is empty!" ).arg ( i18n ( "ssh config remote script" ) ) ); + GlobalConfig->appendLogEntry ( i18n ( "%1 is empty!" ).arg ( i18n ( "ssh config remote script" ) ),GlobalConfig->error ); + disconnectClicked(); + return; + } + } + } + + if ( GlobalConfig->KvpncDebugLevel > 3 ) + { + QString args = ""; + QValueList list = SshProcess->args(); + QValueList::Iterator it = list.begin(); + while ( it != list.end() ) + { + args += QString ( " " + *it ) ; + ++it; + } + GlobalConfig->appendLogEntry ( i18n ( "%1 arguments: %1" ).arg ( "ssh" ).arg ( args ), GlobalConfig->debug ); + } + + + connect ( SshProcess, SIGNAL ( receivedStdout ( KProcess *, char *, int ) ), this, SLOT ( readFromStdout_ssh ( KProcess *, char *, int ) ) ); + connect ( SshProcess, SIGNAL ( receivedStderr ( KProcess *, char *, int ) ), this, SLOT ( readFromStderr_ssh ( KProcess *, char *, int ) ) ); +// connect( SshProcess, SIGNAL( processExited() ), this, SLOT( sshExited() ) ); + + GlobalConfig->appendLogEntry ( i18n ( "Trying to connect to server \"%1\" with ...\n" ).arg ( GlobalConfig->currentProfile->getGateway() ) ,GlobalConfig->info ); + slotStatusMsg ( i18n ( "Connecting..." ), ID_CONNECTION_MSG ); + + SshProcess->setEnvironment ( "LC_ALL", "C" ); + SshProcess->setEnvironment ( "LANG","C" ); + SshProcess->setEnvironment ( "PATH","/bin:/usr/bin:/usr/sbin:/sbin" ); +// SshProcess->setEnvironment ( "SSH_ASKPASS",AskPassScript ); + + ToolInfo *KsshaskpassInfo = Utils ( GlobalConfig ).getToolInfo ( "ksshaskpass" ); + ToolInfo *GnomeaskpassInfo = Utils ( GlobalConfig ).getToolInfo ( "gnome-ssh-askpass" ); + + if ( KsshaskpassInfo->found ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "%1 will be used." ).arg ( "ksshaskpass" ),GlobalConfig->debug ); + SshProcess->setEnvironment ( "SSH_ASKPASS",GlobalConfig->pathToKsshAskpass ); + } + else if ( GnomeaskpassInfo->found ) + { + SshProcess->setEnvironment ( "SSH_ASKPASS",GlobalConfig->pathToGnomeSshAskpass ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "%1 will be used." ).arg ( "gnome-ssh-askpass" ),GlobalConfig->debug ); + } + else + { + KMessageBox::error ( this, i18n ( "No ssh askpass program found!" ) ); + GlobalConfig->appendLogEntry ( i18n ( "No ssh askpass program found!" ),GlobalConfig->error ); + disconnectClicked(); + return; + } + +// SshProcess->setUsePty(KProcess::All ,true); + +// if ( !SshProcess->start(KProcess::NotifyOnExit,KProcess::Communication(KProcess::All))) +// if ( !SshProcess->start(KProcess::RunMode(KProcess::NotifyOnExit),KProcess::Communication(KProcess::All))) + if ( !SshProcess->start ( KProcess::NotifyOnExit, KProcess::All ) ) + { + KMessageBox::sorry ( this, i18n ( "\"%1\" start failed!" ).arg ( "ssh" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "ssh" ) , GlobalConfig->error ); + disconnectClicked(); + } + else + { + ConnectingProcess = VpnAccountData::ssh; + GlobalConfig->status = GlobalConfig->connecting; + mw->buttonDisconnect->setEnabled ( true ); + this->DisconnectAction->setEnabled ( true ); + mw->buttonConnect->setEnabled ( false ); + this->ConnectAction->setEnabled ( false ); + + GlobalConfig->currentConnectRetry++; + + SshProcess->writeStdin ( QString ( GlobalConfig->TmpPassword+'\n' ).ascii(),GlobalConfig->TmpPassword.length() +1 ); + + } + } + else + { + setGuiStatus ( disconnected ); + return ; + } + } +} + +void KVpnc::disconnectClicked() +{ + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Disconnect requested" ), GlobalConfig->debug ); + + DisconnectAction->setEnabled ( false ); + + tmpPath = locateLocal ( "data", "kvpnc/" ); + + if ( GlobalConfig->status == GlobalConfig->connected ) + { + prevConnectionState = connected; + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Disconnect requested, status connected" ), GlobalConfig->debug ); + QString type_string = ""; + bool ok = true; // if ok we will run process + + if ( ConnectionStatusCheckProcess != 0 ) + { + if ( ConnectionStatusCheckProcess->isRunning() ) + { + disconnect ( ConnectionStatusCheckProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_connectionStatusCheck() ) ); + disconnect ( ConnectionStatusCheckProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_connectionStatusCheck() ) ); + + ConnectionStatusCheckProcess->kill(); + + } + } + // here we go + if ( ok ) + { + if ( GlobalConfig->currentProfile->getUseAdditionalNetworkRoutes() ) + removeAdditionalNetworkRoutes(); + + if ( GlobalConfig->currentProfile->getExecuteCmdBeforeDisconnect() ) + executeCommandBeforeDisconnect(); + setFirewallBeforeDisconnect(); + + /* type selection */ + // cisco + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::cisco ) + { + + tmpPath = locateLocal ( "data", "kvpnc/" ); + //Vpnc_pid_file = tmpPath + "vpnc-pid." + GlobalConfig->currentProfile->getID() + ".pid"; // vpnc-pid..pid + VpncDisconnectScript = tmpPath + "vpnc-disconnect." + GlobalConfig->currentProfile->getID() + ".sh"; + // write vpnc connect script + QFile pidFile ( GlobalConfig->Vpnc_pid_file ); + QString Vpnc_pid = ""; + if ( pidFile.open ( IO_ReadOnly ) ) + { + Vpnc_pid = QString ( pidFile.readAll() ).stripWhiteSpace(); + } + + + if ( VpncProcess != 0 ) + { + if ( VpncProcess->isRunning() ) + { + disconnect ( VpncProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readOutputFrom_vpnc() ) ); + disconnect ( VpncProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readOutputFrom_vpnc() ) ); + disconnect ( &timer, SIGNAL ( timeout() ), this, SLOT ( slotConnectTimedOut() ) ); + + VpncProcess->kill(); + sleep ( 1 ); + if ( VpncProcess->isRunning() ) + VpncProcess->kill(); + sleep ( 1 ); + if ( VpncProcess->isRunning() ) + VpncProcess->kill(); + sleep ( 1 ); + if ( VpncProcess->isRunning() ) + VpncProcess->kill(); + } + delete VpncProcess; + VpncProcess = 0L; + } + + QFile file ( VpncDisconnectScript ); + QTextStream stream ( &file ); + if ( file.open ( IO_WriteOnly ) ) + { + stream << "#!"<< GlobalConfig->InterpreterShell << "\n"; + stream << "# generated by kvpnc. Do not edit it." << "\n"; + stream << "# profile: " + GlobalConfig->currentProfile->getName() << "\n"; + stream << "\n"; + + if ( !Vpnc_pid.isEmpty() ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Vpnc pid file found, killing process %1" ).arg ( Vpnc_pid ) , GlobalConfig->debug ); + stream << GlobalConfig->pathToKill << " " << Vpnc_pid << " > /dev/null 2>&1\n"; + stream << GlobalConfig->pathToKill << " " << Vpnc_pid << " > /dev/null 2>&1\n"; + stream << GlobalConfig->pathToKill << " " << Vpnc_pid << " > /dev/null 2>&1\n"; + stream << GlobalConfig->pathToKill << " -TERM " << Vpnc_pid << " > /dev/null 2>&1\n"; + stream << GlobalConfig->pathToKill << " -TERM " << Vpnc_pid << " > /dev/null 2>&1\n"; + stream << GlobalConfig->pathToKill << " -TERM " << Vpnc_pid << " > /dev/null 2>&1\n"; + stream << GlobalConfig->pathToKill << " -KILL " << Vpnc_pid << " > /dev/null 2>&1\n"; + stream << GlobalConfig->pathToKill << " -KILL " << Vpnc_pid << " > /dev/null 2>&1\n"; + stream << GlobalConfig->pathToKill << " -KILL " << Vpnc_pid << " > /dev/null 2>&1\n"; + QFile ( GlobalConfig->Vpnc_pid_file ).remove(); + } +// else +// { +// if ( GlobalConfig->KvpncDebugLevel > 0 ) +// GlobalConfig->appendLogEntry ( i18n ( "No vpnc pid file found, using \"killall\" for killing vpnc." ), GlobalConfig->debug ); +// stream << GlobalConfig->pathToKillall << " -TERM vpnc" << " > /dev/null 2>&1\n"; +// stream << GlobalConfig->pathToKillall << " -TERM vpnc" << " > /dev/null 2>&1\n"; +// stream << GlobalConfig->pathToKillall << " -TERM vpnc" << " > /dev/null 2>&1\n"; +// stream << GlobalConfig->pathToKillall << " -KILL vpnc" << " > /dev/null 2>&1\n"; +// stream << GlobalConfig->pathToKillall << " -KILL vpnc" << " > /dev/null 2>&1\n"; +// stream << GlobalConfig->pathToKillall << " -KILL vpnc" << " > /dev/null 2>&1\n"; +// } + + if ( GlobalConfig->currentProfile->getUseDnsUpdate() ) + { + // FIXME this is a temporary fix for not calling vpnc script with disconnect at disconnect time! + if (VpncDevice.isEmpty()) + VpncDevice = "tun0"; + stream << " if [ -f /sbin/resolvconf ] ; then\n"; + stream << " /sbin/resolvconf -d \"" << VpncDevice << "\"\n"; + stream << " else\n"; + stream << " cat " + tmpPath + "resolv.conf.before.kvpnc_" + GlobalConfig->currentProfile->getName() + " > /etc/resolv.conf\n"; + stream << " fi\n"; + // end temp fix + } + else + { + /* dont update dns */ + } + + if ( GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Restoring default route before connection..." ), GlobalConfig->debug ); + + QString OldDefaultroute = tmpPath + "default-route." + GlobalConfig->currentProfile->getName(); // default-route. + stream << GlobalConfig->pathToIp + " route del default > /dev/null 2>&1\n"; + stream << GlobalConfig->pathToIp + " route add $(cat \"" + OldDefaultroute + "\")\n"; + // stream << GlobalConfig->pathToIp + " route add $(cat \"/var/run/vpnc/defaultroute\")\n"; + } + // stream << GlobalConfig->pathToIp+" route del $(cat \"" + VpncGateway + "\")\n"; + + // fix broken vpnc: remove route of vpngatewayAddNetworkRouteDialog + stream << GlobalConfig->pathToRoute << " del " + GlobalConfig->TmpGatewayIP << "\n"; + + stream << GlobalConfig->pathToIp + " route flush cache\n"; + + file.close(); + + DisconnectProcess = new QProcess (); + DisconnectProcess->addArgument ( GlobalConfig->InterpreterShell ); + DisconnectProcess->addArgument ( VpncDisconnectScript ); + + connect ( DisconnectProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_disconnect() ) ); + connect ( DisconnectProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_disconnect() ) ); + + if ( !DisconnectProcess->start ( env ) ) + { + KMessageBox::sorry ( this, i18n ( "\"%1\" start failed!" ).arg ( "vpnc_disconnect" ) ); + } + else + { + while ( DisconnectProcess->isRunning() ) + { + sleep ( 1 ); + } + } + disconnect ( DisconnectProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_disconnect() ) ); + disconnect ( DisconnectProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_disconnect() ) ); + delete DisconnectProcess; + DisconnectProcess=0L; + } + + setGuiStatus ( disconnected ); + durationTimer.stop(); + disconnect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + connectionEnded(); + } + // vpnclient + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ciscoorig ) + { + tmpPath = locateLocal ( "data", "kvpnc/" ); + QString CiscoVpncDisconnectScript = tmpPath + "vpnclient-disconnect." + GlobalConfig->currentProfile->getID() + ".sh"; + // write vpnc connect script + + QFile file ( CiscoVpncDisconnectScript ); + QTextStream stream ( &file ); + if ( file.open ( IO_WriteOnly ) ) + { + stream << "#!"<< GlobalConfig->InterpreterShell << "\n"; + stream << "# generated by kvpnc. Do not edit it." << "\n"; + stream << "# profile: " + GlobalConfig->currentProfile->getName() << "\n"; + stream << "\n"; + +// if ( !GlobalConfig->currentProfile->getKeepDefaultRoute() ) +// { +// if ( GlobalConfig->KvpncDebugLevel > 2 ) +// GlobalConfig->appendLogEntry ( i18n ( "Restoring default route before connection..." ), GlobalConfig->debug ); +// +// QString OldDefaultroute = tmpPath + "default-route." + GlobalConfig->currentProfile->getName(); // default-route. +// stream << GlobalConfig->pathToIp + " route del default > /dev/null 2>&1\n"; +// stream << GlobalConfig->pathToIp + " route add $(cat \"" + OldDefaultroute + "\")\n"; +// // stream << GlobalConfig->pathToIp + " route add $(cat \"/var/run/vpnc/defaultroute\")\n"; +// } +// // stream << GlobalConfig->pathToIp+" route del $(cat \"" + VpncGateway + "\")\n"; + + /* update dns? */ + if ( GlobalConfig->currentProfile->getUseDnsUpdate() ) + { +// stream << "chmod u+w /etc/resolv.conf\n"; + stream << "if [ -f /sbin/resolvconf ] ; then\n"; + stream << " /sbin/resolvconf -d "+GlobalConfig->DnsDevice+"\n"; + stream << "else\n"; + stream << " cat " + tmpPath + "resolv.conf.before.kvpnc_" + GlobalConfig->currentProfile->getName() + " > /etc/resolv.conf\n"; + stream << "fi\n"; + } + else + { + /* dont update dns */ + } + + stream << GlobalConfig->pathToIp + " route flush cache\n"; + + } + file.close(); + + DisconnectProcess = new QProcess (); + DisconnectProcess->addArgument ( GlobalConfig->InterpreterShell ); + DisconnectProcess->addArgument ( CiscoVpncDisconnectScript ); + + connect ( DisconnectProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_disconnect() ) ); + connect ( DisconnectProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_disconnect() ) ); + + if ( !DisconnectProcess->start ( env ) ) + { + KMessageBox::sorry ( this, i18n ( "\"%1\" start failed!" ).arg ( "vpnc_disconnect" ) ); + } + else + { + while ( DisconnectProcess->isRunning() ) + { + sleep ( 1 ); + } + } + disconnect ( DisconnectProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_disconnect() ) ); + disconnect ( DisconnectProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_disconnect() ) ); + delete DisconnectProcess; + DisconnectProcess=0L; + + disconnect ( &timer, SIGNAL ( timeout() ), this, SLOT ( slotConnectTimedOut() ) ); + + + if ( CiscoVpncProcess != 0 && CiscoVpncProcess->isRunning() ) + CiscoVpncProcess->tryTerminate(); + sleep ( 1 ); + if ( CiscoVpncProcess != 0 && CiscoVpncProcess->isRunning() ) + CiscoVpncProcess->kill(); + + delete CiscoVpncProcess; + CiscoVpncProcess=0L; + + setGuiStatus ( disconnected ); + disconnect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + connectionEnded(); + } + // racoon + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon || GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { + + // // looking for setkey + // if ( GlobalConfig->pathToSetkey.isEmpty() ) { + // QFile setkey( "/usr/sbin/setkey" ); + // if ( setkey.exists() ) + // GlobalConfig->pathToSetkey = "/usr/sbin/setkey"; + // else { + // setkey.setName( "/usr/local/sbin/setkey" ); + // if ( setkey.exists() ) + // GlobalConfig->pathToSetkey = "/usr/local/sbin/setkey"; + // else { + // setkey.setName( "/usr/bin/setkey" ); + // if ( setkey.exists() ) + // GlobalConfig->pathToSetkey = "/usr/bin/setkey"; + // else { + // KMessageBox::error( this, i18n( "Unable to find \"%1\"!" ).arg("setkey") ); + // ok = false; + // } + // } + // } + // } + + + + QFile file2 ( tmpPath + "setkey." + GlobalConfig->currentProfile->getName() + ".remove_setkey.sh" ); + QTextStream stream2 ( &file2 ); + if ( file2.open ( IO_WriteOnly ) ) + { + stream2 << "#!"<< GlobalConfig->InterpreterShell << "\n"; + stream2 << "# generated by kvpnc. Do not edit it." << "\n"; + stream2 << "# profile: " + GlobalConfig->currentProfile->getName() << "\n"; + stream2 << GlobalConfig->pathToSetkey << " -PF" << "\n"; + stream2 << GlobalConfig->pathToSetkey << " -F" << "\n"; + file2.close(); + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" write successful." ).arg ( "setkey (remove)" ) , GlobalConfig->debug ); + } + else + { + // KMessageBox::error( this, i18n( "\"%1\" write failed!" ).arg( "setkey (remove)" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" write failed!" ).arg ( "setkey (remove)" ) , GlobalConfig->error ); + } + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { +// if (QFile("/var/run/l2tpd.pid").exists()) +// { +// if (GlobalConfig->KvpncDebugLevel > 1) +// GlobalConfig->appendLogEntry(i18n("Using control interface for disconnecting l2tp connection"),GlobalConfig->debug); +// QFile L2tpdControlFile ( "/var/run/l2tp-control" ); +// QTextStream stream( &L2tpdControlFile ); +// if ( L2tpdControlFile.open( IO_WriteOnly ) ) { +// stream << "d " << GlobalConfig->currentProfile->getName() << "\n"; +// L2tpdControlFile.close(); +// } +// } +// else +// { + if ( GlobalConfig->currentProfile->getL2tpDaemon() == VpnAccountData::l2tpd ) + { + if ( L2tpdProcess != 0L && L2tpdProcess->isRunning() ) + { + + disconnect ( this, SIGNAL ( L2tpdStdoutRecieved() ), this, SLOT ( processStdout_l2tpd() ) ); + disconnect ( this, SIGNAL ( L2tpdStderrRecieved() ), this, SLOT ( processStderr_l2tpd() ) ); + + L2tpdProcess->kill(); + if ( L2tpdProcess->isRunning() ) + L2tpdProcess->tryTerminate(); + sleep ( 1 ); + if ( L2tpdProcess != 0L && L2tpdProcess->isRunning() ) + L2tpdProcess->kill(); + } + } + if ( GlobalConfig->currentProfile->getL2tpDaemon() == VpnAccountData::openl2tp ) + { + if ( OpenL2tpProcess != 0L && OpenL2tpProcess->isRunning() ) + { + + disconnect ( OpenL2tpProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_openl2tp() ) ); + disconnect ( OpenL2tpProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_openl2tp() ) ); + + OpenL2tpProcess->tryTerminate(); + sleep ( 1 ); + if ( OpenL2tpProcess->isRunning() ) + OpenL2tpProcess->tryTerminate(); + sleep ( 1 ); + if ( OpenL2tpProcess != 0L && OpenL2tpProcess->isRunning() ) + OpenL2tpProcess->kill(); + + if ( QFile ( "/var/run/openl2tpd.pid" ).exists() ) + QFile ( "/var/run/openl2tpd.pid" ).remove(); + + if ( !Utils ( GlobalConfig, parent ).unloadKernelModule ( "slhc", parent ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" failed" ).arg ( "slhc" ).arg ( "/etc/modprobe.conf" ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" succeded" ).arg ( "slhc" ), GlobalConfig->debug ); + } + if ( !Utils ( GlobalConfig, parent ).unloadKernelModule ( "ppp_generic", parent ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" failed." ).arg ( "ppp_generic" ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" succeded" ).arg ( "ppp_generic" ), GlobalConfig->debug ); + } + if ( !Utils ( GlobalConfig, parent ).unloadKernelModule ( "pppox", parent ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" failed." ).arg ( "pppox" ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" succeded" ).arg ( "pppox" ), GlobalConfig->debug ); + } + if ( !Utils ( GlobalConfig, parent ).unloadKernelModule ( "pppol2tp", parent ,true ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" failed" ).arg ( "pppol2tp" ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" succeded" ).arg ( "pppol2tp" ), GlobalConfig->debug ); + } + + startStopOpenl2tp ( true ); + sleep ( 2 ); + startStopOpenl2tp(); + + } + } +// } + } + + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon && GlobalConfig->currentProfile->getUseLeftSourceIp()) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Removing virtual IP address" ), GlobalConfig->debug ); + doAddRemoveVirtualIp("del"); + } + stopRacoon(); + + if ( RacoonTailProcess != 0 && RacoonTailProcess->isRunning() ) + { + disconnect ( RacoonTailProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_tail_racoon() ) ); + disconnect ( RacoonTailProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_tail_racoon() ) ); + // terminateConnection( RacoonTailProcess ); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Trying to terminate \"%1\"..." ).arg ( "racoon tail" ) , GlobalConfig->debug ); + + RacoonTailProcess->tryTerminate(); + + while ( RacoonTailProcess != 0 && RacoonTailProcess->isRunning() ) + { + sleep ( 1 ); + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Killing \"%1\"..." ).arg ( "racoon tail" ) , GlobalConfig->debug ); + RacoonTailProcess->kill(); + } + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" killed" ).arg ( "racoon tail" ) , GlobalConfig->debug ); + + } + + if ( RacoonProcess != 0 && RacoonProcess->isRunning() ) + { + disconnect ( RacoonProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_racoon() ) ); + disconnect ( RacoonProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_racoon() ) ); + + // terminateConnection( RacoonProcess ); + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Trying to terminate \"%1\"..." ).arg ( "racoon" ) , GlobalConfig->debug ); +// RacoonProcess->tryTerminate(); + while ( RacoonProcess != 0 && RacoonProcess->isRunning() ) + { + sleep ( 1 ); + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Killing \"%1\"..." ).arg ( "racoon" ) , GlobalConfig->debug ); + + RacoonProcess->kill(); + } + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" killed" ).arg ( "racoon tail" ) , GlobalConfig->debug ); + + } + + delete RacoonProcess; + RacoonProcess =0L; + + removeSetkey(); + delRouteRacoon(); + removeIptablesRacoon(); + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon && ( GlobalConfig->currentProfile->getL2tpDaemon() == "l2tpd" || GlobalConfig->currentProfile->getL2tpDaemon() == "l2tpd" ) ) + { + // remove kvpnc entries from secrets file + QFile papSecretsFile ( "/etc/ppp/pap-secrets" ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "pppd secrets file: %1" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + QTextStream stream ( &papSecretsFile ); + if ( papSecretsFile.open ( IO_ReadOnly ) ) + { + QString line = ""; + QString papsecret_content = ""; + bool kvpnc_start_marker_found = false; + bool kvpnc_end_marker_found = false; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' + if ( line == "# --- generated by kvpnc. Do not edit it." ) + { + kvpnc_end_marker_found = true; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "End marker in %1 found" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + } + if ( line == "# +++ generated by kvpnc. Do not edit it." ) + { + kvpnc_start_marker_found = true; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Start marker in %1 found" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + } + + if ( kvpnc_start_marker_found == false ) + { + papsecret_content += line; + papsecret_content += '\n'; + } + } + papSecretsFile.close(); + if ( papSecretsFile.remove() ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 successfully removed" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + // papSecretsFile.setName("/etc/ppp/pap-secrets2"); + if ( papSecretsFile.open ( IO_WriteOnly ) ) + { + stream.setDevice ( &papSecretsFile ); + stream << papsecret_content; + papSecretsFile.close(); + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 sucessfully rewritten" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 rewrite failed" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->error ); + } + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 remove failed" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->error ); + } + + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "File %1 could not opened!" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->error ); + } + } + + setGuiStatus ( disconnected ); + disconnect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + durationTimer.stop(); + connectionEnded(); + + // DisconnectProcess->clearArguments(); + // DisconnectProcess->addArgument( GlobalConfig->pathToKillall ); + // DisconnectProcess->addArgument( "-3" ); + // DisconnectProcess->addArgument( "racoon" ); + // + // connect( DisconnectProcess, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdout_racoon() ) ); + // connect( DisconnectProcess, SIGNAL( readyReadStderr() ), this, SLOT( readFromStderr_racoon() ) ); + // connect( DisconnectProcess, SIGNAL( processExited () ), this, SLOT( removeSetkey() ) ); + // + // if ( !DisconnectProcess->start(env) ) + // KMessageBox::error( this, i18n( "\"%1\" start failed!" ).arg("killall -3 racoon") ); + // else { + // RacoonTailProcess->tryTerminate(); + // if ( GlobalConfig->KvpncDebugLevel > 0 ) + // GlobalConfig->appendLogEntry( i18n( "\"%1\" was successful." ).arg("killall -3 racoon"), GlobalConfig->debug ); + // } + +// } + } + // freeswan + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan || GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { + // iptables need the right interface (eth0:1 => eth0) + QString tmpInterface2 = ""; + int pointPos = tmpInterface.find ( ':', 0, FALSE ); + if ( pointPos > 1 ) + { + tmpInterface2 = tmpInterface.left ( pointPos ); + } + else + tmpInterface2 = tmpInterface; + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { +// if (QFile("/var/run/l2tpd.pid").exists()) +// { +// if (GlobalConfig->KvpncDebugLevel > 1) +// GlobalConfig->appendLogEntry(i18n("Using control interface for disconnecting l2tp connection"),GlobalConfig->debug); +// QFile L2tpdControlFile ( "/var/run/l2tp-control" ); +// QTextStream stream( &L2tpdControlFile ); +// if ( L2tpdControlFile.open( IO_WriteOnly ) ) { +// stream << "d " << GlobalConfig->currentProfile->getName() << "\n"; +// L2tpdControlFile.close(); +// } +// } +// else + { + if ( GlobalConfig->currentProfile->getL2tpDaemon() == VpnAccountData::l2tpd ) + { + if ( L2tpdProcess != 0L && L2tpdProcess->isRunning() ) + { + + L2tpdProcess->kill(); +// if (L2tpdProcess->isRunning()) +// L2tpdProcess->tryTerminate(); + sleep ( 1 ); + if ( L2tpdProcess != 0L && L2tpdProcess->isRunning() ) + L2tpdProcess->kill(); + } + } + if ( GlobalConfig->currentProfile->getL2tpDaemon() == VpnAccountData::openl2tp ) + { + if ( OpenL2tpProcess != 0L && OpenL2tpProcess->isRunning() ) + { + disconnect ( OpenL2tpProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_openl2tp() ) ); + disconnect ( OpenL2tpProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_openl2tp() ) ); + //OpenL2tpProcess->tryTerminate(); + sleep ( 1 ); + //if (OpenL2tpProcess->isRunning()) + // OpenL2tpProcess->tryTerminate(); + sleep ( 1 ); + if ( OpenL2tpProcess != 0L && OpenL2tpProcess->isRunning() ) + OpenL2tpProcess->kill(); + + if ( QFile ( "/var/run/openl2tpd.pid" ).exists() ) + QFile ( "/var/run/openl2tpd.pid" ).remove(); + + if ( !Utils ( GlobalConfig, parent ).unloadKernelModule ( "slhc", parent ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" failed" ).arg ( "slhc" ).arg ( "/etc/modprobe.conf" ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" succeded" ).arg ( "slhc" ), GlobalConfig->debug ); + } + if ( !Utils ( GlobalConfig, parent ).unloadKernelModule ( "ppp_generic", parent ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" failed." ).arg ( "ppp_generic" ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" succeded" ).arg ( "ppp_generic" ), GlobalConfig->debug ); + } + if ( !Utils ( GlobalConfig, parent ).unloadKernelModule ( "pppox", parent ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" failed." ).arg ( "pppox" ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" succeded" ).arg ( "pppox" ), GlobalConfig->debug ); + } + if ( !Utils ( GlobalConfig, parent ).unloadKernelModule ( "pppol2tp", parent ,true ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" failed" ).arg ( "pppol2tp" ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" succeded" ).arg ( "pppol2tp" ), GlobalConfig->debug ); + } + + startStopOpenl2tp ( true ); + sleep ( 2 ); + startStopOpenl2tp(); + + } + } + + } + } + + if (GlobalConfig->currentProfile->getUseLeftSourceIp()) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Removing virtual IP address" ), GlobalConfig->debug ); + doAddRemoveVirtualIp("del"); + } + + + ToolInfo *tool = Utils ( GlobalConfig ).getToolInfo ( "ipsec" ); + QString realversion = tool->Version.section ( ' ', 1, 1 ).section ( '/', 0, 0 ).right ( tool->Version.section ( ' ', 1, 1 ).section ( '/', 0, 0 ).length() - 1 ); + int IpsecMajor= realversion.section ( '.',0,0 ).toInt(); + int IpsecMinor= realversion.section ( '.',1,1 ).toInt(); + int IpsecSubMinor= realversion.section ( '.',2,2 ).toInt(); + QString realtype = tool->Version.section ( ' ', 0, 0 ).lower(); + + putenv ( ( char* ) ( "LC_ALL=C" ) ); + IpsecWhackDeleteProcess = new QProcess ( this ); + IpsecWhackDeleteProcess->addArgument ( GlobalConfig->pathToIpsec ); + IpsecWhackDeleteProcess->addArgument ( "whack" ); + IpsecWhackDeleteProcess->addArgument ( "--name" ); + IpsecWhackDeleteProcess->addArgument ( GlobalConfig->currentProfile->getName() ); + IpsecWhackDeleteProcess->addArgument ( "--delete" ); + + connect ( IpsecWhackDeleteProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_ipsecwhackdelete() ) ); + connect ( IpsecWhackDeleteProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsecwhackdelete() ) ); + + if ( !IpsecWhackDeleteProcess->start ( env ) ) + { + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( GlobalConfig->pathToIpsec+" whack' --name "+GlobalConfig->currentProfile->getName() +" --delete" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( GlobalConfig->pathToIpsec+" whack' --name "+GlobalConfig->currentProfile->getName() +" --delete" ) , GlobalConfig->error ); + } + else + { + int tryCounter=0; + while ( IpsecWhackDeleteProcess !=0 && IpsecWhackDeleteProcess->isRunning() ) + { + tryCounter++; + if ( tryCounter ==20 ) + { + tryCounter=0; + if ( GlobalConfig->KvpncDebugLevel > 8 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" is still running waiting for terminate..." ).arg ( GlobalConfig->pathToIpsec+" whack --name "+GlobalConfig->currentProfile->getName() +" --delete" ), GlobalConfig->debug ); + } + usleep ( 500 ); + } + } + disconnect ( IpsecWhackDeleteProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_ipsecwhackdelete() ) ); + disconnect ( IpsecWhackDeleteProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsecwhackdelete() ) ); + delete IpsecWhackDeleteProcess; + IpsecWhackDeleteProcess=0L; + + // prevent old logs... + IpsecGotError = true; + + +// IpsecStartProcess = new QProcess ( this ); +// IpsecStartProcess->addArgument ( GlobalConfig->pathToIpsec ); +// if ( !IpsecType.contains ( "Openswan", false ) ) +// { +// IpsecStartProcess->addArgument ( "setup" ); +// IpsecStartProcess->addArgument ( "stop" ); +// } +// // if (IpsecType.contains( "strongSwan", false ) && ( (IpsecMajor >= 4 && IpsecMinor >= 2 && IpsecSubMinor >=2 ) || IpsecMajor > 4 ) ) +// // if ( ! IpsecType.contains ( "free", false ) && ( (IpsecMajor = 4 && IpsecMinor >= 2 && IpsecSubMinor >= 2) || IpsecMajor > 4)) +// if ( IpsecType.contains ( "strongSwan", false ) ) +// { +// IpsecStartProcess->addArgument ( "stop" ); +// } +// +// connect ( IpsecStartProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStderr_ipsec() ) ); +// connect ( IpsecStartProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsec() ) ); +// // connect( IpsecStartProcess, SIGNAL( processExited () ), this, SLOT( removeRouteFreeswan() ) ); +// +// if ( !IpsecStartProcess->start ( env ) ) +// { +// if ( !IpsecType.contains ( "strongSwan", false ) ) +// { +// KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( "ipsec setup stop" ) ); +// GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "ipsec setup stop" ) , GlobalConfig->error ); +// } +// if ( ! IpsecType.contains ( "free", false ) && ( ( IpsecMajor = 4 && IpsecMinor >= 2 && IpsecSubMinor >= 2 ) || IpsecMajor > 4 ) ) +// { +// KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( "ipsec stop" ) ); +// GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "ipsec stop" ) , GlobalConfig->error ); +// } +// } +// else +// { +// int tryCounter=0; +// while ( IpsecStartProcess !=0 && IpsecStartProcess->isRunning() ) +// { +// tryCounter++; +// // if (tryCounter ==20) +// { +// tryCounter=0; +// if ( GlobalConfig->KvpncDebugLevel > 8 ) +// { +// if ( !IpsecType.contains ( "strongSwan", false ) ) +// GlobalConfig->appendLogEntry ( i18n ( "\"%1\" is still running waiting for terminate..." ).arg ( "ipsec setup stop" ), GlobalConfig->debug ); +// if ( IpsecType.contains ( "strongSwan", false ) && ( ( IpsecMajor >= 4 && IpsecMinor >= 2 && IpsecSubMinor >=2 ) || IpsecMajor > 4 ) ) +// GlobalConfig->appendLogEntry ( i18n ( "\"%1\" is still running waiting for terminate..." ).arg ( "ipsec stop" ), GlobalConfig->debug ); +// } +// } +// usleep ( 500 ); +// } +// +// } +// disconnect ( IpsecStartProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStderr_ipsec() ) ); +// disconnect ( IpsecStartProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsec() ) ); +// //disconnect( IpsecStartProcess, SIGNAL( processExited () ), this, SLOT( removeRouteFreeswan() ) ); +// delete IpsecStartProcess; +// IpsecStartProcess=0L; + + // stopping using function + startStopIpsec(true); + + delRouteIpsec(); + removeIptablesFreeswan(); + disconnect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + setGuiStatus ( disconnected ); + durationTimer.stop(); + GlobalConfig->currentConnectRetry=0; + connectionEnded(); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Restoring original ipsec settings" ), KVpncConfig::debug ); + + // restore system files + QString IpsecPrefix = "/etc"; + // ipsec.conf + QFile originalIpsecConfFile ( "/etc/ipsec.conf.before.kvpnc" ); + QTextStream stream ( &originalIpsecConfFile ); + QString originalIpsecConfFileContent = ""; + + if ( originalIpsecConfFile.exists() ) + { + if ( originalIpsecConfFile.open ( IO_ReadOnly ) ) + { + originalIpsecConfFileContent = QString ( originalIpsecConfFile.readAll() ); + originalIpsecConfFile.close(); + } + } + + QFile backupOriginalIpsecConfFile ( "/etc/ipsec.conf" ); + stream.setDevice ( &backupOriginalIpsecConfFile ); + if ( backupOriginalIpsecConfFile.open ( IO_WriteOnly ) ) + { + stream << originalIpsecConfFileContent; + backupOriginalIpsecConfFile.close(); + } + stream.unsetDevice(); + + //if ( GlobalConfig->KvpncDebugLevel > 0 ) + // GlobalConfig->appendLogEntry( i18n( "%1 found in %2, assuming %3 as prefix for %4." ).arg( "ipsec.conf.before.kvpnc" ).arg( IpsecPrefix ).arg( IpsecPrefix ).arg( IpsecType ), GlobalConfig->debug ); + + // ipsec.secret + QFile originalIpsecSecretFile ( "/etc/ipsec.secrets.before.kvpnc" ); + stream.setDevice ( &originalIpsecSecretFile ); + QString originalIpsecSecretFileContent = ""; + if ( originalIpsecSecretFile.open ( IO_ReadOnly ) ) + { + originalIpsecSecretFileContent = QString ( originalIpsecSecretFile.readAll() ); + originalIpsecSecretFile.close(); + } + + QFile backupOriginalIpsecSecretFile ( "/etc/ipsec.secrets" ); + stream.setDevice ( &backupOriginalIpsecSecretFile ); + if ( backupOriginalIpsecSecretFile.open ( IO_WriteOnly ) ) + { + stream << originalIpsecSecretFileContent; + backupOriginalIpsecSecretFile.close(); + } + stream.unsetDevice(); + + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { + // remove kvpnc entries from secrets file + QFile papSecretsFile ( "/etc/ppp/pap-secrets" ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "pppd secrets file: %1" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + QTextStream stream ( &papSecretsFile ); + if ( papSecretsFile.open ( IO_ReadOnly ) ) + { + QString line = ""; + QString papsecret_content = ""; + bool kvpnc_start_marker_found = false; + bool kvpnc_end_marker_found = false; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' + if ( line == "# --- generated by kvpnc. Do not edit it." ) + { + kvpnc_end_marker_found = true; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "End marker in %1 found" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + } + if ( line == "# +++ generated by kvpnc. Do not edit it." ) + { + kvpnc_start_marker_found = true; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Start marker in %1 found" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + } + + if ( kvpnc_start_marker_found == false ) + { + papsecret_content += line; + papsecret_content += '\n'; + } + } + papSecretsFile.close(); + if ( papSecretsFile.remove() ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 successfully removed" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + // papSecretsFile.setName("/etc/ppp/pap-secrets2"); + if ( papSecretsFile.open ( IO_WriteOnly ) ) + { + stream.setDevice ( &papSecretsFile ); + stream << papsecret_content; + papSecretsFile.close(); + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 sucessfully rewritten" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 rewrite failed" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->error ); + } + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 remove failed" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->error ); + } + + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "File %1 could not opened!" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->error ); + } + } + + + // start ipsec with restored config again + startStopIpsec ( false ); + + } + // pptp + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::pptp ) + { + + if (PptpProcess != 0L) + { + disconnect ( PptpProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_pptp() ) ); + disconnect ( PptpProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_pptp() ) ); + OldDefaultroute = tmpPath + "default-route." + GlobalConfig->currentProfile->getName(); // default-route. + + ToolInfo *PptpInfo = Utils ( GlobalConfig ).getToolInfo ( "pptp" ); + QString pptpversion = PptpInfo->Version.section ( ' ', 1, 1 ).section ( '/', 0, 0 ).right ( PptpInfo->Version.section ( ' ', 1, 1 ).section ( '/', 0, 0 ).length() - 1 ); + int PptpMajor= pptpversion.section ( '.',0,0 ).toInt(); + int PptpMinor= pptpversion.section ( '.',1,1 ).toInt(); + int PptpSubMinor= pptpversion.section ( '.',2,2 ).toInt(); + + if ( PptpProcess != 0 && PptpProcess->isRunning()) + PptpProcess->kill(); + + +// QProcess *pptpdKillProcess = new QProcess ( this ); +// if ( GlobalConfig->KvpncDebugLevel > 2 ) +// GlobalConfig->appendLogEntry ( i18n ( "No pid file, trying to terminate %1 with killall..." ).arg ( "pptp" ), GlobalConfig->debug ); +// pptpdKillProcess->addArgument ( GlobalConfig->pathToKillall ); +// pptpdKillProcess->addArgument ( "-TERM" ); +// pptpdKillProcess->addArgument ( GlobalConfig->pathToPptp ); +// +// if ( !pptpdKillProcess->start ( env ) ) +// { +// KMessageBox::sorry ( this, i18n ( "\"%1\" start failed!" ).arg ( QString ( GlobalConfig->pathToKillall+" -TERM "+GlobalConfig->pathToPptp ) ) ); +// } +// else +// { +// if ( GlobalConfig->KvpncDebugLevel > 1 ) +// GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( QString ( GlobalConfig->pathToKillall+" -TERM "+GlobalConfig->pathToPptp ) ) , GlobalConfig->debug ); +// } +// +// sleep ( 2 ); +// pptpdKillProcess->kill(); +// if ( GlobalConfig->KvpncDebugLevel > 2 ) +// GlobalConfig->appendLogEntry ( i18n ( "kill %1 with killall..." ).arg ( "pptp" ), GlobalConfig->debug ); +// +// pptpdKillProcess->clearArguments(); +// pptpdKillProcess->addArgument ( GlobalConfig->pathToKillall ); +// pptpdKillProcess->addArgument ( "-KILL" ); +// pptpdKillProcess->addArgument ( GlobalConfig->pathToPptp ); +// +// if ( !pptpdKillProcess->start ( env ) ) +// { +// KMessageBox::sorry ( this, i18n ( "\"%1\" start failed!" ).arg ( QString ( GlobalConfig->pathToKillall+" -KILL "+GlobalConfig->pathToPptp ) ) ); +// } +// else +// { +// if ( GlobalConfig->KvpncDebugLevel > 1 ) +// GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( "killall" ) , GlobalConfig->debug ); +// +// while ( pptpdKillProcess->isRunning() ) +// { +// sleep ( 1 ); +// } +// } +// +// int killcounter=0; +// while ( PptpProcess != 0 && PptpProcess->isRunning() && killcounter < 5 ) +// { +// sleep ( 1 ); +// killcounter++; +// if ( GlobalConfig->KvpncDebugLevel > 8 ) +// GlobalConfig->appendLogEntry ( i18n ( "\"%1\" is still running waiting for terminate..." ).arg ( "pptp" ) , GlobalConfig->debug ); +// GlobalConfig->appPointer->processEvents(); +// } +// +// if ( killcounter >= 5 ) +// { +// pptpdKillProcess->kill(); +// pptpdKillProcess->clearArguments(); +// pptpdKillProcess->addArgument ( GlobalConfig->pathToKillall ); +// pptpdKillProcess->addArgument ( "-9" ); +// pptpdKillProcess->addArgument ( GlobalConfig->pathToPptp ); +// +// if ( !pptpdKillProcess->start ( env ) ) +// { +// KMessageBox::sorry ( this, i18n ( "\"%1\" start failed!" ).arg ( QString ( GlobalConfig->pathToKillall+" -SIGKILL "+GlobalConfig->pathToPptp ) ) ); +// } +// else +// { +// if ( GlobalConfig->KvpncDebugLevel > 1 ) +// GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( QString ( GlobalConfig->pathToKillall+" -SIGKILL "+GlobalConfig->pathToPptp ) ) , GlobalConfig->debug ); +// while ( pptpdKillProcess->isRunning() ) +// { +// sleep ( 1 ); +// } +// } +// delete pptpdKillProcess; +// pptpdKillProcess=0L; +// +// while ( PptpProcess != 0 && PptpProcess->isRunning() ) +// { +// sleep ( 1 ); +// if ( GlobalConfig->KvpncDebugLevel > 8 ) +// GlobalConfig->appendLogEntry ( i18n ( "\"%1\" is still running waiting for terminate..." ).arg ( "pptp" ) , GlobalConfig->debug ); +// GlobalConfig->appPointer->processEvents(); +// } +// +// } + + //why it crash here? + //delete PptpProcess; + //PptpProcess=0L; + + durationTimer.stop(); + + // write pppd..down + QFile downfile ( tmpPath + "pppd." + GlobalConfig->currentProfile->getName() + ".down" ); + QTextStream downstream ( &downfile ); + if ( downfile.open ( IO_WriteOnly ) ) + { + downstream << "#!"<< GlobalConfig->InterpreterShell << "\n"; + downstream << "# generated by kvpnc. Do not edit it." << "\n"; + downstream << "# profile: " + GlobalConfig->currentProfile->getName() << "\n\n"; + + /* update dns? */ + if ( GlobalConfig->currentProfile->getUseDnsUpdate() ) + { + // downstream << "chmod u+w /etc/resolv.conf\n"; + downstream << "if [ -x /sbin/resolvconf ] ; then\n"; + downstream << " dev=$1\n"; + downstream << " if [ -z $dev ] ; then\n"; + downstream << " dev=\"ppp0\"\n"; + downstream << " fi\n"; + downstream << " /sbin/resolvconf -d $dev\n"; + + downstream << " nameserver=\"$(cat /etc/resolv.conf | grep nameserver | head -n1 | sed -e 's/nameserver //')\"\n"; + downstream << " if [ -z $nameserver ] ; then\n"; + downstream << " nameserver=\"$(cat " << tmpPath + "resolv.conf." + GlobalConfig->currentProfile->getName() << " | grep nameserver | head -n1 | sed -e 's/nameserver //')\"\n"; + downstream << " fi" << "\n"; + + downstream << "else" << "\n"; + downstream << " cat " << tmpPath + "resolv.conf." + GlobalConfig->currentProfile->getName() << " > /etc/resolv.conf\n"; + downstream << "fi" << "\n"; + } + else + { + /* dont update dns */ + } + + if ( GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + { + // downstream << GlobalConfig->pathToIp + " route del " + GlobalConfig->currentProfile->getGateway() + "/32 via " << GlobalConfig->OldDefaultGw << " dev " << GlobalConfig->OldDefaultDev << "\n"; + downstream << GlobalConfig->pathToRoute << " del default" << "\n"; + if ( ! pppdHasReplacedefaultrouteSupport ) + { + downstream << GlobalConfig->pathToIp << " route add $(cat " << OldDefaultroute << ")" << "\n"; + } + + + // if ( GlobalConfig->NewDefaultGw != "0.0.0.0" ) + // { + // QString pppdev = ""; + // if ( !PppdDevice.isEmpty() ) + // pppdev = PppdDevice; + // else + // pppdev = "ppp0"; + // + // if ( GlobalConfig->KvpncDebugLevel > 3 ) + // GlobalConfig->appendLogEntry ( i18n ( "Removing extra route: %1 over %2 gw %3" ).arg ( "0.0.0.0" ).arg ( GlobalConfig->NewDefaultGw ).arg ( pppdev ), GlobalConfig->debug ); + // downstream << GlobalConfig->pathToIp + " route del 0.0.0.0 via " << GlobalConfig->NewDefaultGw << " dev " << pppdev << "\n"; + // } + + } + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Removing extra route: %1 over %2 gw %3" ).arg ( GlobalConfig->currentProfile->getGateway() ).arg ( GlobalConfig->OldDefaultDev ).arg ( GlobalConfig->OldDefaultGw ), GlobalConfig->debug ); + + downstream << GlobalConfig->pathToIp + " route del " + GlobalConfig->currentProfile->getGateway() + "/32 via " << GlobalConfig->OldDefaultGw << " dev " << GlobalConfig->OldDefaultDev << "\n"; + + downfile.close(); + + QProcess *pppdDownProcess = new QProcess ( this ); + pppdDownProcess->addArgument ( GlobalConfig->InterpreterShell ); + pppdDownProcess->addArgument ( tmpPath + "pppd." + GlobalConfig->currentProfile->getName() + ".down" ); + + if ( !pppdDownProcess->start ( env ) ) + { + KMessageBox::sorry ( this, i18n ( "\"%1\" start failed!" ).arg ( "PppdDownScript" ) ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( "PppdDownScript" ) , GlobalConfig->debug ); + while ( pppdDownProcess->isRunning() ) + parent->QApplication::processEvents(); + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" (%2) finished." ).arg ( "PppdDownScript" ).arg ( tmpPath + "pppd." + GlobalConfig->currentProfile->getName() + ".down" ), GlobalConfig->debug ); + + if ( ! pppdHasReplacedefaultrouteSupport && GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Default route was restored." ), GlobalConfig->debug ); + + if ( GlobalConfig->currentProfile->getUseDnsUpdate() && Utils ( GlobalConfig ).resolvConfAvailable() ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "resolvconf restored the old /etc/resolv.conf." ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->currentProfile->getUseDnsUpdate() ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "/etc/resolv.conf was restored." ), GlobalConfig->debug ); + } + } + } + delete pppdDownProcess; + pppdDownProcess=0L; + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" could not written." ).arg ( i18n ( "pppd down file" ) ) , GlobalConfig->error ); + } + + if ( GlobalConfig->currentProfile->getAuthMethod() == "chap" || GlobalConfig->currentProfile->getAuthMethod() == "mschap" || GlobalConfig->currentProfile->getAuthMethod() == "mschap-v2" ) + { + // remove kvpnc entries from chap-secerets + QFile ChapSecretsFile ( "/etc/ppp/chap-secrets" ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "pppd secrets file: %1" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + QTextStream stream ( &ChapSecretsFile ); + if ( ChapSecretsFile.open ( IO_ReadOnly ) ) + { + QString line = ""; + QString chapsecret_content = ""; + bool kvpnc_start_marker_found = false; + bool kvpnc_end_marker_found = false; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' + if ( line == "# --- generated by kvpnc. Do not edit it." ) + { + kvpnc_end_marker_found = true; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "End marker in %1 found" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + } + if ( line == "# +++ generated by kvpnc. Do not edit it." ) + { + kvpnc_start_marker_found = true; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Start marker in %1 found" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + } + + if ( kvpnc_start_marker_found == false ) + { + chapsecret_content += line; + chapsecret_content += '\n'; + } + } + ChapSecretsFile.close(); + if ( ChapSecretsFile.remove() ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 successfully removed" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + // ChapSecretsFile.setName("/etc/ppp/chap-secrets2"); + if ( ChapSecretsFile.open ( IO_WriteOnly ) ) + { + stream.setDevice ( &ChapSecretsFile ); + stream << chapsecret_content; + ChapSecretsFile.close(); + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 sucessfully rewritten" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 rewrite failed" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->error ); + } + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 remove failed" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->error ); + } + + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "File %1 could not opened!" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->error ); + } + } + if ( GlobalConfig->currentProfile->getAuthMethod() == "pap" ) + { + // remove kvpnc entries from pap-secerets + QFile papSecretsFile ( "/etc/ppp/pap-secrets" ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "pppd secrets file: %1" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + QTextStream stream ( &papSecretsFile ); + if ( papSecretsFile.open ( IO_ReadOnly ) ) + { + QString line = ""; + QString papsecret_content = ""; + bool kvpnc_start_marker_found = false; + bool kvpnc_end_marker_found = false; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' + if ( line == "# --- generated by kvpnc. Do not edit it." ) + { + kvpnc_end_marker_found = true; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "End marker in %1 found" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + } + if ( line == "# +++ generated by kvpnc. Do not edit it." ) + { + kvpnc_start_marker_found = true; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Start marker in %1 found" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + } + + if ( kvpnc_start_marker_found == false ) + { + papsecret_content += line; + papsecret_content += '\n'; + } + } + papSecretsFile.close(); + if ( papSecretsFile.remove() ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 successfully removed" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + // papSecretsFile.setName("/etc/ppp/pap-secrets2"); + if ( papSecretsFile.open ( IO_WriteOnly ) ) + { + stream.setDevice ( &papSecretsFile ); + stream << papsecret_content; + papSecretsFile.close(); + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 sucessfully rewritten" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 rewrite failed" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->error ); + } + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 remove failed" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->error ); + } + + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "File %1 could not opened!" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->error ); + } + } + setGuiStatus ( disconnected ); + GlobalConfig->status = GlobalConfig->disconnected; + connectCounter = 0; + disconnect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + // connectionEnded(); + } + } + // openvpn + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::openvpn ) + { + + // if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::openvpn && GlobalConfig->currentProfile->getUseSmartcard() || GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) + { + // delete managementhandler; + } + disconnect ( OpenvpnProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readOutput_openvpn() ) ); + //disconnect( OpenvpnProcess, SIGNAL( readyReadStderr() ), this, SLOT( readOutput_openvpn() ) ); + //disconnect ( OpenvpnProcess, SIGNAL ( processExited() ), this, SLOT ( openvpn_exited() ) ); + + if ( managementhandler ) + { + disconnect ( managementhandler, SIGNAL ( terminate_openvpn() ), this, SLOT ( disconnectClicked() ) ); + managementhandler->greetingtimer.stop(); + managementhandler->closeConnection(); + while( ! managementhandler->socketReallyClosed ) + { + if (GlobalConfig->appPointer->hasPendingEvents()) + GlobalConfig->appPointer->processEvents(); + usleep(500); + } + delete managementhandler; + } + + if ( OpenvpnProcess != 0L && OpenvpnProcess->isRunning() ) + { + //OpenvpnProcess->tryTerminate(); + //QTimer::singleShot ( 2000, OpenvpnProcess, SLOT ( kill() ) ); + OpenvpnProcess->kill(); + } + + //sleep ( 2 ); + disconnect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + connectionEnded(); + + + } + // vtun + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::vtun ) + { + + if ( VtundProcess != 0 ) + { + VtundProcess->tryTerminate(); + QTimer::singleShot ( 2000, VtundProcess, SLOT ( kill() ) ); + } + + // terminateConnection( VtundProcess ); + // VtundProcess = new QProcess (); + // VtundProcess->addArgument( GlobalConfig->pathToKillall ); + // VtundProcess->addArgument( "vtund" ); + // + // connect( VtundProcess, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdout_disconnect() ) ); + // connect( VtundProcess, SIGNAL( readyReadStderr() ), this, SLOT( readFromStderr_disconnect() ) ); + // + // if ( !DisconnectProcess->start(env) ) { + // KMessageBox::sorry( this, i18n( "\"%1\" start failed!" ).arg( "killall vtund" ) ); +// else +// { +// sleep(1); +// } +// delete VtundProcess; +// VtundProcess=0L; + // } + disconnect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + + sleep ( 2 ); + delete VtundProcess; + VtundProcess=0L; + connectionEnded(); + + } + // ssh + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ssh ) + { + + if ( SshProcess != 0 ) + { +// SshProcess->tryTerminate(); +// QTimer::singleShot ( 5000, SshProcess, SLOT ( kill() ) ); + SshProcess->kill(); + } + + // terminateConnection( SshProcess ); + // SshProcess = new QProcess (); + // SshProcess->addArgument( GlobalConfig->pathToKillall ); + // SshProcess->addArgument( "openvpn" ); + // + // connect( SshProcess, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdout_disconnect() ) ); + // connect( SshProcess, SIGNAL( readyReadStderr() ), this, SLOT( readFromStderr_disconnect() ) ); + // + // if ( !DisconnectProcess->start(env) ) { + // KMessageBox::sorry( this, i18n( "\"%1\" start failed!" ).arg( "killall ssh" ) ); + // } + else + { + sleep ( 1 ); + } + delete SshProcess; + SshProcess=0L; + + // write ssh..down + QFile downfile ( tmpPath + "ssh." + GlobalConfig->currentProfile->getName() + ".down" ); + QTextStream downstream ( &downfile ); + if ( downfile.open ( IO_WriteOnly ) ) + { + downstream << "#!"<< GlobalConfig->InterpreterShell << "\n"; + downstream << "# generated by kvpnc. Do not edit it." << "\n"; + downstream << "# profile: " + GlobalConfig->currentProfile->getName() << "\n\n"; + + /* update dns? */ + if ( GlobalConfig->currentProfile->getUseDnsUpdate() == true ) + { + downstream << "# profile: " + GlobalConfig->currentProfile->getName() << "\n\n"; + // downstream << "chmod u+w /etc/resolv.conf\n"; + downstream << "if [ -x /sbin/resolvconf ] ; then\n"; + downstream << " dev=$1\n"; + downstream << " if [ -z $dev ] ; then\n"; + if ( GlobalConfig->currentProfile->getTunnelDeviceType() == "tun" ) + downstream << " dev=\"tun0\"\n"; + else + downstream << " dev=\"tap0\"\n"; + downstream << " fi\n"; + downstream << " /sbin/resolvconf -d $dev\n"; + downstream << "else" << "\n"; + downstream << " cat " << tmpPath + "resolv.conf." + GlobalConfig->currentProfile->getName() << " > /etc/resolv.conf\n"; + downstream << "fi" << "\n"; + } + else + { + /* dont update dns */ + } + + if ( GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + { + downstream << GlobalConfig->pathToIp + " route del " + GlobalConfig->currentProfile->getGateway() + "/32 via " << GlobalConfig->OldDefaultGw << " dev " << GlobalConfig->OldDefaultDev << "\n"; + downstream << GlobalConfig->pathToIp << " route add $(cat " << OldDefaultroute << ")" << "\n"; + + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Removing extra route: %1 over %2 gw %3" ).arg ( GlobalConfig->currentProfile->getGateway() ).arg ( GlobalConfig->OldDefaultDev ).arg ( GlobalConfig->OldDefaultGw ), GlobalConfig->debug ); + + downstream << GlobalConfig->pathToIp + " route del " + GlobalConfig->currentProfile->getGateway() + "/32 via " << GlobalConfig->OldDefaultGw << " dev " << GlobalConfig->OldDefaultDev << "\n"; + + } + +// if ( GlobalConfig->NewDefaultGw != "0.0.0.0" ) +// { +// SshDevice = ""; +// // if ( !PppDevice.isEmpty() ) +// // sshev = PppDevice; +// // else +// if ( GlobalConfig->currentProfile->getTunnelDeviceType() == "tun" ) +// SshDevice = "tun0"; +// else +// SshDevice ="tap0"; +// +// if ( GlobalConfig->KvpncDebugLevel > 3 ) +// GlobalConfig->appendLogEntry ( i18n ( "Removing extra route: %1 over %2 gw %3" ).arg ( "0.0.0.0" ).arg ( GlobalConfig->NewDefaultGw ).arg ( SshDevice ), GlobalConfig->debug ); +// downstream << GlobalConfig->pathToIp + " route del 0.0.0.0 via " << GlobalConfig->NewDefaultGw << " dev " << SshDevice << "\n"; +// } + + downfile.close(); + + QProcess *SshDownProcess = new QProcess ( this ); + SshDownProcess->addArgument ( GlobalConfig->InterpreterShell ); + SshDownProcess->addArgument ( tmpPath + "ssh." + GlobalConfig->currentProfile->getName() + ".down" ); + + if ( !SshDownProcess->start ( env ) ) + { + KMessageBox::sorry ( this, i18n ( "\"%1\" start failed!" ).arg ( "SshDownScript" ) ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( "SshDownScript" ) , GlobalConfig->debug ); + while ( SshDownProcess->isRunning() ) + parent->QApplication::processEvents(); + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" (%2) finished." ).arg ( "SshDownScript" ).arg ( tmpPath + "ssh." + GlobalConfig->currentProfile->getName() + ".down" ), GlobalConfig->debug ); + + if ( GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Default route was restored." ), GlobalConfig->debug ); + + if ( GlobalConfig->currentProfile->getUseDnsUpdate() && Utils ( GlobalConfig ).resolvConfAvailable() ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "resolvconf restored the old /etc/resolv.conf." ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->currentProfile->getUseDnsUpdate() ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "/etc/resolv.conf was restored." ), GlobalConfig->debug ); + } + } + } + delete SshDownProcess; + SshDownProcess=0L; + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" could not written." ).arg ( i18n ( "ssh down file" ) ) , GlobalConfig->error ); + + } + + + disconnect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + connectionEnded(); + } + } + // ConnectingProcess = 0L; + + setGuiStatus ( disconnected ); + + if ( GlobalConfig->currentProfile->getExecuteCmdAfterDisconnect() ) + executeCommandAfterDisconnect(); + + } + else if ( GlobalConfig->status == GlobalConfig->connecting ) + { + prevConnectionState = connecting; + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Disconnect requested, status connecting" ), GlobalConfig->debug ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Killing process while connecting.\n" ), GlobalConfig->debug ); + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::cisco ) + { + if ( VpncProcess != 0 ) + { + + tmpPath = locateLocal ( "data", "kvpnc/" ); + //Vpnc_pid_file = tmpPath + "vpnc-pid." + GlobalConfig->currentProfile->getID() + ".pid"; // vpnc-pid..pid + VpncDisconnectScript = tmpPath + "vpnc-disconnect." + GlobalConfig->currentProfile->getID() + ".sh"; + // write vpnc connect script + QFile pidFile ( GlobalConfig->Vpnc_pid_file ); + QString Vpnc_pid = ""; + if ( pidFile.open ( IO_ReadOnly ) ) + { + Vpnc_pid = QString ( pidFile.readAll() ).stripWhiteSpace(); + } + + if ( VpncProcess != 0 ) + { + if ( VpncProcess->isRunning() ) + { + disconnect ( VpncProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readOutputFrom_vpnc() ) ); + disconnect ( VpncProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readOutputFrom_vpnc() ) ); + disconnect ( &timer, SIGNAL ( timeout() ), this, SLOT ( slotConnectTimedOut() ) ); + + VpncProcess->kill(); + sleep ( 1 ); + if ( VpncProcess->isRunning() ) + VpncProcess->kill(); + sleep ( 1 ); + if ( VpncProcess->isRunning() ) + VpncProcess->kill(); + sleep ( 1 ); + if ( VpncProcess->isRunning() ) + VpncProcess->kill(); + } + delete VpncProcess; + VpncProcess = 0L; + } + + QFile file ( VpncDisconnectScript ); + QTextStream stream ( &file ); + if ( file.open ( IO_WriteOnly ) ) + { + stream << "#!"<< GlobalConfig->InterpreterShell << "\n"; + stream << "# generated by kvpnc. Do not edit it." << "\n"; + stream << "# profile: " + GlobalConfig->currentProfile->getName() << "\n"; + stream << "\n"; + + if ( !Vpnc_pid.isEmpty() ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Vpnc pid file found, killing process %1" ).arg ( Vpnc_pid ) , GlobalConfig->debug ); + stream << GlobalConfig->pathToKill << " -TERM " << Vpnc_pid << " > /dev/null 2>&1\n"; + stream << GlobalConfig->pathToKill << " -TERM " << Vpnc_pid << " > /dev/null 2>&1\n"; + stream << GlobalConfig->pathToKill << " -KILL " << Vpnc_pid << " > /dev/null 2>&1\n"; + stream << GlobalConfig->pathToKill << " -KILL " << Vpnc_pid << " > /dev/null 2>&1\n"; + stream << GlobalConfig->pathToKill << " -KILL " << Vpnc_pid << " > /dev/null 2>&1\n"; + QFile ( GlobalConfig->Vpnc_pid_file ).remove(); + } +// else +// { +// if ( GlobalConfig->KvpncDebugLevel > 0 ) +// GlobalConfig->appendLogEntry ( i18n ( "No vpnc pid file found, using \"killall\" for killing vpnc." ), GlobalConfig->debug ); +// stream << GlobalConfig->pathToKillall << " -TERM vpnc" << " > /dev/null 2>&1\n"; +// stream << GlobalConfig->pathToKillall << " -TERM vpnc" << " > /dev/null 2>&1\n"; +// stream << GlobalConfig->pathToKillall << " -KILL vpnc" << " > /dev/null 2>&1\n"; +// stream << GlobalConfig->pathToKillall << " -KILL vpnc" << " > /dev/null 2>&1\n"; +// stream << GlobalConfig->pathToKillall << " -KILL vpnc" << " > /dev/null 2>&1\n"; +// } + + if ( GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Restoring default route before connection..." ), GlobalConfig->debug ); + + QString OldDefaultroute = tmpPath + "default-route." + GlobalConfig->currentProfile->getName(); // default-route. + stream << GlobalConfig->pathToIp + " route del default > /dev/null 2>&1\n"; + stream << GlobalConfig->pathToIp + " route add $(cat \"" + OldDefaultroute + "\")\n"; + // stream << GlobalConfig->pathToIp + " route add $(cat \"/var/run/vpnc/defaultroute\")\n"; + } + // stream << GlobalConfig->pathToIp+" route del $(cat \"" + VpncGateway + "\")\n"; + + // fix broken vpnc: remove route of vpngatewayAddNetworkRouteDialog + stream << GlobalConfig->pathToRoute << " del " + GlobalConfig->TmpGatewayIP << "\n"; + + if ( GlobalConfig->currentProfile->getUseDnsUpdate() ) + { + // FIXME this is a temporary fix for not calling vpnc script with disconnect at disconnect time! + if (VpncDevice.isEmpty()) + VpncDevice = "tun0"; + stream << " if [ -f /sbin/resolvconf ] ; then\n"; + stream << " /sbin/resolvconf -d \"" << VpncDevice << "\"\n"; + stream << " else\n"; + stream << " cat " + tmpPath + "resolv.conf.before.kvpnc_" + GlobalConfig->currentProfile->getName() + " > /etc/resolv.conf\n"; + stream << " fi\n"; + // end temp fix + } + else + { + /* dont update dns */ + } + + //if (!restoreResolvConf()) + //GlobalConfig->appendLogEntry(i18n("Restore of %1 has been failed!").arg(""),GlobalConfig->error); + + stream << GlobalConfig->pathToIp + " route flush cache\n"; + + file.close(); + + DisconnectProcess = new QProcess (); + DisconnectProcess->addArgument ( GlobalConfig->InterpreterShell ); + DisconnectProcess->addArgument ( VpncDisconnectScript ); + + connect ( DisconnectProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_disconnect() ) ); + connect ( DisconnectProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_disconnect() ) ); + + if ( !DisconnectProcess->start ( env ) ) + { + KMessageBox::sorry ( this, i18n ( "\"%1\" start failed!" ).arg ( "vpnc_disconnect" ) ); + } + else + { + sleep ( 1 ); + } + delete DisconnectProcess; + DisconnectProcess=0L; + } + + disconnect ( &timer, SIGNAL ( timeout() ), this, SLOT ( slotConnectTimedOut() ) ); + + + + setGuiStatus ( disconnected ); + disconnect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + timer.stop(); + connectionEnded(); + } + + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ciscoorig ) + { + if ( CiscoVpncProcess != 0 ) + { + CiscoVpncProcess->kill(); + CiscoVpncProcess->tryTerminate(); + QTimer::singleShot ( 5000, CiscoVpncProcess, SLOT ( kill() ) ); + + sleep ( 5 ); + delete CiscoVpncProcess; + CiscoVpncProcess=0L; + } + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan || GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { + // iptables need the right interface (eth0:1 => eth0) + QString tmpInterface2 = ""; + int pointPos = tmpInterface.find ( ':', 0, FALSE ); + if ( pointPos > 1 ) + { + tmpInterface2 = tmpInterface.left ( pointPos ); + } + else + tmpInterface2 = tmpInterface; + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { +// if (QFile("/var/run/l2tpd.pid").exists()) +// { +// if (GlobalConfig->KvpncDebugLevel > 1) +// GlobalConfig->appendLogEntry(i18n("Using control interface for disconnecting l2tp connection"),GlobalConfig->debug); +// QFile L2tpdControlFile ( "/var/run/l2tp-control" ); +// QTextStream stream( &L2tpdControlFile ); +// if ( L2tpdControlFile.open( IO_WriteOnly ) ) { +// stream << "d " << GlobalConfig->currentProfile->getName() << "\n"; +// L2tpdControlFile.close(); +// } +// } +// else + { + if ( GlobalConfig->currentProfile->getL2tpDaemon() == VpnAccountData::l2tpd ) + { + if ( L2tpdProcess != 0L ) + { + L2tpWaitForPppUpTimer.stop(); + disconnect ( this, SIGNAL ( L2tpdStdoutRecieved() ), this, SLOT ( processStdout_l2tpd() ) ); + disconnect ( this, SIGNAL ( L2tpdStderrRecieved() ), this, SLOT ( processStderr_l2tpd() ) ); + + if ( L2tpdProcess->isRunning() ) + { + L2tpdProcess->kill(); + if ( L2tpdProcess != 0L && L2tpdProcess->isRunning() ) + L2tpdProcess->tryTerminate(); + sleep ( 1 ); + if ( L2tpdProcess != NULL && L2tpdProcess->isRunning() ) + L2tpdProcess->kill(); + } + } + } + if ( GlobalConfig->currentProfile->getL2tpDaemon() == VpnAccountData::openl2tp ) + { + if ( OpenL2tpProcess != 0L ) + { + + disconnect ( OpenL2tpProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_openl2tp() ) ); + disconnect ( OpenL2tpProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_openl2tp() ) ); + + OpenL2tpProcess->kill(); + delete OpenL2tpProcess; + OpenL2tpProcess=0L; + if ( QFile ( "/var/run/openl2tpd.pid" ).exists() ) + QFile ( "/var/run/openl2tpd.pid" ).remove(); + + if ( !Utils ( GlobalConfig, parent ).unloadKernelModule ( "slhc", parent ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" failed" ).arg ( "slhc" ).arg ( "/etc/modprobe.conf" ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" succeded" ).arg ( "slhc" ), GlobalConfig->debug ); + } + if ( !Utils ( GlobalConfig, parent ).unloadKernelModule ( "ppp_generic", parent ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" failed." ).arg ( "ppp_generic" ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" succeded" ).arg ( "ppp_generic" ), GlobalConfig->debug ); + } + if ( !Utils ( GlobalConfig, parent ).unloadKernelModule ( "pppox", parent ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" failed." ).arg ( "pppox" ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" succeded" ).arg ( "pppox" ), GlobalConfig->debug ); + } + if ( !Utils ( GlobalConfig, parent ).unloadKernelModule ( "pppol2tp", parent ,true ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" failed" ).arg ( "pppol2tp" ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" succeded" ).arg ( "pppol2tp" ), GlobalConfig->debug ); + } + + startStopOpenl2tp ( true ); + sleep ( 2 ); + startStopOpenl2tp(); + } + } + } + } + + timer.stop(); + IpsecWhackStatusTimer.stop(); + + if (GlobalConfig->currentProfile->getUseLeftSourceIp()) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Removing virtual IP address" ), GlobalConfig->debug ); + doAddRemoveVirtualIp("del"); + } + + ToolInfo *tool = Utils ( GlobalConfig ).getToolInfo ( "ipsec" ); + QString realversion = tool->Version.section ( ' ', 1, 1 ).section ( '/', 0, 0 ).right ( tool->Version.section ( ' ', 1, 1 ).section ( '/', 0, 0 ).length() - 1 ); + int IpsecMajor= realversion.section ( '.',0,0 ).toInt(); + int IpsecMinor= realversion.section ( '.',1,1 ).toInt(); + int IpsecSubMinor= realversion.section ( '.',2,2 ).toInt(); + QString realtype = tool->Version.section ( ' ', 0, 0 ).lower(); + + putenv ( ( char* ) ( "LC_ALL=C" ) ); + IpsecWhackDeleteProcess = new QProcess ( this ); + IpsecWhackDeleteProcess->addArgument ( GlobalConfig->pathToIpsec ); + IpsecWhackDeleteProcess->addArgument ( "whack" ); + IpsecWhackDeleteProcess->addArgument ( "--name" ); + IpsecWhackDeleteProcess->addArgument ( GlobalConfig->currentProfile->getName() ); + IpsecWhackDeleteProcess->addArgument ( "--delete" ); + + connect ( IpsecWhackDeleteProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_ipsecwhackdelete() ) ); + connect ( IpsecWhackDeleteProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsecwhackdelete() ) ); + + if ( !IpsecWhackDeleteProcess->start ( env ) ) + { + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( GlobalConfig->pathToIpsec+" whack' --name "+GlobalConfig->currentProfile->getName() +" --delete" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( GlobalConfig->pathToIpsec+" whack' --name "+GlobalConfig->currentProfile->getName() +" --delete" ) , GlobalConfig->error ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( GlobalConfig->pathToIpsec+" whack --name "+GlobalConfig->currentProfile->getName() +" --delete" ), GlobalConfig->debug ); + + int tryCounter=0; + while ( IpsecWhackDeleteProcess !=0 && IpsecWhackDeleteProcess->isRunning() ) + { + tryCounter++; + if ( tryCounter ==20 ) + { + tryCounter=0; + if ( GlobalConfig->KvpncDebugLevel > 8 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" is still running waiting for terminate..." ).arg ( GlobalConfig->pathToIpsec+" whack --name "+GlobalConfig->currentProfile->getName() +" --delete" ), GlobalConfig->debug ); + } + usleep ( 500 ); + } + } + delete IpsecWhackDeleteProcess; + IpsecWhackDeleteProcess=0L; + + IpsecStartProcess = new QProcess ( this ); + IpsecStartProcess->addArgument ( GlobalConfig->pathToIpsec ); + if ( !IpsecType.contains ( "strongSwan", false ) ) + { + IpsecStartProcess->addArgument ( "setup" ); + IpsecStartProcess->addArgument ( "stop" ); + } + if ( ! IpsecType.contains ( "free", false ) && ( ( IpsecMajor = 4 && IpsecMinor >= 2 && IpsecSubMinor >= 2 ) || IpsecMajor > 4 ) ) + { + IpsecStartProcess->addArgument ( "stop" ); + } + + connect ( IpsecStartProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStderr_ipsec() ) ); + connect ( IpsecStartProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsec() ) ); + // connect( IpsecStartProcess, SIGNAL( processExited () ), this, SLOT( removeRouteFreeswan() ) ); + + if ( !IpsecStartProcess->start ( env ) ) + { + if ( !IpsecType.contains ( "strongSwan", false ) ) + { + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( "ipsec setup stop" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "ipsec setup stop" ) , GlobalConfig->error ); + } + if ( ! IpsecType.contains ( "free", false ) && ( ( IpsecMajor = 4 && IpsecMinor >= 2 && IpsecSubMinor >= 2 ) || IpsecMajor > 4 ) ) + { + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( "ipsec stop" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "ipsec stop" ) , GlobalConfig->error ); + } + } + else + { + int tryCounter=0; + while ( IpsecStartProcess !=0 && IpsecStartProcess->isRunning() ) + { + tryCounter++; + if ( tryCounter ==20 ) + { + tryCounter=0; + if ( GlobalConfig->KvpncDebugLevel > 8 ) + { + if ( !IpsecType.contains ( "strongSwan", false ) ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" is still running waiting for terminate..." ).arg ( "ipsec setup stop" ), GlobalConfig->debug ); + if ( IpsecType.contains ( "strongSwan", false ) && ( ( IpsecMajor >= 4 && IpsecMinor >= 2 && IpsecSubMinor >=2 ) || IpsecMajor > 4 ) ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" is still running waiting for terminate..." ).arg ( "ipsec stop" ), GlobalConfig->debug ); + } + } + usleep ( 500 ); + } + } + disconnect ( IpsecStartProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStderr_ipsec() ) ); + disconnect ( IpsecStartProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsec() ) ); + delete IpsecStartProcess; + IpsecStartProcess=0L; + +// delRouteIpsec(); + removeIptablesFreeswan(); + setGuiStatus ( disconnected ); + + GlobalConfig->currentConnectRetry=0; + + connectionEnded(); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Restoring original ipsec settings" ), KVpncConfig::debug ); + // restore system files + QString IpsecPrefix = "/etc"; + // ipsec.conf + QFile originalIpsecConfFile ( "/etc/ipsec.conf.before.kvpnc" ); + QTextStream stream ( &originalIpsecConfFile ); + QString originalIpsecConfFileContent = ""; + + if ( originalIpsecConfFile.exists() ) + { + if ( originalIpsecConfFile.open ( IO_ReadOnly ) ) + { + originalIpsecConfFileContent = QString ( originalIpsecConfFile.readAll() ); + originalIpsecConfFile.close(); + } + } + + QFile backupOriginalIpsecConfFile ( "/etc/ipsec.conf" ); + stream.setDevice ( &backupOriginalIpsecConfFile ); + if ( backupOriginalIpsecConfFile.open ( IO_WriteOnly ) ) + { + stream << originalIpsecConfFileContent; + backupOriginalIpsecConfFile.close(); + } + stream.unsetDevice(); + + //if ( GlobalConfig->KvpncDebugLevel > 0 ) + // GlobalConfig->appendLogEntry( i18n( "%1 found in %2, assuming %3 as prefix for %4." ).arg( "ipsec.conf.before.kvpnc" ).arg( IpsecPrefix ).arg( IpsecPrefix ).arg( IpsecType ), GlobalConfig->debug ); + + // ipsec.secret + QFile originalIpsecSecretFile ( "/etc/ipsec.secrets.before.kvpnc" ); + stream.setDevice ( &originalIpsecSecretFile ); + QString originalIpsecSecretFileContent = ""; + if ( originalIpsecSecretFile.open ( IO_ReadOnly ) ) + { + originalIpsecSecretFileContent = QString ( originalIpsecSecretFile.readAll() ); + originalIpsecSecretFile.close(); + } + + QFile backupOriginalIpsecSecretFile ( "/etc/ipsec.secrets" ); + stream.setDevice ( &backupOriginalIpsecSecretFile ); + if ( backupOriginalIpsecSecretFile.open ( IO_WriteOnly ) ) + { + stream << originalIpsecSecretFileContent; + backupOriginalIpsecSecretFile.close(); + } + stream.unsetDevice(); + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { + if ( GlobalConfig->currentProfile->getAuthMethod() == "chap" || GlobalConfig->currentProfile->getAuthMethod() == "mschap" || GlobalConfig->currentProfile->getAuthMethod() == "mschap-v2" ) + { + // remove kvpnc entries from chap-secerets + QFile ChapSecretsFile ( "/etc/ppp/chap-secrets" ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "pppd secrets file: %1" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + QTextStream stream ( &ChapSecretsFile ); + if ( ChapSecretsFile.open ( IO_ReadOnly ) ) + { + QString line = ""; + QString chapsecret_content = ""; + bool kvpnc_start_marker_found = false; + bool kvpnc_end_marker_found = false; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' + if ( line == "# --- generated by kvpnc. Do not edit it." ) + { + kvpnc_end_marker_found = true; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "End marker in %1 found" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + } + if ( line == "# +++ generated by kvpnc. Do not edit it." ) + { + kvpnc_start_marker_found = true; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Start marker in %1 found" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + } + + if ( kvpnc_start_marker_found == false ) + { + chapsecret_content += line; + chapsecret_content += '\n'; + } + } + ChapSecretsFile.close(); + if ( ChapSecretsFile.remove() ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 successfully removed" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + // ChapSecretsFile.setName("/etc/ppp/chap-secrets2"); + if ( ChapSecretsFile.open ( IO_WriteOnly ) ) + { + stream.setDevice ( &ChapSecretsFile ); + stream << chapsecret_content; + ChapSecretsFile.close(); + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 sucessfully rewritten" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 rewrite failed" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->error ); + } + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 remove failed" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->error ); + } + + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "File %1 could not opened!" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->error ); + } + } + if ( GlobalConfig->currentProfile->getAuthMethod() == "pap" ) + { + // remove kvpnc entries from pap-secerets + QFile papSecretsFile ( "/etc/ppp/pap-secrets" ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "pppd secrets file: %1" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + QTextStream stream ( &papSecretsFile ); + if ( papSecretsFile.open ( IO_ReadOnly ) ) + { + QString line = ""; + QString papsecret_content = ""; + bool kvpnc_start_marker_found = false; + bool kvpnc_end_marker_found = false; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' + if ( line == "# --- generated by kvpnc. Do not edit it." ) + { + kvpnc_end_marker_found = true; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "End marker in %1 found" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + } + if ( line == "# +++ generated by kvpnc. Do not edit it." ) + { + kvpnc_start_marker_found = true; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Start marker in %1 found" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + } + + if ( kvpnc_start_marker_found == false ) + { + papsecret_content += line; + papsecret_content += '\n'; + } + } + papSecretsFile.close(); + if ( papSecretsFile.remove() ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 successfully removed" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + // papSecretsFile.setName("/etc/ppp/pap-secrets2"); + if ( papSecretsFile.open ( IO_WriteOnly ) ) + { + stream.setDevice ( &papSecretsFile ); + stream << papsecret_content; + papSecretsFile.close(); + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 sucessfully rewritten" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 rewrite failed" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->error ); + } + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 remove failed" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->error ); + } + + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "File %1 could not opened!" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->error ); + } + } + } + + // start ipsec with restored config again +// startStopIpsec(true); + startStopIpsec ( false,false ); + + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon || GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { + + QFile file2 ( tmpPath + "setkey." + GlobalConfig->currentProfile->getName() + ".remove_setkey.sh" ); + QTextStream stream2 ( &file2 ); + if ( file2.open ( IO_WriteOnly ) ) + { + stream2 << "#!"<< GlobalConfig->InterpreterShell << "\n"; + stream2 << "# generated by kvpnc. Do not edit it." << "\n"; + stream2 << "# profile: " + GlobalConfig->currentProfile->getName() << "\n"; + stream2 << GlobalConfig->pathToSetkey << " -PF" << "\n"; + stream2 << GlobalConfig->pathToSetkey << " -F" << "\n"; + file2.close(); + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" write successful." ).arg ( "setkey (remove)" ) , GlobalConfig->debug ); + } + else + { + // KMessageBox::error( this, i18n( "\"%1\" write failed!" ).arg( "setkey (remove)" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" write failed!" ).arg ( "setkey (remove)" ) , GlobalConfig->error ); + } + +// if (RacoonctlProcess !=0 && RacoonctlProcess->isRunning()) +// { +// disconnect( RacoonctlProcess, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdout_racoonctl() ) ); +// disconnect( RacoonctlProcess, SIGNAL( readyReadStderr() ), this, SLOT( readFromStderr_racoonctl() ) ); +// +// RacoonctlProcess->kill(); +// } + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { + //if (QFile("/var/run/l2tpd.pid").exists()) + //{ + // if (GlobalConfig->KvpncDebugLevel > 1) + // GlobalConfig->appendLogEntry(i18n("Using control interface for disconnecting l2tp connection"),GlobalConfig->debug); + // QFile L2tpdControlFile ( "/var/run/l2tp-control" ); + // QTextStream stream( &L2tpdControlFile ); + // if ( L2tpdControlFile.open( IO_WriteOnly ) ) { + // stream << "d " << GlobalConfig->currentProfile->getName() << "\n"; + // L2tpdControlFile.close(); + // } + //} + //else + //{ + // if (QFile("/var/run/l2tpd.pid").exists()) + // { + // if (GlobalConfig->KvpncDebugLevel > 1) + // GlobalConfig->appendLogEntry(i18n("Using control interface for disconnecting l2tp connection"),GlobalConfig->debug); + // QFile L2tpdControlFile ( "/var/run/l2tp-control" ); + // QTextStream stream( &L2tpdControlFile ); + // if ( L2tpdControlFile.open( IO_WriteOnly ) ) { + // stream << "d " << GlobalConfig->currentProfile->getName() << "\n"; + // L2tpdControlFile.close(); + // } + // else + // { + if ( GlobalConfig->currentProfile->getL2tpDaemon() == VpnAccountData::l2tpd ) + { + if ( L2tpdProcess != 0L && L2tpdProcess->isRunning() ) + { + + L2tpWaitForPppUpTimer.stop(); + disconnect ( this, SIGNAL ( L2tpdStdoutRecieved() ), this, SLOT ( processStdout_l2tpd() ) ); + disconnect ( this, SIGNAL ( L2tpdStderrRecieved() ), this, SLOT ( processStderr_l2tpd() ) ); + + L2tpdProcess->kill(); + if ( L2tpdProcess->isRunning() ) + L2tpdProcess->tryTerminate(); + sleep ( 1 ); + if ( L2tpdProcess != 0L && L2tpdProcess->isRunning() ) + L2tpdProcess->kill(); + } + } + if ( GlobalConfig->currentProfile->getL2tpDaemon() == VpnAccountData::openl2tp ) + { + if ( OpenL2tpProcess != 0L && OpenL2tpProcess->isRunning() ) + { + disconnect ( OpenL2tpProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_openl2tp() ) ); + disconnect ( OpenL2tpProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_openl2tp() ) ); + OpenL2tpProcess->tryTerminate(); + sleep ( 1 ); + if ( OpenL2tpProcess->isRunning() ) + OpenL2tpProcess->tryTerminate(); + sleep ( 1 ); + if ( OpenL2tpProcess != 0L && OpenL2tpProcess->isRunning() ) + OpenL2tpProcess->kill(); + delete OpenL2tpProcess; + OpenL2tpProcess=0L; + + if ( QFile ( "/var/run/openl2tpd.pid" ).exists() ) + QFile ( "/var/run/openl2tpd.pid" ).remove(); + } + } + + + if ( !Utils ( GlobalConfig, parent ).unloadKernelModule ( "slhc", parent ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" failed" ).arg ( "slhc" ).arg ( "/etc/modprobe.conf" ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" succeded" ).arg ( "slhc" ), GlobalConfig->debug ); + } + if ( !Utils ( GlobalConfig, parent ).unloadKernelModule ( "ppp_generic", parent ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" failed." ).arg ( "ppp_generic" ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" succeded" ).arg ( "ppp_generic" ), GlobalConfig->debug ); + } + if ( !Utils ( GlobalConfig, parent ).unloadKernelModule ( "pppox", parent ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" failed." ).arg ( "pppox" ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" succeded" ).arg ( "pppox" ), GlobalConfig->debug ); + } + if ( !Utils ( GlobalConfig, parent ).unloadKernelModule ( "pppol2tp", parent ,true ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" failed" ).arg ( "pppol2tp" ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Unloading module \"%1\" succeded" ).arg ( "pppol2tp" ), GlobalConfig->debug ); + } + startStopOpenl2tp ( true ); + sleep ( 2 ); + startStopOpenl2tp(); + + //} + //} + //} + + } + + if ( RacoonTailProcess != 0 && RacoonTailProcess->isRunning() ) + { + disconnect ( RacoonTailProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_tail_racoon() ) ); + disconnect ( RacoonTailProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_tail_racoon() ) ); + // terminateConnection( RacoonTailProcess ); + RacoonTailProcess->kill(); + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Killing \"%1\"..." ).arg ( "racoon tail" ) , GlobalConfig->debug ); + } + + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "%1 tunnel state: %2" ).arg ( "racoon" ).arg ( QString().setNum ( racoon_tunnel_state ) ) , GlobalConfig->debug ); + + + if ( racoon_tunnel_state==1 ) + { + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon && GlobalConfig->currentProfile->getUseLeftSourceIp()) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Removing virtual IP address" ), GlobalConfig->debug ); + doAddRemoveVirtualIp("del"); + } + stopRacoon(); + } + else + { + if ( RacoonctlProcess != 0L ) + { + if ( RacoonctlProcess->isRunning() ) + RacoonctlProcess->kill(); + } + } + + if ( RacoonProcess != 0 && RacoonProcess->isRunning() ) + { + disconnect ( RacoonProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_racoon() ) ); + disconnect ( RacoonProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_racoon() ) ); + + // terminateConnection( RacoonProcess ); + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Killing \"%1\"..." ).arg ( "racoon" ) , GlobalConfig->debug ); + RacoonProcess->kill(); + } + +// delete RacoonProcess; +// RacoonProcess =0L; + + removeSetkey(); + delRouteRacoon(); + removeIptablesRacoon(); + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon && ( GlobalConfig->currentProfile->getL2tpDaemon() == "l2tpd" || GlobalConfig->currentProfile->getL2tpDaemon() == "l2tpd" ) ) + { + if ( GlobalConfig->currentProfile->getAuthMethod() == "chap" || GlobalConfig->currentProfile->getAuthMethod() == "mschap" || GlobalConfig->currentProfile->getAuthMethod() == "mschap-v2" ) + { + // remove kvpnc entries from chap-secerets + QFile ChapSecretsFile ( "/etc/ppp/chap-secrets" ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "pppd secrets file: %1" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + QTextStream stream ( &ChapSecretsFile ); + if ( ChapSecretsFile.open ( IO_ReadOnly ) ) + { + QString line = ""; + QString chapsecret_content = ""; + bool kvpnc_start_marker_found = false; + bool kvpnc_end_marker_found = false; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' + if ( line == "# --- generated by kvpnc. Do not edit it." ) + { + kvpnc_end_marker_found = true; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "End marker in %1 found" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + } + if ( line == "# +++ generated by kvpnc. Do not edit it." ) + { + kvpnc_start_marker_found = true; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Start marker in %1 found" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + } + + if ( kvpnc_start_marker_found == false ) + { + chapsecret_content += line; + chapsecret_content += '\n'; + } + } + ChapSecretsFile.close(); + if ( ChapSecretsFile.remove() ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 successfully removed" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + // ChapSecretsFile.setName("/etc/ppp/chap-secrets2"); + if ( ChapSecretsFile.open ( IO_WriteOnly ) ) + { + stream.setDevice ( &ChapSecretsFile ); + stream << chapsecret_content; + ChapSecretsFile.close(); + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 sucessfully rewritten" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 rewrite failed" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->error ); + } + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 remove failed" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->error ); + } + + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "File %1 could not opened!" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->error ); + } + } + if ( GlobalConfig->currentProfile->getAuthMethod() == "pap" ) + { + // remove kvpnc entries from pap-secerets + QFile papSecretsFile ( "/etc/ppp/pap-secrets" ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "pppd secrets file: %1" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + QTextStream stream ( &papSecretsFile ); + if ( papSecretsFile.open ( IO_ReadOnly ) ) + { + QString line = ""; + QString papsecret_content = ""; + bool kvpnc_start_marker_found = false; + bool kvpnc_end_marker_found = false; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' + if ( line == "# --- generated by kvpnc. Do not edit it." ) + { + kvpnc_end_marker_found = true; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "End marker in %1 found" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + } + if ( line == "# +++ generated by kvpnc. Do not edit it." ) + { + kvpnc_start_marker_found = true; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Start marker in %1 found" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + } + + if ( kvpnc_start_marker_found == false ) + { + papsecret_content += line; + papsecret_content += '\n'; + } + } + papSecretsFile.close(); + if ( papSecretsFile.remove() ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 successfully removed" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + // papSecretsFile.setName("/etc/ppp/pap-secrets2"); + if ( papSecretsFile.open ( IO_WriteOnly ) ) + { + stream.setDevice ( &papSecretsFile ); + stream << papsecret_content; + papSecretsFile.close(); + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 sucessfully rewritten" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 rewrite failed" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->error ); + } + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 remove failed" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->error ); + } + + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "File %1 could not opened!" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->error ); + } + } + } + } + else if ( ConnectingProcess == VpnAccountData::pptp ) + { + + if ( PptpProcess != 0 && PptpProcess->isRunning()) + { + disconnect ( PptpProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_pptp() ) ); + disconnect ( PptpProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_pptp() ) ); + + // try to kill the pptp process self + PptpProcess->tryTerminate(); + if ( PptpProcess != 0 && PptpProcess->isRunning()) + PptpProcess->tryTerminate(); + if ( PptpProcess != 0 && PptpProcess->isRunning()) + PptpProcess->tryTerminate(); + if ( PptpProcess != 0 && PptpProcess->isRunning()) + PptpProcess->kill(); + +// if ( PptpProcess != 0 && PptpProcess->isRunning()) +// { +// QProcess *pptpdKillProcess = new QProcess ( this ); +// if ( GlobalConfig->KvpncDebugLevel > 2 ) +// GlobalConfig->appendLogEntry ( i18n ( "No pid file, trying to terminate %1 with killall..." ).arg ( "pptp" ), GlobalConfig->debug ); +// pptpdKillProcess->addArgument ( GlobalConfig->pathToKillall ); +// pptpdKillProcess->addArgument ( "-TERM" ); +// pptpdKillProcess->addArgument ( GlobalConfig->pathToPppd ); +// +// if ( !pptpdKillProcess->start ( env ) ) +// { +// KMessageBox::sorry ( this, i18n ( "\"%1\" start failed!" ).arg ( QString ( GlobalConfig->pathToKillall+" -TERM "+GlobalConfig->pathToPptp ) ) ); +// } +// else +// { +// if ( GlobalConfig->KvpncDebugLevel > 1 ) +// GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( QString ( GlobalConfig->pathToKillall+" -TERM "+GlobalConfig->pathToPptp ) ) , GlobalConfig->debug ); +// while ( pptpdKillProcess->isRunning() ) +// { +// sleep ( 1 ); +// } +// } +// sleep ( 5 ); +// +// pptpdKillProcess->clearArguments(); +// pptpdKillProcess->addArgument ( GlobalConfig->pathToKillall ); +// pptpdKillProcess->addArgument ( "-KILL" ); +// pptpdKillProcess->addArgument ( GlobalConfig->pathToPppd ); +// +// int killcounter=0; +// while ( PptpProcess != 0 && PptpProcess->isRunning() && killcounter < 5 ) +// { +// if ( !pptpdKillProcess->start ( env ) ) +// { +// KMessageBox::sorry ( this, i18n ( "\"%1\" start failed!" ).arg ( QString ( GlobalConfig->pathToKillall+" -KILL "+GlobalConfig->pathToPptp ) ) ); +// } +// else +// { +// if ( GlobalConfig->KvpncDebugLevel > 1 ) +// GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( QString ( GlobalConfig->pathToKillall+" -KILL "+GlobalConfig->pathToPptp ) ) , GlobalConfig->debug ); +// } +// usleep ( 500 ); +// if (GlobalConfig->appPointer->hasPendingEvents()) +// GlobalConfig->appPointer->processEvents(); +// killcounter++; +// if ( GlobalConfig->KvpncDebugLevel > 8 ) +// GlobalConfig->appendLogEntry ( i18n ( "\"%1\" is still running waiting for terminate..." ).arg ( "pptp" ) , GlobalConfig->debug ); +// } +// +// if ( killcounter >= 5 ) +// { +// pptpdKillProcess->clearArguments(); +// pptpdKillProcess->addArgument ( GlobalConfig->pathToKillall ); +// pptpdKillProcess->addArgument ( "-9" ); +// pptpdKillProcess->addArgument ( GlobalConfig->pathToPppd ); +// +// if ( !pptpdKillProcess->start ( env ) ) +// { +// KMessageBox::sorry ( this, i18n ( "\"%1\" start failed!" ).arg ( QString ( GlobalConfig->pathToKillall+" -SIGKILL "+GlobalConfig->pathToPptp ) ) ); +// } +// else +// { +// if ( GlobalConfig->KvpncDebugLevel > 1 ) +// GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( QString ( GlobalConfig->pathToKillall+" -SIGKILL "+GlobalConfig->pathToPptp ) ) , GlobalConfig->debug ); +// while ( pptpdKillProcess->isRunning() ) +// { +// usleep ( 500 ); +// if (GlobalConfig->appPointer->hasPendingEvents()) +// GlobalConfig->appPointer->processEvents(); +// } +// } +// } +// } + + + //delete PptpProcess; + //PptpProcess=0L; + } + + + + // write pppd..down + QFile downfile ( tmpPath + "pppd." + GlobalConfig->currentProfile->getName() + ".down" ); + QTextStream downstream ( &downfile ); + if ( downfile.open ( IO_WriteOnly ) ) + { + downstream << "#!"<< GlobalConfig->InterpreterShell << "\n"; + downstream << "# generated by kvpnc. Do not edit it." << "\n"; + downstream << "# profile: " + GlobalConfig->currentProfile->getName() << "\n\n"; + + /* update dns? */ + if ( GlobalConfig->currentProfile->getUseDnsUpdate() ) + { + // downstream << "chmod u+w /etc/resolv.conf\n"; + downstream << "if [ -x /sbin/resolvconf ] ; then\n"; + downstream << " dev=$1\n"; + downstream << " if [ -z $dev ] ; then\n"; + downstream << " dev=\"ppp0\"\n"; + downstream << " fi\n"; + downstream << " /sbin/resolvconf -d $dev\n"; + downstream << "else" << "\n"; + downstream << " cat " << tmpPath + "resolv.conf." + GlobalConfig->currentProfile->getName() << " > /etc/resolv.conf\n"; + downstream << "fi" << "\n"; + } + else + { + /* dont update dns */ + } + + if ( ! pppdHasReplacedefaultrouteSupport && GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + { + downstream << GlobalConfig->pathToIp << " route add $(cat " << OldDefaultroute << ")" << "\n"; + } + if ( ! pppdHasReplacedefaultrouteSupport && GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + { + downstream << GlobalConfig->pathToIp << " route add $(cat " << OldDefaultroute << ")" << "\n"; + } + downfile.close(); + } + + QProcess *pppdDownProcess = new QProcess ( this ); + pppdDownProcess->addArgument ( GlobalConfig->InterpreterShell ); + pppdDownProcess->addArgument ( tmpPath + "pppd." + GlobalConfig->currentProfile->getName() + ".down" ); + + if ( !pppdDownProcess->start ( env ) ) + { + KMessageBox::sorry ( this, i18n ( "\"%1\" start failed!" ).arg ( "PppdDownScript" ) ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( "PppdDownScript" ).arg ( tmpPath + "pppd." + GlobalConfig->currentProfile->getName() + ".down" ) , GlobalConfig->debug ); + while ( pppdDownProcess->isRunning() ) + { + usleep ( 500 ); + if (GlobalConfig->appPointer->hasPendingEvents()) + GlobalConfig->appPointer->processEvents(); + } + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" (%2) finished." ).arg ( "PppdDownScript" ).arg ( tmpPath + "pppd." + GlobalConfig->currentProfile->getName() + ".down" ), GlobalConfig->debug ); + + if ( ! pppdHasReplacedefaultrouteSupport && GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Default route was restored." ), GlobalConfig->debug ); + + if ( GlobalConfig->currentProfile->getUseDnsUpdate() && Utils ( GlobalConfig ).resolvConfAvailable() ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "resolvconf restored the old /etc/resolv.conf." ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->currentProfile->getUseDnsUpdate() ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "/etc/resolv.conf was restored." ), GlobalConfig->debug ); + } + } + } + + delete pppdDownProcess; + pppdDownProcess=0L; + + if ( GlobalConfig->currentProfile->getAuthMethod() == "chap" || GlobalConfig->currentProfile->getAuthMethod() == "mschap" || GlobalConfig->currentProfile->getAuthMethod() == "mschap-v2" ) + { + // remove kvpnc entries from chap-secerets + QFile ChapSecretsFile ( "/etc/ppp/chap-secrets" ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "pppd secrets file: %1" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + QTextStream stream ( &ChapSecretsFile ); + if ( ChapSecretsFile.open ( IO_ReadOnly ) ) + { + QString line = ""; + QString chapsecret_content = ""; + bool kvpnc_start_marker_found = false; + bool kvpnc_end_marker_found = false; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' + if ( line == "# --- generated by kvpnc. Do not edit it." ) + { + kvpnc_end_marker_found = true; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "End marker in %1 found" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + } + if ( line == "# +++ generated by kvpnc. Do not edit it." ) + { + kvpnc_start_marker_found = true; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Start marker in %1 found" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + } + + if ( kvpnc_start_marker_found == false ) + { + chapsecret_content += line; + chapsecret_content += '\n'; + } + } + ChapSecretsFile.close(); + if ( ChapSecretsFile.remove() ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 successfully removed" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + // ChapSecretsFile.setName("/etc/ppp/chap-secrets2"); + if ( ChapSecretsFile.open ( IO_WriteOnly ) ) + { + stream.setDevice ( &ChapSecretsFile ); + stream << chapsecret_content; + ChapSecretsFile.close(); + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 sucessfully rewritten" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 rewrite failed" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->error ); + } + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 remove failed" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->error ); + } + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "File %1 could not opened!" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->error ); + } + } + if ( GlobalConfig->currentProfile->getAuthMethod() == "pap" ) + { + // remove kvpnc entries from pap-secerets + QFile papSecretsFile ( "/etc/ppp/pap-secrets" ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "pppd secrets file: %1" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + QTextStream stream ( &papSecretsFile ); + if ( papSecretsFile.open ( IO_ReadOnly ) ) + { + QString line = ""; + QString papsecret_content = ""; + bool kvpnc_start_marker_found = false; + bool kvpnc_end_marker_found = false; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' + if ( line == "# --- generated by kvpnc. Do not edit it." ) + { + kvpnc_end_marker_found = true; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "End marker in %1 found" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + } + if ( line == "# +++ generated by kvpnc. Do not edit it." ) + { + kvpnc_start_marker_found = true; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Start marker in %1 found" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + } + + if ( kvpnc_start_marker_found == false ) + { + papsecret_content += line; + papsecret_content += '\n'; + } + } + papSecretsFile.close(); + if ( papSecretsFile.remove() ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 successfully removed" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + // papSecretsFile.setName("/etc/ppp/pap-secrets2"); + if ( papSecretsFile.open ( IO_WriteOnly ) ) + { + stream.setDevice ( &papSecretsFile ); + stream << papsecret_content; + papSecretsFile.close(); + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 sucessfully rewritten" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 rewrite failed" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->error ); + } + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 remove failed" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->error ); + } + + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "File %1 could not opened!" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->error ); + } + } + setGuiStatus ( disconnected ); + GlobalConfig->status = GlobalConfig->disconnected; + connectCounter = 0; + connectionEnded(); + } + else if ( ConnectingProcess == VpnAccountData::openvpn ) + { + if ( managementhandler ) + { + disconnect ( managementhandler, SIGNAL ( terminate_openvpn() ), this, SLOT ( disconnectClicked() ) ); + managementhandler->greetingtimer.stop(); + managementhandler->closeConnection(); + while( ! managementhandler->socketReallyClosed ) + { + if (GlobalConfig->appPointer->hasPendingEvents()) + GlobalConfig->appPointer->processEvents(); + usleep(500); + } + delete managementhandler; + } + + disconnect ( OpenvpnProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readOutput_openvpn() ) ); + //disconnect( OpenvpnProcess, SIGNAL( readyReadStderr() ), this, SLOT( readOutput_openvpn() ) ); + //disconnect ( OpenvpnProcess, SIGNAL ( processExited() ), this, SLOT ( openvpn_exited() ) ); + if ( OpenvpnProcess != 0 && OpenvpnProcess->isRunning() ) + { + //OpenvpnProcess->tryTerminate(); + //QTimer::singleShot ( 2000, OpenvpnProcess, SLOT ( kill() ) ); + OpenvpnProcess->kill(); + } + + //FIXME why the hell it crashes here in qprocess if OpenvpnProcess is killed and all slots are disconnected? + // delete is done at connectClicked + connectionEnded(); + + + } + else if ( ConnectingProcess == VpnAccountData::vtun ) + { + + if ( VtundProcess != 0 ) + { + VtundProcess->tryTerminate(); + QTimer::singleShot ( 2000, VtundProcess, SLOT ( kill() ) ); + } + + // terminateConnection( VtundProcess ); + // VtundProcess = new QProcess (); + // VtundProcess->addArgument( GlobalConfig->pathToKillall ); + // VtundProcess->addArgument( "vtund" ); + // + // connect( VtundProcess, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdout_disconnect() ) ); + // connect( VtundProcess, SIGNAL( readyReadStderr() ), this, SLOT( readFromStderr_disconnect() ) ); + // + // if ( !DisconnectProcess->start(env) ) { + // KMessageBox::sorry( this, i18n( "\"%1\" start failed!" ).arg( "killall vtund" ) ); + // } +// else +// { +// sleep(1); +// } +// delete VtundProcess; +// VtundProcess=0L; + + disconnect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + sleep ( 2 ); + delete VtundProcess; + VtundProcess=0L; + connectionEnded(); + + } + // ssh + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ssh ) + { + + if ( SshProcess != 0 ) + { +// SshProcess->tryTerminate(); +// QTimer::singleShot ( 5000, SshProcess, SLOT ( kill() ) ); + SshProcess->kill(); + } + + // terminateConnection( SshProcess ); + // SshProcess = new QProcess (); + // SshProcess->addArgument( GlobalConfig->pathToKillall ); + // SshProcess->addArgument( "openvpn" ); + // + // connect( SshProcess, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdout_disconnect() ) ); + // connect( SshProcess, SIGNAL( readyReadStderr() ), this, SLOT( readFromStderr_disconnect() ) ); + // + // if ( !DisconnectProcess->start(env) ) { + // KMessageBox::sorry( this, i18n( "\"%1\" start failed!" ).arg( "killall ssh" ) ); + // } + else + { + sleep ( 1 ); + } + delete SshProcess; + SshProcess=0L; + + disconnect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + connectionEnded(); + } + //connectionEnded(); + setGuiStatus ( disconnected ); + ConnectingProcess = -1; + } + else + { + prevConnectionState = disconnected; + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Not connected.\n" ), GlobalConfig->debug ); + setGuiStatus ( disconnected ); + ConnectingProcess = -1; + } + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Disconnected." ), GlobalConfig->debug ); +} + +void KVpnc::helpClicked() +{ + + /* + mw->DebugOutput->append( "getting userID:\n" ); + QString leftid = getX509CertificateID( "/etc/racoon/certs/mykeys_thielecke.pem", true ); // we + mw->DebugOutput->append( "getting issuerID:\n" ); + QString rightid = getX509CertificateID( "/etc/racoon/certs/mykeys_thielecke.pem", false ); // remote + */ + //doPingTest(); + + // QString buggystring= "aaaaa::::bbbb cccc$$$***//////"; + // mw->DebugOutput->append(QString("Buggy string: "+buggystring)); + // buggystring.replace(QRegExp("[*]+"),"_"); + // buggystring.replace(QRegExp("[+] +"),"_"); + // buggystring.replace(QRegExp("[$]+"),"_"); + // buggystring.replace(QRegExp(":+"),"_"); + // buggystring.replace(QRegExp("ᅵ"),"_"); + // buggystring.replace(QRegExp("ᅵ"),"_"); + // buggystring.replace(QRegExp("+"),"_"); + // buggystring.replace(QRegExp("ᅵ"),"_"); + // buggystring.replace(QRegExp("ᅵ"),"_"); + // buggystring.replace(QRegExp("ᅵ"),"_"); + // buggystring.replace(QRegExp("ᅵ"),"_"); + // buggystring.replace(QRegExp("\\+"),"_"); + // buggystring.replace(QRegExp("/+"),"_"); + // buggystring.replace(QRegExp(";+"),"_"); + // buggystring.replace(QRegExp(" "),"_"); + // buggystring.replace(QRegExp("_+"),"_"); + // + // mw->DebugOutput->append(QString("Buggy string fixed: "+buggystring)); + + // HelpDialog d1; + // d1.exec(); + + // slotStatusMsg ( i18n( "Help dialog called." ), ID_FLASH_MSG ); + + // QString host = "www.fdkldghgfdsfjhsjfgdjhsgfds.de"; + // QString ip = Utils( GlobalConfig, parent ).resolveName(host, parent); + // if (ip=="0.0.0.0") + // KMessageBox::error( this, i18n( "Host \"%1\" could not be resolved!" ).arg(host) ); + // else + // mw->DebugOutput->append( QString("first ip of "+host+": "+ip )); + // + // QString host2 = "www.hs-harz.de"; + // QString ip2 = Utils( GlobalConfig, parent ).resolveName(host2, parent); + // if (ip2=="0.0.0.0") + // KMessageBox::error( this, i18n( "Host \"%1\" could not be resolved!" ).arg(host2) ); + // else + // mw->DebugOutput->append( QString("first ip of "+host2+": "+ip2 )); + + // if (Utils( GlobalConfig, parent ).loadKernelModule("parport_pc",parent)) + // mw->DebugOutput->append( "Loading module ok" ); + // else + // mw->DebugOutput->append( "Loading module failed." ); + + +// appHelpActivated (); + + + // QString bin="/a/b/c/myexe"; + // kdDebug() << "bin: " << bin.section('/',-1,-1) << endl; + // kdDebug() << "path: " << bin.section('/',0,-2) << endl; + + // // looking for vpnc + // if ( GlobalConfig->useDefaultPaths ){ + // GlobalConfig->pathToVpnc= KStandardDirs::findExe("vpnc",QString::null); + // kdDebug() << "vpnc found at; " << GlobalConfig->pathToVpnc << endl; + // } + // if ( GlobalConfig->pathToVpnc.isEmpty() || KStandardDirs::findExe( GlobalConfig->pathToVpnc.section('/',-1,-1),GlobalConfig->pathToVpnc.section('/',0,-2)).isEmpty()) + // { + // kdDebug() << "vpnc not found!" << endl; + // } + // else + // kdDebug() << "vpnc (2) found at; " << GlobalConfig->pathToVpnc << endl; + + + /* network tests */ + // QString iface = "eth2"; + // if ( Utils(GlobalConfig,this).isValidNetworkDevice(iface) ) + // std::cout << iface <<" is a valid network interface" << "\n"; + // else + // std::cout << iface << " is not valid network interface" << "\n"; + // + // QString iface2 = "eth3"; + // if ( Utils(GlobalConfig,this).isValidNetworkDevice(iface2) ) + // std::cout << iface2 <<" is a valid network interface" << "\n"; + // else + // std::cout << iface2 << " is not valid network interface" << "\n"; + /* + NetworkInterface iface(GlobalConfig,parent); + bool success = iface.interfaceExist( "eth0" ); + QString succString; + if ( success == true ) + mw->DebugOutput->append( "Testing interface eth0: success" ); + else + mw->DebugOutput->append( "Testing interface eth0: failed" ); + + QStringList list = iface.getAllNetworkInterfaces(); + QString netliststring=""; + for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { + QString aa = QString( *it ); + netliststring+=" "; + netliststring+=aa; + } + + mw->DebugOutput->append( "All network interfaces:"+netliststring ); + + QString defaultinterface = iface.getDefaultInterface(); + if ( defaultinterface.isEmpty() ) + defaultinterface += "none"; + mw->DebugOutput->append( "Defaultinterface: "+defaultinterface ); + + QString interfaceaddress = "Interface address for ip 127.0.0.1: " + iface.getInterfaceAddress( "127.0.0.1" ); + if ( interfaceaddress.isEmpty() ) + interfaceaddress += "none"; + mw->DebugOutput->append( interfaceaddress ); + + QString interfaceip = "Interface IP of eth1:2: " + iface.getInterfaceIP( "eth1:2" ); + if ( interfaceip.isEmpty() ) + interfaceip += "none"; + mw->DebugOutput->append( interfaceip ); + */ +// NetworkInterface iface(GlobalConfig,parent); +// QString gatewayofdefaultinterface = "GW IP of default interface: " + iface.getGatewayOfDefaultInterface(); +// mw->DebugOutput->append( gatewayofdefaultinterface ); +// QString NetmaskOfInterface = "netmask IP of interface: " + iface.getNetmaskOfInterface("wlan0"); +// mw->DebugOutput->append( NetmaskOfInterface ); + /* + if (iface.inSameNetwork("192.168.10.253","255.255.255.0","192.168.10.222","255.255.255.0")) + mw->DebugOutput->append("192.168.10.253 in same network as 192.168.10.222: yes"); + else + mw->DebugOutput->append("192.168.10.253 in same network as 192.168.10.222: no"); + + if (iface.inSameNetwork("192.168.10.253","255.255.255.0","192.168.1.2","255.255.255.0")) + mw->DebugOutput->append("192.168.10.253 in same network as 192.168.1.2: yes"); + else + mw->DebugOutput->append("192.168.10.253 in same network as 192.168.1.2: no"); + */ + /* + QString gatewayofinterface = "GW IP of interface eth1:1: " + iface.getGatewayOfInterface("eth1:1"); + mw->DebugOutput->append( gatewayofinterface ); + + mw->DebugOutput->append( "www.sun.de => "+Utils(GlobalConfig).resolveName("www.sun.de") ); + */ + /* + QString ipstring = "aaa\ngot address 194.95.192.28\nbbbb\ncccc"; + mw->DebugOutput->append(QString("Ipstring: \n"+ipstring)); + QString ip = ipstring.section('\n',1,1); + ip = ip.right(ip.length()-12); + mw->DebugOutput->append(QString("Ip: "+ip)); + */ + // NetworkInterface iface(parent); + // QString extIP = iface.getExternalIpAddress(); + // if ( extIP.isEmpty() ) + // extIP += "none"; + // + // KMessageBox::information(0,extip,"ext ip" ); + + // /* passwords with kwallet */ + // if (GlobalConfig->useKwallet && KWallet::Wallet::isEnabled()) + // { + // // Open local wallet + // GlobalConfig->wallet = KWallet::Wallet::openWallet(KWallet::Wallet::LocalWallet()); + // if (GlobalConfig->wallet != 0) + // { + // + // QString walletname="kvpnc"; + // // Check if folder exists, otherwise create it + // + // if (!GlobalConfig->wallet->hasFolder(walletname)) + // { + // bool walletOK = GlobalConfig->wallet->createFolder(walletname); + // GlobalConfig->wallet->setFolder(walletname); + // QString account="HS"; + // + // QString loginname="masta"; + // QString pwd="secret"; + // std::cout << "[set] account: " << account << ", loginname: " << loginname << ", password: " << pwd << std::endl; + // + // bool pwdOK = (GlobalConfig->wallet->writePassword (QString(account+"_"+loginname), pwd) == 0); + // std::cout << "success: " << pwdOK << std::endl; + // } + // // Read password entry + // + // { + // GlobalConfig->wallet->setFolder(walletname); + // QString loginname="masta"; + // QString pwd=""; + // QString account="HS"; + // bool pwdOK = (GlobalConfig->wallet->readPassword(QString(account+"_"+loginname), pwd) == 0); + // std::cout << "success: " << pwdOK << std::endl; + // std::cout << "[get]: loginname: " << loginname << ", password: " << pwd << std::endl; + // + // } + // } + // } + + // QStringList ciphers = Utils(GlobalConfig).getOpenvpnCiphers(); + // + // std::cout << "ciphers: " << std::endl ; + // + // for ( QStringList::Iterator it = ciphers.begin(); it != ciphers.end(); ++it ) { + // std::cout << QString(*it).ascii() << "\n"; + // } + // std::cout << std::endl; + + // bool ret = Utils(GlobalConfig).getNeedsPassphrase("/etc/ipsec.d/private/crissi.pem"); + // + // if (ret) + // mw->DebugOutput->append("private key needs a passprase "); + // else + // mw->DebugOutput->append("private key dont need a passprase "); + + /* + QString testfilename="sfsd/::::( *#v v###\\"; + QString cleanedUpName = Utils(this->GlobalConfig).removeSpecialCharsForFilename( testfilename); + cQString("testfilename: \"%1\", cleaned up: \"%2\"").arg(testfilename).arg(cleanedUpName)); + */ + +// GlobalConfig->exportKvpncConfig("./kvpnc_export.xml"); +// importIpsecProfileClicked(); + +// Utils::IpsecAlgos algos = Utils(GlobalConfig).getIpsecAlgos(); + +// Utils::PppdCapabilities pppdcap = Utils ( GlobalConfig ).checkPppdCapabilities(); +// +// if (pppdcap.pppdHasMppeRequiredSupport==true) +// mw->DebugOutput->append( "pppdHasMppeRequiredSupport: yes"); +// else +// mw->DebugOutput->append( "pppdHasMppeRequiredSupport: no"); +// if (pppdcap.pppdHasRequireMppeSupport==true) +// mw->DebugOutput->append( "pppdHasRequireMppeSupport: yes"); +// else +// mw->DebugOutput->append( "pppdHasRequireMppeSupport: no"); +// if (pppdcap.pppdHasReplacedefaultrouteSupport==true) +// mw->DebugOutput->append( "pppdHasReplacedefaultrouteSupport: yes"); +// else +// mw->DebugOutput->append( "pppdHasReplacedefaultrouteSupport: no"); +// if (pppdcap.pppdHasMppeSupport==true) +// mw->DebugOutput->append( "pppdHasMppeSupport: yes"); +// else +// mw->DebugOutput->append( "pppdHasMppeSupport: no"); +// if (pppdcap.oldPppdStyle==true) +// mw->DebugOutput->append( "oldPppdStyle: yes"); +// else +// mw->DebugOutput->append( "oldPppdStyle: no"); +// if (pppdcap.pppdOk==true) +// mw->DebugOutput->append( "pppdOk: yes"); +// else +// mw->DebugOutput->append( "pppdOk: no"); +// +// +// if (pppdcap.pppdHasMppeSupport) +// mw->DebugOutput->append( "pppdHasMppeSupport: true"); +// else +// mw->DebugOutput->append( "pppdHasMppeSupport: false"); +// +// if (pppdcap.oldPppdStyle) +// mw->DebugOutput->append( "oldPppdStyle: true"); +// else +// mw->DebugOutput->append( "oldPppdStyle: false"); + +// Utils::IpsecAlgos KernelCrypto = Utils ( GlobalConfig ).getKernelCrypto(); +// +// // phase 2 encr algos from kernel +// QString EncrAlgos=""; +// for ( QStringList::Iterator it = KernelCrypto.IpsecEspEncryptionAlgorithms.begin(); it != KernelCrypto.IpsecEspEncryptionAlgorithms.end(); ++it ) +// { +// EncrAlgos+= QString(", "+*it ); +// } +// mw->DebugOutput->append( "Kernel encryption algos:\n"); +// mw->DebugOutput->append( EncrAlgos+"\n"); +// +// // phase 2 auth algos from kernel +// QString AuthAlgos=""; +// for ( QStringList::Iterator it = KernelCrypto.IpsecEspAuthenticationAlgorithms.begin(); it != KernelCrypto.IpsecEspAuthenticationAlgorithms.end(); ++it ) +// { +// AuthAlgos+= QString(", "+*it ); +// } +// mw->DebugOutput->append( "Kernel auth algos:\n"); +// mw->DebugOutput->append( AuthAlgos+"\n"); + +} + +void KVpnc::toolsInfoClicked() +{ + ToolsInfoDialog infodlg ( GlobalConfig ); + ToolsInfoAction->setChecked ( true ); + infodlg.exec(); + ToolsInfoAction->setChecked ( false ); +} + +void KVpnc::vpnTypesInfoClicked() +{ + VpnTypesInfoDialog infodlg ( GlobalConfig ); + VpnTypesInfoAction->setChecked ( true ); + infodlg.exec(); + VpnTypesInfoAction->setChecked ( false ); +} + +void KVpnc::donateClicked() +{ + this->slotStatusMsg ( i18n ( "Calling KVpnc website..." ), ID_FLASH_MSG ); + QString donateurl = "http://home.gna.org/kvpnc/en/donate.html"; + QString browser = QString ( KConfigGroup ( KGlobal::config(), "General" ).readEntry ( "BrowserApplication" ) ).remove ( "!", "" ); + + if ( browser.isEmpty() ) + browser = "konqueror"; + + KRun * run = new KRun ( KURL ( donateurl ),0,false,true ); + if ( run ) + ; + +// DonateProcess = new QProcess ( this ); +// DonateProcess->addArgument ( browser ); +// DonateProcess->addArgument ( donateurl ); +// +// // connect( DonateProcess, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdout_bugreport() ) ); +// // connect( DonateProcess, SIGNAL( readyReadStderr() ), this, SLOT( readFromStderr_bugreport() ) ); +// +// if ( !DonateProcess->start(env) ) +// { +// GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( i18n ( "donate" ) ), GlobalConfig->error ); +// KMessageBox::error ( this, i18n ( "\"%1\" with %2 start failed!" ).arg ( i18n ( "donate" ) ).arg ( browser ) ); +// } +// else +// { +// if ( GlobalConfig->KvpncDebugLevel > 0 ) +// GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( i18n ( "browser" ) ), GlobalConfig->debug ); + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "URL \"%1\" with browser \"%2\" called." ).arg ( donateurl ).arg ( browser ), GlobalConfig->debug ); +// } + delete DonateProcess; + DonateProcess=0L; + + this->slotStatusMsg ( i18n ( "Ready." ), ID_STATUS_MSG ); +} + +void KVpnc::reportBugClicked() +{ + QString bugreporturl = "https://gna.org/bugs/?group=kvpnc"; + QString browser = QString ( KConfigGroup ( KGlobal::config(), "General" ).readEntry ( "BrowserApplication" ) ).remove ( "!", "" ); + + if ( browser.isEmpty() ) + browser = "konqueror"; + + // KRun * run = new KRun( KURL( bugreporturl ),0,false,true ); + // if ( run ) + // ; + + BugReportProcess = new QProcess ( this ); + BugReportProcess->addArgument ( browser ); + BugReportProcess->addArgument ( bugreporturl ); + + // connect( BugReportProcess, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdout_bugreport() ) ); + // connect( BugReportProcess, SIGNAL( readyReadStderr() ), this, SLOT( readFromStderr_bugreport() ) ); + + if ( !BugReportProcess->start ( env ) ) + { + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( i18n ( "bugreport" ) ), GlobalConfig->error ); + KMessageBox::error ( this, i18n ( "\"%1\" with %2 start failed!" ).arg ( i18n ( "bugreport" ) ).arg ( browser ) ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( i18n ( "bugreport" ) ), GlobalConfig->debug ); + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "URL \"%1\" with browser \"%2\" called." ).arg ( bugreporturl ).arg ( browser ), GlobalConfig->debug ); + + while ( BugReportProcess->isRunning() ) + { + sleep ( 1 ); + } + } + delete BugReportProcess; + BugReportProcess=0L; + +} + +void KVpnc::readOutputFrom_vpnc() +{ + + + //mw->DebugOutput->append( "readOutputFrom_vpnc!\n" ); + while ( VpncProcess->canReadLineStdout() ) + { + ProcessMsg_connect = VpncProcess->readLineStdout(); + // ProcessMsg_connect = QString( VpncProcess->readStdout() ); + + + if ( deviceaddrstr2addr ) + { + deviceaddrstr = ProcessMsg_connect; + + // if (GlobalConfig->KvpncDebugLevel > 0) + // this->GlobalConfig->appendLogEntry ( QString ( "deviceaddrstr: " + deviceaddrstr ),GlobalConfig->debug); + deviceaddr = "addr: " + QString ( deviceaddrstr.simplifyWhiteSpace ().section ( ' ', 1, 1 ) ).section ( ':', 1, 1 ); + // if (GlobalConfig->KvpncDebugLevel > 0) + // this->GlobalConfig->appendLogEntry ( deviceaddr,GlobalConfig->debug); // + deviceaddrstr2addr = false; + //disconnect( VpncProcess, SIGNAL( readyReadStdout() ), this, SLOT( readOutputFrom_vpnc() ) ); + //disconnect( VpncProcess, SIGNAL( readyReadStderr() ), this, SLOT( readOutputFrom_vpnc() ) ); + } + + /* TMP !!!! */ + // requesting group password + if ( ProcessMsg_connect.find ( "Enter IPSec secret", 0, FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[vpnc] " + i18n ( "Group password requested, send it..." ), GlobalConfig->debug ); + + + + QString GrpPassStr = ""; + GrpPassStr = GlobalConfig->TmpGroupPassword; + + + VpncProcess->writeToStdin ( GrpPassStr ); + VpncProcess->writeToStdin ( "\n" ); + + if ( GlobalConfig->KvpncDebugLevel > 6 ) + GlobalConfig->appendLogEntry ( "[vpnc] " + i18n ( "Group password: %1" ).arg(GrpPassStr), GlobalConfig->debug ); + + + } + + // requesting password + else if ( ProcessMsg_connect.find ( "password for", 0, FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[vpnc] " + i18n ( "User password requested, send it..." ), GlobalConfig->debug ); + + QString UserPassStr = GlobalConfig->TmpPassword; + VpncProcess->writeToStdin ( UserPassStr ); + VpncProcess->writeToStdin ( "\n" ); + + if ( GlobalConfig->KvpncDebugLevel > 6 ) + GlobalConfig->appendLogEntry ( "[vpnc] " + i18n ( "User password: %1" ).arg(UserPassStr), GlobalConfig->debug ); + + } + + + //"Enter Username and Password" + + // requesting gatway + else if ( ProcessMsg_connect.find ( "Enter IPSec gateway address", 0, FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[vpnc] " + i18n ( "IPSec gateway address requested, send it..." ), GlobalConfig->debug ); + //QString GatewayStr = GlobalConfig->currentProfile->getGateway(); + QString GatewayStr = GlobalConfig->TmpGatewayIP; + VpncProcess->writeToStdin ( GatewayStr ); + VpncProcess->writeToStdin ( "\n" ); + } + + // requesting IPSec ID + //Enter IPSec ID for + else if ( ProcessMsg_connect.find ( "Enter IPSec ID", 0, FALSE ) > -1 || ProcessMsg_connect.find ( "Enter IPSec ID for", 0, FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[vpnc] " + i18n ( "IPSec ID requested, send it..." ), GlobalConfig->debug ); + QString IpsecIDStr = GlobalConfig->currentProfile->getID(); + VpncProcess->writeToStdin ( IpsecIDStr ); + VpncProcess->writeToStdin ( "\n" ); + } + + // requesting username + else if ( ( ProcessMsg_connect.find ( "Enter username for", 0, FALSE ) > -1 ) && !ProcessMsg_connect.find ( "Enter Username and Password", 0, FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[vpnc] " + i18n ( "Username requested, send it..." ), GlobalConfig->debug ); + + QString UsernameStr; + UsernameStr = GlobalConfig->TmpUsername; + + VpncProcess->writeToStdin ( UsernameStr ); + VpncProcess->writeToStdin ( "\n" ); + + if ( GlobalConfig->KvpncDebugLevel > 6 ) + GlobalConfig->appendLogEntry ( "[vpnc] " + i18n ( "User name: %1" ).arg(UsernameStr), GlobalConfig->debug ); + + } + + // using interface tun0 + else if ( ProcessMsg_connect.find ( "using interface", 0, FALSE ) > -1 ) + { + VpncDevice = ProcessMsg_connect.section ( ' ', 2, 2 ); // using interface tun0 -> tun0 + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Tunnel device: %1" ).arg ( VpncDevice ), GlobalConfig->debug ); + } + + //got address 194.95.192.28 + else if ( ProcessMsg_connect.find ( "got address", 0, FALSE ) > -1 ) + { + // "got address 194.95.192.28" => "194.95.192.28" +// TunnelInterfaceIP = ProcessMsg_connect.section ( '\n', 1, 1 ); +// TunnelInterfaceIP = TunnelInterfaceIP.right ( TunnelInterfaceIP.length() - 12 ); + TunnelInterfaceIP = ProcessMsg_connect.section ( ' ',2,2 ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Tunnel IP: %1" ).arg ( TunnelInterfaceIP ), GlobalConfig->debug ); + } + + bool connectSuccess = false; + if ( ProcessMsg_connect.find ( "started in background", 0, FALSE ) > -1 ) + connectSuccess = true; + + else if ( ProcessMsg_connect.find ( "started in foreground", 0, FALSE ) > -1 ) + connectSuccess = true; + + else if ( ProcessMsg_connect.find ( "tun0", 0, FALSE ) > -1 ) + GlobalConfig->appendLogEntry ( i18n ( "line: %1" ).arg ( ProcessMsg_connect ), GlobalConfig->debug ); + + + if ( connectSuccess ) + { + GlobalConfig->appendLogEntry ( "[vpnc] " + i18n ( "Connection established." ) , GlobalConfig->success ); + + sec = hour = min = 0; + + GlobalConfig->status = GlobalConfig->connected; + timer.stop(); + connectCounter=0; + disconnect ( &timer, SIGNAL ( timeout() ), this, SLOT ( slotConnectTimedOut() ) ); + + connect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + durationTimer.start ( 1000, FALSE ); + setGuiStatus ( connected ); + connectSuccess = false; + + NetworkInterface iface ( GlobalConfig, parent ); + TunnelInterfaceIP = iface.getInterfaceIP ( VpncDevice ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[vpnc] " + i18n ( "Tunnel IP: %1" ).arg ( TunnelInterfaceIP ) , GlobalConfig->debug ); + + setFirewallAfterConnect(); + if ( GlobalConfig->currentProfile->getExecuteCmdAfterConnect() ) + executeCommandAfterConnect(); + + if ( GlobalConfig->currentProfile->getUseAdditionalNetworkRoutes() && !GlobalConfig->currentProfile->getAdditionalNetworkRoutes().isEmpty() ) + { + addAdditionalNetworkRoutes(); + //sleep (2); + } + + if ( GlobalConfig->currentProfile->getUseConnectionStatusCheck() ) + { + startConnectionStatusCheck(); + } + } + + bool abort = false; + bool doContinue = true; + //ProcessMsg_connect = QString(VpncProcess->readStdout()); + // if ( this->GlobalConfig->VpncDebugLevel > 0 ) + // this->GlobalConfig->appendLogEntry ( QString ( "[vpnc err] " + ProcessMsg_connect ) , GlobalConfig->error); + + + if ( ProcessMsg_connect.find ( "AUTHENTICATION_FAILED", 0, FALSE ) > -1 ) + { + timer.stop(); + connectCounter=0; + disconnect ( &timer, SIGNAL ( timeout() ), this, SLOT ( slotConnectTimedOut() ) ); + KMessageBox::error ( this, i18n ( "Authentication failed (%1)!" ).arg ( i18n ( "group password" ) ) ); + GlobalConfig->appendLogEntry ( i18n ( "Authentication failed (%1)!" ).arg ( i18n ( "group password" ) ) , GlobalConfig->error ); + //abort = true; + AuthRetry = true; + GlobalConfig->haveUserData = false; + connectClicked(); + } + +// quick mode response rejected: (ISAKMP_N_INVALID_PAYLOAD_TYPE)(1) + if ( ProcessMsg_connect.find ( "quick mode response rejected:", 0, FALSE ) > -1 ) + { + timer.stop(); + connectCounter=0; + disconnect ( &timer, SIGNAL ( timeout() ), this, SLOT ( slotConnectTimedOut() ) ); + KMessageBox::error ( this, i18n ( "Connection rejected because wrong settings sent to the VPN server. Please check your settings." ) ) ; + GlobalConfig->appendLogEntry ( i18n ( "Connection rejected because wrong settings sent to the VPN server. Please check your settings." ) , GlobalConfig->error ); + abort = true; + AuthRetry = false; + disconnect ( VpncProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readOutputFrom_vpnc() ) ); + timer.stop(); + connectClicked(); + } + + if ( ProcessMsg_connect.find ( "authentication unsuccessful", 0, FALSE ) > -1 ) + { + timer.stop(); + connectCounter=0; + disconnect ( &timer, SIGNAL ( timeout() ), this, SLOT ( slotConnectTimedOut() ) ); + KMessageBox::error ( this, i18n ( "Authentication failed (%1)!" ).arg ( i18n ( "user password" ) ) ); + GlobalConfig->appendLogEntry ( i18n ( "Authentication failed (%1)!" ).arg ( i18n ( "user password" ) ) , GlobalConfig->error ); + //abort = true; + AuthRetry = true; + GlobalConfig->haveUserData = false; + disconnect ( VpncProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readOutputFrom_vpnc() ) ); + timer.stop(); + connectClicked(); + } + + // no ip for gateway + if ( ProcessMsg_connect.find ( "vpnc: unknown host `' ", 0, FALSE ) > -1 ) + { + timer.stop(); + connectCounter=0; + disconnect ( &timer, SIGNAL ( timeout() ), this, SLOT ( slotConnectTimedOut() ) ); + KMessageBox::error ( this, i18n ( "You have to enter a IP address for the remote gateway!" ) ); + GlobalConfig->appendLogEntry ( i18n ( "You have to enter a IP address for the remote gateway!" ) , GlobalConfig->error ); + abort = true; + } + + // no answer + if ( ProcessMsg_connect.find ( "no response from target", 0, FALSE ) > -1 ) + { + timer.stop(); + connectCounter=0; + disconnect ( &timer, SIGNAL ( timeout() ), this, SLOT ( slotConnectTimedOut() ) ); + KMessageBox::error ( this, i18n ( "No response from VPN server" ) ); + GlobalConfig->appendLogEntry ( i18n ( "No response from VPN server" ) , GlobalConfig->error ); + abort = true; + } + + // initalizing tunnel interface failed + if ( ProcessMsg_connect.find ( "can't initialise tunnel interface", 0, FALSE ) > -1 ) + { + timer.stop(); + connectCounter=0; + disconnect ( &timer, SIGNAL ( timeout() ), this, SLOT ( slotConnectTimedOut() ) ); + KMessageBox::error ( this, i18n ( "Tunnel interface can't be initalized" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Tunnel interface can't be initalized" ) , GlobalConfig->error ); + abort = true; + doContinue = false; + } + + // /dev/net/tun doesnt exist + if ( ProcessMsg_connect.find ( "can't open /dev/net/tun", 0, FALSE ) > -1 ) + { + if ( doContinue ) + { + KMessageBox::error ( this, i18n ( "Device file \"%1\" can't be opened" ).arg ( "/dev/net/tun" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Device file \"%1\" can't be opened" ).arg ( "/dev/net/tun" ) , GlobalConfig->error ); + abort = true; + } + } + + // host unknown + if ( ProcessMsg_connect.find ( "unknown host" , 0, FALSE ) > -1 ) + { + timer.stop(); + connectCounter=0; + disconnect ( &timer, SIGNAL ( timeout() ), this, SLOT ( slotConnectTimedOut() ) ); + KMessageBox::error ( this, i18n ( "Host unknown" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Host unknown" ) , GlobalConfig->error ); + abort = true; + } + + //socket creation failed + if ( ProcessMsg_connect.find ( "making socket", 0, FALSE ) > -1 ) + { + timer.stop(); + connectCounter=0; + disconnect ( &timer, SIGNAL ( timeout() ), this, SLOT ( slotConnectTimedOut() ) ); + KMessageBox::error ( this, i18n ( "Socket creation failed" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Socket creation failed" ) , GlobalConfig->error ); + abort = true; + } + + if ( ProcessMsg_connect.find ( "receiving packet: Connection refused", 0, FALSE ) > -1 ) + { + timer.stop(); + connectCounter=0; + disconnect ( &timer, SIGNAL ( timeout() ), this, SLOT ( slotConnectTimedOut() ) ); + KMessageBox::error ( this, i18n ( "Connection to the Cisco server was refused" ) ); + GlobalConfig->appendLogEntry ( i18n ( "receiving packet: Connection refused" ) , GlobalConfig->error ); + abort = true; + } + + // binding to port failed + if ( ProcessMsg_connect.find ( "binding to port", 0 , FALSE ) > -1 || ProcessMsg_connect.find ( "Address already in use", 0 , FALSE ) > -1 ) + { + timer.stop(); + connectCounter=0; + disconnect ( &timer, SIGNAL ( timeout() ), this, SLOT ( slotConnectTimedOut() ) ); + // if ( GlobalConfig->KvpncDebugLevel > 0 ) + // GlobalConfig->appendLogEntry( i18n( "Binding to port failed. Another vpnc is running, terminate it and try reconnect ." ), GlobalConfig->debug ); + GlobalConfig->appendLogEntry ( QString ( "binding" + ProcessMsg_connect ), GlobalConfig->debug ); + // QFile oldpidfile( tmpPath + "vpnc-pid." + GlobalConfig->currentProfile->getName() + ".pid" ); + // if (oldpidfile.exists()) + // { + // if ( GlobalConfig->KvpncDebugLevel > 0 ) + // GlobalConfig->appendLogEntry( i18n( "Old pid file found: %1" ).arg(oldpidfile.name()), GlobalConfig->debug ); + // QTextStream pidFileStream( &oldpidfile ); + // QString Vpnc_pid = ""; + // if ( oldpidfile.open( IO_ReadOnly ) ) + // { + // Vpnc_pid = pidFileStream.readLine(); + // oldpidfile.close(); + // } + // QProcess killvpncprocess(this); + // if ( !Vpnc_pid.isEmpty() ) + // { + // + // if ( GlobalConfig->KvpncDebugLevel > 0 ) + // GlobalConfig->appendLogEntry( i18n( "Vpnc pid file contains a pid: %1, try to terminate the process with this pid." ).arg( Vpnc_pid ) , GlobalConfig->debug); + // killvpncprocess.addArgument(GlobalConfig->pathToKill); + // killvpncprocess.addArgument("-3"); + // killvpncprocess.addArgument(Vpnc_pid); + // } + // else + // { + // if ( GlobalConfig->KvpncDebugLevel > 0 ) + // GlobalConfig->appendLogEntry( i18n( "No vpnc pid file found, using \"killall\" for killing vpnc." ), GlobalConfig->debug ); + // killvpncprocess.addArgument("-3"); + // + // } + // + // killvpncprocess.addArgument("vpnc"); + // + // if (!killvpncprocess.start()) + // GlobalConfig->appendLogEntry( i18n( "%1 could not be killed." ).arg("vpnc") ,GlobalConfig->error); + // + // while (killvpncprocess.isRunning()) + // parent->processEvents(); + // } + // else + // { + // //kill vpnc + // QProcess killvpncprocess(this); + // killvpncprocess.addArgument(GlobalConfig->pathToKillall); + // killvpncprocess.addArgument("vpnc"); + // + // if (!killvpncprocess.start()) + // GlobalConfig->appendLogEntry( i18n( "%1 could not be killed." ).arg("vpnc") ,GlobalConfig->error); + // + // while (killvpncprocess.isRunning()) + // parent->processEvents(); +// delete killvpncprocess; +// killvpncprocess=0L; + // + // disconnectClicked(); + // connectClicked(); + // } + // + // VpncDisconnectScript = tmpPath + "vpnc-disconnect." + GlobalConfig->currentProfile->getID() + ".sh"; + // + // QString OldDefaultroute=""; + // QString oldProfileName=""; + // + // QDir tmpDir(tmpPath); + // + // QStringList lst = tmpDir.entryList( "default-route.*" ); + // if (!lst.isEmpty()) + // { + // OldDefaultroute = lst.first(); // default-route. + // + // if ( GlobalConfig->KvpncDebugLevel > 0 ) + // GlobalConfig->appendLogEntry( i18n( "Old defaultroute file found: %1" ).arg(OldDefaultroute), GlobalConfig->debug ); + // + // + // QFile file( VpncDisconnectScript ); + // QTextStream stream( &file ); + // if ( file.open( IO_WriteOnly ) ) + // { + // // stream << "#!"<< GlobalConfig->InterpreterShell << "\n"; + // stream << "# generated by kvpnc. Do not edit it." << "\n"; + // stream << "\n"; + // if (!GlobalConfig->currentProfile->getKeepDefaultRoute()) + // { + // stream << GlobalConfig->pathToIp+" route del default > /dev/null 2>&1\n"; + // stream << GlobalConfig->pathToIp+" route add $(cat \"" + OldDefaultroute + "\")\n"; + // } + // //stream << GlobalConfig->pathToIp+" route del $(cat \"" + VpncGateway + "\")\n"; + + /* update dns? */ +// if (GlobalConfig->currentProfile->getUseDnsUpdate()) +// { + // stream << "chmod u+w /etc/resolv.conf\n"; + // stream << "if [ -f /sbin/resolvconf ] ; then\n"; + // stream << "sbin/resolvconf -d "+GlobalConfig->DnsDevice+"\n"; + // oldProfileName=OldDefaultroute.section('/',-2,-1); // /root/.kde/share/apps/kvpnc/default-route. -> + // if (!oldProfileName.isEmpty() &&QFile("/etc/resolv.conf.before.kvpnc_"+oldProfileName).exists() ) + // { + // if ( GlobalConfig->KvpncDebugLevel > 0 ) + // GlobalConfig->appendLogEntry( i18n( "Old resolv.conf file found, restore it." ), GlobalConfig->debug ); + // + // stream << "else\n"; + // stream << " mv /etc/resolv.conf.before.kvpnc_"+oldProfileName+" /etc/resolv.conf\n"; + // } + // stream << "fi\n"; +// } +// else +// { +// /* dont update dns */ +// } + // + // stream << GlobalConfig->pathToIp+" route flush cache\n"; + // } + // file.close(); + // + // DisconnectProcess = new QProcess (); + // DisconnectProcess->addArgument( GlobalConfig->InterpreterShell ); + // DisconnectProcess->addArgument( VpncDisconnectScript ); + // + // connect( DisconnectProcess, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdout_disconnect() ) ); + // connect( DisconnectProcess, SIGNAL( readyReadStderr() ), this, SLOT( readFromStderr_disconnect() ) ); + // + // if ( !DisconnectProcess->start(env) ) + // { + // KMessageBox::sorry( this, i18n( "\"%1\" start failed!" ).arg( "vpnc_disconnect" ) ); + // } + // else + // { + // if ( GlobalConfig->KvpncDebugLevel > 0 ) + // GlobalConfig->appendLogEntry( i18n( "Disconnect script started." ), GlobalConfig->debug ); + // } + // setGuiStatus(disconnected); + // connectionEnded(); + // } + // + // if ( GlobalConfig->KvpncDebugLevel > 0 ) + // GlobalConfig->appendLogEntry( i18n( "Trying reconnect..." ), GlobalConfig->debug ); + // + // connectClicked(); + + QString NameAndPid = Utils ( GlobalConfig ).getNameAndPidOfProgramListen ( 500 ); + GlobalConfig->appendLogEntry ( i18n ( "NameAndPid: %1" ).arg ( NameAndPid ) , GlobalConfig->debug ); + int pid = -1; + QString Name = ""; + if ( !NameAndPid.isEmpty() ) + { + pid = NameAndPid.section ( '/', 0, 0 ).toInt(); + Name = NameAndPid.section ( '/', 1, 1 ); + KMessageBox::error ( this, i18n ( "Binding port %1 failed. Program \"%2\" with PID \"%3\" is using it. You have to stop it first." ).arg ( QString().setNum ( 500 ) ).arg ( Name ).arg ( QString().setNum ( pid ) ) ); + } + else + KMessageBox::error ( this, i18n ( "Port binding failed" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Port binding failed" ) , GlobalConfig->error ); + abort = true; + } + + // binding to port 500: Address already in use + // if ( ProcessMsg_connect.find( "Address already in use", 0 , FALSE ) > -1 ) + // { + + //int PortToListen = ProcessMsg_connect.section(' ',3,3).section(':',0,0).toInt(); // binding to port 500: Address already in use -> 500 + + // netstat -npltu | grep ':500' + // tcp 0 0 0.0.0.0:500 0.0.0.0:* LISTEN 4272/racoon + // 4272 is pid + + + // if ( GlobalConfig->KvpncDebugLevel > 0 ) + // GlobalConfig->appendLogEntry( i18n( "Binding to port failed. Another program is running at this port, terminate it and try reconnect ." ), GlobalConfig->debug ); + /* + QFile oldpidfile( tmpPath + "vpnc-pid." + GlobalConfig->currentProfile->getName() + ".pid" ); + if (oldpidfile.exists()) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry( i18n( "Old pid file found: %1" ).arg(oldpidfile.name()), GlobalConfig->debug ); + QTextStream pidFileStream( &oldpidfile ); + QString Vpnc_pid = ""; + if ( oldpidfile.open( IO_ReadOnly ) ) + { + Vpnc_pid = pidFileStream.readLine(); + oldpidfile.close(); + } + QProcess killvpncprocess(this); + if ( !Vpnc_pid.isEmpty() ) + { + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry( i18n( "Vpnc pid file contains a pid: %1, try to terminate the process with this pid." ).arg( Vpnc_pid ) , GlobalConfig->debug); + killvpncprocess.addArgument(GlobalConfig->pathToKill); + killvpncprocess.addArgument("-3"); + killvpncprocess.addArgument(Vpnc_pid); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry( i18n( "No vpnc pid file found, using \"killall\" for killing vpnc." ), GlobalConfig->debug ); + killvpncprocess.addArgument("-3"); + + } + + killvpncprocess.addArgument("vpnc"); + + if (!killvpncprocess.start()) + GlobalConfig->appendLogEntry( i18n( "%1 could not be killed." ).arg("vpnc") ,GlobalConfig->error); + + while (killvpncprocess.isRunning()) + parent->processEvents(); + } + else + { + //kill vpnc + QProcess killvpncprocess(this); + killvpncprocess.addArgument(GlobalConfig->pathToKillall); + killvpncprocess.addArgument("vpnc"); + + if (!killvpncprocess.start()) + GlobalConfig->appendLogEntry( i18n( "%1 could not be killed." ).arg("vpnc") ,GlobalConfig->error); + + while (killvpncprocess.isRunning()) + parent->processEvents(); + delete killvpncprocess; + killvpncprocess=0L; + */ + + // disconnectClicked(); + //connectClicked(); + // } + + // KMessageBox::error( this, i18n( "Address already in use" ) ); + // GlobalConfig->appendLogEntry(i18n( "Address already in use" ) ,GlobalConfig->error); + // abort = true; + // } + + + if ( ProcessMsg_connect.find ( "Network is unreachable", 0 , FALSE ) > -1 ) + { + timer.stop(); + connectCounter=0; + disconnect ( &timer, SIGNAL ( timeout() ), this, SLOT ( slotConnectTimedOut() ) ); + KMessageBox::error ( this, i18n ( "No network reachable" ) ); + GlobalConfig->appendLogEntry ( i18n ( "No network reachable" ) , GlobalConfig->error ); + terminateConnection ( VpncProcess ); + } + + + if ( ProcessMsg_connect.find ( "response was invalid",0 , FALSE ) > -1 && ProcessMsg_connect.find ( "ISAKMP_N_INVALID_EXCHANGE_TYPE", 0, FALSE ) > -1 ) + { + timer.stop(); + connectCounter=0; + disconnect ( &timer, SIGNAL ( timeout() ), this, SLOT ( slotConnectTimedOut() ) ); + KMessageBox::error ( this, i18n ( "Invalid ISAKMP exchange type received" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Invalid ISAKMP exchange type received" ) , GlobalConfig->error ); + abort = true; + doContinue = false; + } + + if ( ProcessMsg_connect.find ( "vpnc found running", 0 , FALSE ) > -1 ) + { + //KMessageBox::sorry( this, i18n( "vpnc is already running, kill it manually" ) ); + //terminateConnection ( VpncProcess ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + { + GlobalConfig->appendLogEntry ( "[vpnc] " + i18n ( "Vpnc found running, killing it...\n" ) , GlobalConfig->debug ); + } + timer.stop(); + disconnectClicked(); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[vpnc] " + i18n ( "Trying again...\n" ), GlobalConfig->debug ); + connectClicked(); + } + + if ( ProcessMsg_connect.find ( "Passcode for VPN", 0, FALSE ) > -1 ) + { + if ( GlobalConfig->currentProfile->getUseXauthInteractive() ) + { + GlobalConfig->TmpXauthInterPasscode = ""; + EnterXauthInteractivePasscodeDialog dlg ( this); + dlg.setCaption( i18n ( "Enter Xauth interactive passcode" ) ); + dlg.main->SavePasswordCheckBox->hide(); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[vpnc] " + i18n ( "Passcode for Xauth interactive requested...\n" ), GlobalConfig->debug ); + dlg.exec(); + if ( !dlg.main->PasswordEdit->text().isEmpty() ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[vpnc] " + i18n ( "Got passcode for Xauth interactive from enter Xauth interactive passcode dialog...\n" ), GlobalConfig->debug ); + GlobalConfig->TmpXauthInterPasscode = dlg.main->PasswordEdit->text(); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[vpnc] " + i18n ( "Send passcode for Xauth interactive...\n" ), GlobalConfig->debug ); + VpncProcess->writeToStdin ( GlobalConfig->TmpXauthInterPasscode ); + VpncProcess->writeToStdin ( "\n" ); + } + } + } + + if ( ProcessMsg_connect.find ( "Connect Banner", 0, FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[vpnc] " + i18n ( "Connect banner recieved" ), GlobalConfig->debug ); + GlobalConfig->appendLogEntry ( ProcessMsg_connect , GlobalConfig->info ); + } + + + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( "[vpnc] "+ProcessMsg_connect , GlobalConfig->debug ); + + if ( abort ) + { + timer.stop(); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "vpnc" ) , GlobalConfig->debug ); + terminateConnection ( VpncProcess ); + return ; + } + + } +} + +void KVpnc::readOutputFrom_ciscovpnc() +{ + bool abort=false; + bool connectSuccess = false; + bool terminatedByClient=false; + + //mw->DebugOutput->append( "readOutputFrom_vpnc!\n" ); + QString line2 = QString ( CiscoVpncProcess->readStdout() ); + QStringList lines = QStringList::split ( '\n', line2 ); + for ( QStringList::Iterator it = lines.begin(); it != lines.end(); ++it ) +// while ( CiscoVpncProcess->canReadLineStdout() ) + { +// QString ProcessMsg_connect = CiscoVpncProcess->readLineStdout(); +// QString ProcessMsg_connect = QString( CiscoVpncProcess->readStdout() ); + QString ProcessMsg_connect = *it; + + if ( GlobalConfig->KvpncDebugLevel> 3 ) + GlobalConfig->appendLogEntry ( QString ( "[vpnclient raw]: " ) +ProcessMsg_connect , GlobalConfig->debug ); + + + if ( ProcessMsg_connect.find ( "illegal read", 0 , FALSE ) > -1 ) + { } + + else if ( ProcessMsg_connect.find ( "The profile specified could not be read.", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( 0,i18n ( "Profile missing. Please contact the KVpnc author." ),i18n ( "Profile missing" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Profile file missing. Please contact the KVpnc author." ),GlobalConfig->error ); + abort=true; + } + + else if ( ProcessMsg_connect.find ( "Secure VPN Connection terminated locally by the Client", 0 , FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( i18n ( "Secure VPN connection terminated locally by the client." ),GlobalConfig->error ); + terminatedByClient=true; + KMessageBox::error ( 0,i18n ( "Secure VPN connection terminated locally by the client. Please check your settings (Certificate password, e.g.)." ),i18n ( "Connection terminated" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Secure VPN connection terminated locally by the client. Please check your settings (Certificate password, e.g.)" ),GlobalConfig->error ); + abort=true; + } + + // binding to port failed + if ( ProcessMsg_connect.find ( "bind: Address already in use", 0 , FALSE ) > -1 ) + { + // if ( GlobalConfig->KvpncDebugLevel > 0 ) + // GlobalConfig->appendLogEntry( i18n( "Binding to port failed. Another vpnc is running, terminate it and try reconnect ." ), GlobalConfig->debug ); + GlobalConfig->appendLogEntry ( QString ( "binding" + ProcessMsg_connect ), GlobalConfig->debug ); + + QString NameAndPid = Utils ( GlobalConfig ).getNameAndPidOfProgramListen ( 500 ); + GlobalConfig->appendLogEntry ( i18n ( "NameAndPid: %1" ).arg ( NameAndPid ) , GlobalConfig->debug ); + int pid = -1; + QString Name = ""; + if ( !NameAndPid.isEmpty() ) + { + pid = NameAndPid.section ( '/', 0, 0 ).toInt(); + Name = NameAndPid.section ( '/', 1, 1 ); + KMessageBox::error ( this, i18n ( "Binding port %1 failed. Program \"%2\" with PID \"%3\" is using it. You have to stop it first." ).arg ( QString().setNum ( 500 ) ).arg ( Name ).arg ( QString().setNum ( pid ) ) ); + } + else + KMessageBox::error ( this, i18n ( "Port binding failed" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Port binding failed" ) , GlobalConfig->error ); + abort = true; + } + + if ( ProcessMsg_connect.find ( "Reason: Failed to establish a VPN connection.", 0 , FALSE ) > -1 ) + { + if ( terminatedByClient ) + { + KMessageBox::error ( 0,i18n ( "Secure VPN connection terminated locally by the client. Please check your settings (Certificate password, e.g.)." ),i18n ( "Connection terminated" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Secure VPN connection terminated locally by the client. Please check your settings (Certificate password, e.g.)" ),GlobalConfig->error ); + abort=true; + } + } + + if ( ProcessMsg_connect.find ( "The VPN sub-system is busy or has failed.", 0, FALSE ) > -1 ) + { + abort = true; + } + + else if ( ProcessMsg_connect.find ( "Reason: Remote peer is no longer responding.", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( 0,i18n ( "Timeout while connecting to %1." ).arg ( GlobalConfig->currentProfile->getGateway(),i18n ( "Connection terminated" ) ) ); + GlobalConfig->appendLogEntry ( i18n ( "Timeout while connecting to %1." ).arg ( GlobalConfig->currentProfile->getGateway() ), GlobalConfig->error ); + abort=true; + } + + if ( ProcessMsg_connect.find ( "Reason: A connection is already in the process of being established.", 0, FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "There is already an instance of %1 running!" ).arg ( "vpnclient" ) ); + GlobalConfig->appendLogEntry ( i18n ( "There is already an instance of %1 running!" ).arg ( "vpnclient" ) , GlobalConfig->error ); + abort = true; + } + + // requesting username + if ( ProcessMsg_connect.find ( "Username [", 0, FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[vpnclient] " + i18n ( "Username requested, send it...\n" ), GlobalConfig->debug ); + + QString UsernameStr; + if ( !GlobalConfig->currentProfile->getDontSaveUsername() ) + UsernameStr = GlobalConfig->currentProfile->getUserName(); + else + UsernameStr = GlobalConfig->TmpUsername; + + CiscoVpncProcess->writeToStdin ( UsernameStr ); + CiscoVpncProcess->writeToStdin ( "\n" ); + } + + // requesting password + if ( ProcessMsg_connect.find ( "Password [", 0, FALSE ) > -1 ) + { + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[vpnclient] " + i18n ( "User password requested, send it...\n" ), GlobalConfig->debug ); + + QString UserPassStr = ""; + if ( !GlobalConfig->currentProfile->getSaveUserPassword() || AuthRetry ) + UserPassStr = GlobalConfig->TmpPassword; + else + UserPassStr = GlobalConfig->currentProfile->getUserPassword(); + + if ( GlobalConfig->VpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( "[vpnclient] " + i18n ( "User password: %1\n" ).arg ( UserPassStr ), GlobalConfig->debug ); + + + CiscoVpncProcess->writeToStdin ( UserPassStr ); + CiscoVpncProcess->writeToStdin ( "\n" ); + } + if ( ProcessMsg_connect.find ( "Authenticating user.", 0, FALSE ) > -1 ) + { + if ( GlobalConfig->AuthRetryCount > 1 ) + { + timer.stop(); + connectCounter=0; + disconnect ( &timer, SIGNAL ( timeout() ), this, SLOT ( slotConnectTimedOut() ) ); + KMessageBox::error ( this, i18n ( "Authentication failed (%1)!" ).arg ( i18n ( "group password" ) ) ); + GlobalConfig->appendLogEntry ( i18n ( "Authentication failed (%1)!" ).arg ( i18n ( "group password" ) ) , GlobalConfig->error ); + //abort = true; + AuthRetry = true; + GlobalConfig->haveUserData = false; + connectClicked(); + } + else + { + // nothing here, its first normal try + GlobalConfig->AuthRetryCount++; + } + } + if ( ProcessMsg_connect.find ( "Save Password (Y/N)", 0, FALSE ) > -1 ) + { + CiscoVpncProcess->writeToStdin ( "Y" ); + CiscoVpncProcess->writeToStdin ( "\n" ); + } + + if ( ProcessMsg_connect.find ( "Reason: A connection is already in the process of being established.", 0, FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Reason: A connection is already in the process of being established." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Reason: A connection is already in the process of being established." ) , GlobalConfig->error ); + abort = true; + } + + // requesting certificate password + if ( ProcessMsg_connect.find ( "Enter Certificate password:",0,FALSE ) > -1 ) + { + if ( GlobalConfig->VpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[vpnclient] " + i18n ( "Certificate password requested, send it...\n" ), GlobalConfig->debug ); + + QString PrivKeyPassStr = ""; + // if (GlobalConfig->currentProfile->getSavePsk()) + PrivKeyPassStr = GlobalConfig->currentProfile->getPrivateKeyPass(); + // else + // PrivKeyPassStr = TmpPrivKeyPassStr; + if ( PrivKeyPassStr.isEmpty() ) + { + GlobalConfig->TmpPrivateKeyPass = ""; + QString pass=""; + bool allowEmptyPassword=true; + EnterXauthInteractivePasscodeDialog dlg ( 0, allowEmptyPassword); + dlg.setCaption(i18n ( "Enter certificate password" ) ); + dlg.main->DescriptionLabel->setText ( i18n ( "Enter certificate password to unlock certificate:" ) ); + dlg.main->LabelPassword->setText ( i18n ( "Certificate password:" ) ); + dlg.main->SavePasswordCheckBox->setText ( i18n ( "Save certificate password" ) ); +// dlg.resize(QSize(dlg.width()+20,dlg.height())); + dlg.main->PasswordEdit->setFocus(); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[vpnclient] " + i18n ( "Password for certificate requested...\n" ), GlobalConfig->debug ); + if ( dlg.exec() ) + { + + pass = dlg.main->PasswordEdit->text(); + + if ( !pass.isEmpty() || allowEmptyPassword ) + { + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( "[vpnclient] " + i18n ( "cerificate password got from user" ), GlobalConfig->debug ); + + if ( GlobalConfig->KvpncDebugLevel > 6 ) + GlobalConfig->appendLogEntry ( i18n ( "Send certificate password: %1" ).arg ( pass ), KVpncConfig::debug ); + + if ( dlg.main->SavePasswordCheckBox->isChecked() ) + { + GlobalConfig->currentProfile->setSavePrivateKeyPassword ( true ); + GlobalConfig->currentProfile->setPrivateKeyPass ( QString ( pass ) ); + } + + GlobalConfig->TmpPrivateKeyPass = QString ( pass ); + + // if ( GlobalConfig->KvpncDebugLevel > 5 ) + // GlobalConfig->appendLogEntry( "[vpnclient]: private key password: " + GlobalConfig->TmpPrivateKeyPass, GlobalConfig->debug ); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( "[vpnclient] " + i18n ( "Send certificate password..." ), GlobalConfig->debug ); + + CiscoVpncProcess->writeToStdin ( GlobalConfig->TmpPrivateKeyPass ); + CiscoVpncProcess->writeToStdin ( "\n" ); + } + else + { + GlobalConfig->appendLogEntry ( "[vpnclient] certificate password empty, stop.", GlobalConfig->error ); + return; + } + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "Connect canceled because password enter dialog aborted." ), GlobalConfig->info ); + disconnectClicked(); + } + } + else + { + if ( CiscoVpncProcess != 0 && CiscoVpncProcess->isRunning() ) + { + + if ( GlobalConfig->KvpncDebugLevel > 6 ) + GlobalConfig->appendLogEntry ( i18n ( "Send certificate password: %1" ).arg ( PrivKeyPassStr ), KVpncConfig::debug ); + + CiscoVpncProcess->writeToStdin ( PrivKeyPassStr ); + CiscoVpncProcess->writeToStdin ( "\n" ); + } + return ; + } + } + + if ( ProcessMsg_connect.find ( "Reason: User authentication failed.", 0, FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Authentication failed (%1)!" ).arg ( i18n ( "user password" ) ) ); + GlobalConfig->appendLogEntry ( i18n ( "Authentication failed (%1)!" ).arg ( i18n ( "user password" ) ) , GlobalConfig->error ); + //abort = true; + AuthRetry = true; + GlobalConfig->haveUserData = false; + disconnect ( CiscoVpncProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readOutputFrom_ciscovpnc() ) ); + timer.stop(); + connectClicked(); + } + + if ( ProcessMsg_connect.find ( "Your VPN connection is secure.", 0, FALSE ) > -1 ) + connectSuccess = true; + + if ( ProcessMsg_connect.find ( "Client address: ", 0, FALSE ) > -1 ) + { +// NetworkInterface iface ( GlobalConfig, parent ); +// TunnelInterfaceIP = iface.getInterfaceIP ( CiscoVpncDevice ); + + TunnelInterfaceIP = ProcessMsg_connect.section ( ':',1,1 ).stripWhiteSpace(); +// NetworkInterface iface ( GlobalConfig, parent ); +// TunnelInterfaceIP = iface.getInterfaceIP ( CiscoVpncDevice ); + + + } + + if ( ProcessMsg_connect.find ( "VPN tunnel information:",0,FALSE ) > -1 ) + { +// Client address: 192.168.201.59 + } + if ( ProcessMsg_connect.find ( "Local LAN Access is disabled",0,FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( i18n ( "Local LAN access is disabled (forced by server). This means you cant access to your local LAN." ), KVpncConfig::info ); + } + + if ( ProcessMsg_connect.find ( "Local LAN Access is enabled",0,FALSE ) > -1 ) + { +// GlobalConfig->appendLogEntry ( i18n ( "Local LAN access is enabled." ).arg ( PrivKeyPassStr ), KVpncConfig::info ); + } + + if ( ProcessMsg_connect.find ( "Encryption:",0,FALSE ) > -1 ) + { + QString Encryption = ProcessMsg_connect.section ( ':',1,1 ).stripWhiteSpace(); + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Encrypion algorithm used: %1" ).arg ( Encryption ),GlobalConfig->debug ); + } + + if ( ProcessMsg_connect.find ( "Authentication:",0,FALSE ) > -1 ) + { + QString Authentication = ProcessMsg_connect.section ( ':',1,1 ).stripWhiteSpace(); + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Authentication algorithm used: %1" ).arg ( Authentication ),GlobalConfig->debug ); + } + + + if ( connectSuccess ) + { + GlobalConfig->appendLogEntry ( "[vpnclient] " + i18n ( "Connection established." ) , GlobalConfig->success ); + + sec = hour = min = 0; + + GlobalConfig->status = GlobalConfig->connected; + timer.stop(); + connectCounter=0; + disconnect ( &timer, SIGNAL ( timeout() ), this, SLOT ( slotConnectTimedOut() ) ); + + connect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + durationTimer.start ( 1000, FALSE ); + setGuiStatus ( connected ); + connectSuccess = false; + GlobalConfig->AuthRetryCount=0; + + NetworkInterface iface ( GlobalConfig, parent ); + TunnelInterfaceIP = iface.getInterfaceIP ( CiscoVpncDevice ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[vpnclient] " + i18n ( "Tunnel IP:" ).arg ( TunnelInterfaceIP ) , GlobalConfig->debug ); + + setFirewallAfterConnect(); + if ( GlobalConfig->currentProfile->getExecuteCmdAfterConnect() ) + executeCommandAfterConnect(); + + if ( GlobalConfig->currentProfile->getUseAdditionalNetworkRoutes() && !GlobalConfig->currentProfile->getAdditionalNetworkRoutes().isEmpty() ) + { + addAdditionalNetworkRoutes(); + //sleep (2); + } + + if ( GlobalConfig->currentProfile->getUseConnectionStatusCheck() ) + { + startConnectionStatusCheck(); + } + } + + + //ProcessMsg_connect = QString(CiscoVpncProcess->readStdout()); + // if ( this->GlobalConfig->VpncDebugLevel > 0 ) + // this->GlobalConfig->appendLogEntry ( QString ( "[vpnc err] " + ProcessMsg_connect ) , GlobalConfig->error); + + if ( abort ) + { + timer.stop(); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "vpnclient" ) , GlobalConfig->debug ); + terminateConnection ( CiscoVpncProcess ); + return ; + } + /* + Contacting the gateway at + Username + + + + VPN tunnel information. + Client address: 192.168.88.11 + Server address: 194.95.17.10 + Encryption: 128-bit AES + Authentication: HMAC-SHA + IP Compression: None + NAT passthrough is active on port UDP 10000 + Local LAN Access is disabled + + Disconnecting the VPN connection. + + */ + } +} + +void KVpnc::wroteToStdin_vpncConfig() +{ + VpncProcess->closeStdin(); +} + +void KVpnc::readFromStdout_racoon() +{ + bool abort = false; +// QString ProcessMsg_connect_raw = QString ( RacoonProcess->readStdout() ); +// if (ProcessMsg_connect_raw.length() ==0) +// return; +// +// QStringList ProcessMsg_connect_raw_list = QStringList::split( '\n', ProcessMsg_connect_raw); +// for ( QStringList::Iterator it = ProcessMsg_connect_raw_list.begin(); it != ProcessMsg_connect_raw_list.end(); ++it ) + + while ( RacoonProcess != 0L && RacoonProcess->canReadLineStdout() ) + { + ProcessMsg_connect = RacoonProcess->readLineStdout(); +// ProcessMsg_connect = *it; + + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( "[racoon raw] " + ProcessMsg_connect, GlobalConfig->debug ); + + // if ( pingtest ) { + // // if ( GlobalConfig->KvpncDebugLevel > 0 ) + // // mw->DebugOutput->append( "raw out (pingtest): " + ProcessMsg_connect ); + // + // if ( ProcessMsg_connect.find( "time=", 0, FALSE ) > -1 ) { + // GlobalConfig->appendLogEntry( "[ping] " + ProcessMsg_connect, GlobalConfig->success ); + // } else if ( ProcessMsg_connect.find( "100 % packet loss", 0, FALSE ) > -1 ) { + // GlobalConfig->appendLogEntry( "[ping err] " + ProcessMsg_connect, GlobalConfig->error ); + // } else { + // if ( ProcessMsg_connect.find( "failed to bind", 0, FALSE ) > -1 ) { + // KMessageBox::error( this, i18n( "Binding interface failed!" ) ); + // GlobalConfig->appendLogEntry( i18n( "Binding interface failed!" ) , GlobalConfig->error ); + // } + // if ( ProcessMsg_connect.find( "Destination Host Unreachable", 0, FALSE ) > -1 ) { + // KMessageBox::error( this, i18n( "Destination host is unreachable!" ) ); + // GlobalConfig->appendLogEntry( i18n( "Destination host is unreachable!" ) , GlobalConfig->error ); + // } + // + //if (GlobalConfig->KvpncDebugLevel > 0) + // GlobalConfig->appendLogEntry( "[ping] " + ProcessMsg_connect, GlobalConfig->debug ); + // } + // } + // + // // normal + // else { + + + +// if (ProcessMsg_connect.find ( "ERROR: ", 0 , FALSE ) > -1 && ProcessMsg_connect.find ( "algorithm mismatched", 0 , FALSE ) > -1 ) +// { +// KMessageBox::error( this, i18n( "Algorithm mismatched, please select another one." ) ); +// GlobalConfig->appendLogEntry ( i18n ( "[racoon err]: algorithm mismatched, please select another one." ) , GlobalConfig->error ); +// abort = true; +// } + + if ( ProcessMsg_connect.find ( "ISAKMP-SA established", 0 , FALSE ) > -1 || ProcessMsg_connect.find ( "STATE: upscript finished", 0 , FALSE ) > -1 || ProcessMsg_connect.find ( "STATE: phase1 up", 0 , FALSE ) > -1 ) + { + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon ) + { + GlobalConfig->appendLogEntry ( "[racoon] " + i18n ( "IPSec phase 1 established." ), GlobalConfig->info ); + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { + GlobalConfig->appendLogEntry ( "[racoon] " + i18n ( "Low level IPsec phase 1 established." ), GlobalConfig->info ); + } + racoon_tunnel_state=1; + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon && GlobalConfig->currentProfile->getUseLeftSourceIp()) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Adding virtual IP address" ), GlobalConfig->debug ); + doAddRemoveVirtualIp("add"); + } + doPingKickupTunnel(); + } + else if ( ProcessMsg_connect.find ( "IPsec-SA established", 0 , FALSE ) > -1 ) + { + racoon_tunnel_state++; + if ( racoon_tunnel_state== 2 ) + { + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + { + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon ) + { + GlobalConfig->appendLogEntry ( "[racoon] " + i18n ( "IPSec phase 2 established." ), GlobalConfig->info ); + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { + GlobalConfig->appendLogEntry ( "[racoon] " + i18n ( "Low level IPsec phase 2 established." ), GlobalConfig->info ); + } + } + + doIptablesRacoon(); + addRouteRacoon(); + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon ) + { + GlobalConfig->appendLogEntry ( "[racoon] " + i18n ( "Connection established." ), GlobalConfig->success ); + + sec = hour = min = 0; + + GlobalConfig->status = GlobalConfig->connected; + + disconnect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + connect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + durationTimer.start ( 1000, FALSE ); + setGuiStatus ( connected ); + + doIptablesRacoon(); + addRouteRacoon(); + + setFirewallAfterConnect(); + if ( GlobalConfig->currentProfile->getExecuteCmdAfterConnect() ) + executeCommandAfterConnect(); + + if ( GlobalConfig->currentProfile->getUseAdditionalNetworkRoutes() && !GlobalConfig->currentProfile->getAdditionalNetworkRoutes().isEmpty() ) + addAdditionalNetworkRoutes(); + + if ( GlobalConfig->currentProfile->getUseConnectionStatusCheck() ) + { + startConnectionStatusCheck(); + } + } + + } + } + else if ( ProcessMsg_connect.find ( "STATE: phase1 down", 0 , FALSE ) > -1 ) + { + //KMessageBox::error ( this, i18n ( "Phase1 expired, shutting down tunnel..." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Phase1 expired, shutting down tunnel..." ) , GlobalConfig->info ); + abort = true; + } + // if ( pingtest ) { + // // mw->DebugOutput->append( "raw err (pingtest): " + ProcessMsg_connect ); + // if ( ProcessMsg_connect.find( "time=", 0, FALSE ) > -1 ) { + // GlobalConfig->appendLogEntry( "[ping] " + ProcessMsg_connect, GlobalConfig->success ); + // } else if ( ProcessMsg_connect.find( "100 % packet loss", 0, FALSE ) > -1 ) { + // GlobalConfig->appendLogEntry( "[ping err] " + ProcessMsg_connect, GlobalConfig->error ); + // } else { + // if ( ProcessMsg_connect.find( "failed to bind", 0, FALSE ) > -1 ) { + // KMessageBox::error( this, i18n( "Binding interface failed!" ) ); + // GlobalConfig->appendLogEntry( i18n( "Binding interface failed!" ) , GlobalConfig->error ); + // } + // if ( ProcessMsg_connect.find( "Destination Host Unreachable", 0, FALSE ) > -1 ) { + // KMessageBox::error( this, i18n( "Destination host is unreachable!" ) ); + // GlobalConfig->appendLogEntry( i18n( "Destination host is unreachable!" ) , GlobalConfig->error ); + // } + // } + // } + + // binding to port failed + if ( ProcessMsg_connect.find ( "ERROR: failed to bind to address", 0 , FALSE ) > -1 || ProcessMsg_connect.find ( "ERROR: no address could be bound.", 0 , FALSE ) > -1 ) + { + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { + if ( L2tpdProcess != 0 && L2tpdProcess->isRunning() ) + L2tpdProcess->kill(); + } + + QString NameAndPid = Utils ( GlobalConfig ).getNameAndPidOfProgramListen ( 500 ); + GlobalConfig->appendLogEntry ( i18n ( "NameAndPid: %1" ).arg ( NameAndPid ) , GlobalConfig->debug ); + int pid = -1; + QString Name = ""; + if ( !NameAndPid.isEmpty() ) + { + pid = NameAndPid.section ( '/', 0, 0 ).toInt(); + Name = NameAndPid.section ( '/', 1, 1 ); + + if ( Name == "racoon" ) + { + + //RacoonProcess->setCommunication ( QProcess::Stdin | QProcess::Stdout | QProcess::Stderr | QProcess::DupStderr ); +// disconnect ( RacoonProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_racoon() ) ); +// disconnect ( RacoonProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_racoon() ) ); + + if ( GlobalConfig->doKillRacoonIfStillRunning && abort == false ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "%1 could not bind too port, tring to kill it...." ).arg ( "racoon" ) , GlobalConfig->error ); + + QProcess killracoonprocess ( this ); + killracoonprocess.addArgument ( GlobalConfig->pathToKillall ); + killracoonprocess.addArgument ( "racoon" ); + + if ( !killracoonprocess.start() ) + { + GlobalConfig->appendLogEntry ( i18n ( "%1 could not be killed." ).arg ( "racoon" ) , GlobalConfig->error ); + GlobalConfig->appendLogEntry ( QString ( "[racoon err] " + i18n ( "Bind to given port has been failed. Another %1 process is running. Please stop %1 first." ).arg ( "racoon" ) ) , GlobalConfig->error ); + abort = true; + } + else + { + while ( killracoonprocess.isRunning() ) + { + // parent->processEvents(); + usleep ( 500 ); + } + sleep ( 2 ); + + // restart racoon + // if ( RacoonProcess != 0) + // RacoonProcess->kill(); + + + putenv ( ( char* ) ( "LC_ALL=C" ) ); + RacoonProcess = new QProcess ( this ); + RacoonProcess->addArgument ( GlobalConfig->pathToRacoon ); + RacoonProcess->addArgument ( "-F" ); // foreground we want :) +// RacoonProcess->addArgument ( "-v" ); + RacoonProcess->addArgument ( "-f" ); + RacoonProcess->addArgument ( tmpPath + "racoon." + GlobalConfig->currentProfile->getName() + ".conf" ); +// RacoonProcess->addArgument ( "-l" ); // logfile (we get content with tail process) +// RacoonProcess->addArgument ( tmpPath + "racoon." + GlobalConfig->currentProfile->getName() + ".log" ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "racoon: " + GlobalConfig->pathToRacoon + " -f " + tmpPath + "/racoon" + GlobalConfig->currentProfile->getName() + ".conf", GlobalConfig->debug ); + + + //RacoonProcess->setCommunication ( QProcess::Stdin | QProcess::Stdout | QProcess::Stderr | QProcess::DupStderr ); +// connect ( RacoonProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_racoon() ) ); +// connect ( RacoonProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_racoon() ) ); + + if ( !RacoonProcess->start ( env ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "racoon" ), GlobalConfig->error ); + + GlobalConfig->appendLogEntry ( QString ( "[racoon err] " + i18n ( "Bind to given port has been failed. Another %1 process is running. Please stop %1 first." ).arg ( "racoon" ) ) , GlobalConfig->error ); + abort = false; + } + else + { + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { + start_l2tpd(); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "%1 was already running. %2 and %3 are killed and restarted." ).arg ( "racoon" ).arg ( "racoon" ).arg ( "l2tpd" ), GlobalConfig->debug ); + } + else + { + doTailRacoonLog(); + racoonStarted(); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "%1 was already running. It was killed and restarted." ).arg ( "racoon" ), GlobalConfig->debug ); + } + } + } + } + else + { + KMessageBox::error ( this, i18n ( "Binding port %1 failed. Program \"%2\" with PID \"%3\" is using it. You have to stop it first." ).arg ( QString().setNum ( 500 ) ).arg ( Name ).arg ( QString().setNum ( pid ) ) ); + GlobalConfig->appendLogEntry ( i18n ( "Port binding failed" ) , GlobalConfig->error ); + abort = true; + } + } + else + { + KMessageBox::error ( this, i18n ( "Binding port %1 failed. Program \"%2\" with PID \"%3\" is using it. You have to stop it first." ).arg ( QString().setNum ( 500 ) ).arg ( Name ).arg ( QString().setNum ( pid ) ) ); + abort = true; + } + } + else + { + KMessageBox::error ( this, i18n ( "Port binding failed" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Port binding failed" ) , GlobalConfig->error ); + abort = true; + } + + } + + + if ( abort ) + { + GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "racoon" ) , GlobalConfig->error ); + disconnectClicked(); + } + + + // } + } +} + +void KVpnc::readFromStderr_racoon() +{ + bool abort = false; +// QString ProcessMsg_connect = QString ( RacoonProcess->readStderr() ); +// if (ProcessMsg_connect.length() ==0) +// return; + while ( RacoonProcess != 0L && RacoonProcess->canReadLineStderr() ) + { + ProcessMsg_connect = RacoonProcess->readLineStderr(); + + GlobalConfig->appendLogEntry ( "[racoon err raw] " + ProcessMsg_connect, GlobalConfig->error ); + + + // binding to port failed + if ( ProcessMsg_connect.find ( "ERROR: failed to bind to address", 0 , FALSE ) > -1 || ProcessMsg_connect.find ( "ERROR: no address could be bound.", 0 , FALSE ) > -1 ) + { + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { + if ( L2tpdProcess != 0 && L2tpdProcess->isRunning() ) + L2tpdProcess->kill(); + } + + QString NameAndPid = Utils ( GlobalConfig ).getNameAndPidOfProgramListen ( 500 ); + GlobalConfig->appendLogEntry ( i18n ( "NameAndPid: %1" ).arg ( NameAndPid ) , GlobalConfig->debug ); + int pid = -1; + QString Name = ""; + if ( !NameAndPid.isEmpty() ) + { + pid = NameAndPid.section ( '/', 0, 0 ).toInt(); + Name = NameAndPid.section ( '/', 1, 1 ); + + if ( Name == "racoon" ) + { + + //RacoonProcess->setCommunication ( QProcess::Stdin | QProcess::Stdout | QProcess::Stderr | QProcess::DupStderr ); +// disconnect ( RacoonProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_racoon() ) ); +// disconnect ( RacoonProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_racoon() ) ); + + if ( GlobalConfig->doKillRacoonIfStillRunning && abort == false ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "%1 could not bind too port, tring to kill it...." ).arg ( "racoon" ) , GlobalConfig->error ); + + QProcess killracoonprocess ( this ); + killracoonprocess.addArgument ( GlobalConfig->pathToKillall ); + killracoonprocess.addArgument ( "racoon" ); + + if ( !killracoonprocess.start() ) + { + GlobalConfig->appendLogEntry ( i18n ( "%1 could not be killed." ).arg ( "racoon" ) , GlobalConfig->error ); + GlobalConfig->appendLogEntry ( QString ( "[racoon err] " + i18n ( "Bind to given port has been failed. Another %1 process is running. Please stop %1 first." ).arg ( "racoon" ) ) , GlobalConfig->error ); + abort = true; + } + else + { + while ( killracoonprocess.isRunning() ) + { + // parent->processEvents(); + usleep ( 500 ); + } + sleep ( 2 ); + + // restart racoon + // if ( RacoonProcess != 0) + // RacoonProcess->kill(); + + + putenv ( ( char* ) ( "LC_ALL=C" ) ); + RacoonProcess = new QProcess ( this ); + RacoonProcess->addArgument ( GlobalConfig->pathToRacoon ); + RacoonProcess->addArgument ( "-F" ); // foreground we want :) +// RacoonProcess->addArgument ( "-v" ); + RacoonProcess->addArgument ( "-f" ); + RacoonProcess->addArgument ( tmpPath + "racoon." + GlobalConfig->currentProfile->getName() + ".conf" ); +// RacoonProcess->addArgument ( "-l" ); // logfile (we get content with tail process) +// RacoonProcess->addArgument ( tmpPath + "racoon." + GlobalConfig->currentProfile->getName() + ".log" ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "racoon: " + GlobalConfig->pathToRacoon + " -f " + tmpPath + "/racoon" + GlobalConfig->currentProfile->getName() + ".conf", GlobalConfig->debug ); + + + //RacoonProcess->setCommunication ( QProcess::Stdin | QProcess::Stdout | QProcess::Stderr | QProcess::DupStderr ); +// connect ( RacoonProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_racoon() ) ); +// connect ( RacoonProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_racoon() ) ); + + if ( !RacoonProcess->start ( env ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "racoon" ), GlobalConfig->error ); + + GlobalConfig->appendLogEntry ( QString ( "[racoon err] " + i18n ( "Bind to given port has been failed. Another %1 process is running. Please stop %1 first." ).arg ( "racoon" ) ) , GlobalConfig->error ); + abort = false; + } + else + { + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { + start_l2tpd(); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "%1 was already running. %2 and %3 are killed and restarted." ).arg ( "racoon" ).arg ( "racoon" ).arg ( "l2tpd" ), GlobalConfig->debug ); + } + else + { + doTailRacoonLog(); + racoonStarted(); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "%1 was already running. It was killed and restarted." ).arg ( "racoon" ), GlobalConfig->debug ); + } + } + } + } + else + { + KMessageBox::error ( this, i18n ( "Binding port %1 failed. Program \"%2\" with PID \"%3\" is using it. You have to stop it first." ).arg ( QString().setNum ( 500 ) ).arg ( Name ).arg ( QString().setNum ( pid ) ) ); + GlobalConfig->appendLogEntry ( i18n ( "Port binding failed" ) , GlobalConfig->error ); + abort = true; + } + } + else + { + KMessageBox::error ( this, i18n ( "Binding port %1 failed. Program \"%2\" with PID \"%3\" is using it. You have to stop it first." ).arg ( QString().setNum ( 500 ) ).arg ( Name ).arg ( QString().setNum ( pid ) ) ); + abort = true; + } + } + else + { + KMessageBox::error ( this, i18n ( "Port binding failed" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Port binding failed" ) , GlobalConfig->error ); + abort = true; + } + + } + else if ( ProcessMsg_connect.find ( "ERROR: fatal BAD-PROPOSAL-SYNTAX", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Bad proposal from peer reported." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Bad proposal from peer reported, aborting." ) , GlobalConfig->error ); + + abort = true; + } + else if ( ProcessMsg_connect.find ( "ERROR: fatal BAD-PROPOSAL-SYNTAX", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Bad proposal from peer reported." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Bad proposal from peer reported, aborting." ) , GlobalConfig->error ); + + abort = true; + } + else if ( ProcessMsg_connect.find ( "ERROR: couldn't find the pskey for", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "The pre shared key couldn't not found, check PSK settings." ) ); + GlobalConfig->appendLogEntry ( i18n ( "PSK is missing, aborting." ) , GlobalConfig->error ); + + abort = true; + } + else if ( ProcessMsg_connect.find ( "ERROR: failed to process packet.", 0 , FALSE ) > -1 ) + { + // KMessageBox::error( this, i18n( "failed to process packet" ) ); + GlobalConfig->appendLogEntry ( i18n ( "failed to process packet" ) , GlobalConfig->error ); + + abort = true; + } + else if ( ProcessMsg_connect.find ( "ERROR: phase1 negotiation failed.", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Phase 1 negotiation of IPSec connection has been failed. Please check encryption and hash algorithm." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Phase 1 negotiation of IPSec connection has been failed." ) , GlobalConfig->error ); + + abort = true; + } + else if ( ProcessMsg_connect.find ( "ERROR: delete phase1 handle.", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Phase 1 negotiation of IPSec connection has been failed. Please check encryption of phase 1 and hash algorithm." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Phase 1 negotiation of IPSec connection has been failed. Please check encryption of phase 1 and hash algorithm." ) , GlobalConfig->error ); + + abort = true; + } + else if ( ProcessMsg_connect.find ( "ERROR: none message must be encrypted", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Phase 1 negotiation of IPSec connection has been failed. Please check encryption of phase 1 and hash algorithm." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Phase 1 negotiation of IPSec connection has been failed. Please check encryption of phase 1 and hash algorithm." ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( "ERROR: reject the packet, received unexpecting payload type 0", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Phase 1 negotiation of IPSec connection has been failed. Please check encryption and hash algorithm." ) ); + GlobalConfig->appendLogEntry ( i18n ( "ERROR: reject the packet, received unexpecting payload type 0" ) , GlobalConfig->error ); + + abort = true; + } + else if ( ProcessMsg_connect.find ( "ERROR: unknown notify message", 0 , FALSE ) > -1 ) + { + // KMessageBox::error( this, i18n( "ERROR: unknown notify message, no phase2 handle found. " ) ); + GlobalConfig->appendLogEntry ( i18n ( "ERROR: unknown notify message, no phase2 handle found. " ) , GlobalConfig->error ); + + abort = true; + } + else if ( ProcessMsg_connect.find ( "ERROR: phase2 negotiation failed due to time up waiting for phase1", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Phase 2 negotiation of IPSec connection has been failed. Please check encryption and hash algorithm." ) ); + GlobalConfig->appendLogEntry ( i18n ( "ERROR: phase2 negotiation failed due to time up waiting for phase1" ) , GlobalConfig->error ); + + abort = true; + } + else if ( ProcessMsg_connect.find ( "ERROR: the peer's certificate is not verified", 0 , FALSE ) > -1 ) + { + // KMessageBox::error( this, i18n( "ERROR: the peer's certificate is not verified" ) ); + GlobalConfig->appendLogEntry ( i18n ( "ERROR: the peer's certificate is not verified" ) , GlobalConfig->error ); + + abort = true; + } + else if ( ProcessMsg_connect.find ( "ignore information because ISAKMP-SAhas not been established yet.", 0 , FALSE ) > -1 || ProcessMsg_connect.find ( "ignore information because ISAKMP-SA has not been established yet.", 0 , FALSE ) > -1 ) + { + //KMessageBox::error( this, i18n( "ERROR: fatal parse failure" ) ); + KMessageBox::error ( this, i18n ( "Phase 2 negotiation of IPSec connection has been failed. Please check encryption and hash algorithm." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Phase 2 negotiation of IPSec connection has been failed. Please check encryption and hash algorithm." ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( "has weak file permission", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Wrong file permission. Aborting." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Wrong file permission. Aborting." ) , GlobalConfig->error ); + + abort = true; + } + else if ( ProcessMsg_connect.find ( "IPsec-SA established", 0 , FALSE ) > -1 ) + { + racoon_tunnel_state++; + if ( racoon_tunnel_state== 1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( "[racoon] " + i18n ( "First tunnel is now up, waiting for second one..." ), GlobalConfig->debug ); + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon && GlobalConfig->currentProfile->getUseLeftSourceIp()) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Adding virtual IP address" ), GlobalConfig->debug ); + doAddRemoveVirtualIp("add"); + } + doPingKickupTunnel(); + } + else if ( racoon_tunnel_state== 2 ) + { + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( "[racoon] " + i18n ( "Second tunnel is now up." ), GlobalConfig->debug ); + GlobalConfig->appendLogEntry ( "[racoon] " + i18n ( "Low level IPsec connection established." ), GlobalConfig->success ); + + doIptablesRacoon(); + addRouteRacoon(); + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon ) + { + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + { + GlobalConfig->appendLogEntry ( "[racoon] " + i18n ( "IPSec phase 2 established." ), GlobalConfig->info ); + } + + GlobalConfig->appendLogEntry ( "[racoon] " + i18n ( "Connection established." ), GlobalConfig->success ); + + sec = hour = min = 0; + + GlobalConfig->status = GlobalConfig->connected; + + disconnect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + connect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + durationTimer.start ( 1000, FALSE ); + setGuiStatus ( connected ); + + doIptablesRacoon(); + addRouteRacoon(); + + setFirewallAfterConnect(); + if ( GlobalConfig->currentProfile->getExecuteCmdAfterConnect() ) + executeCommandAfterConnect(); + + if ( GlobalConfig->currentProfile->getUseAdditionalNetworkRoutes() && !GlobalConfig->currentProfile->getAdditionalNetworkRoutes().isEmpty() ) + addAdditionalNetworkRoutes(); + + if ( GlobalConfig->currentProfile->getUseConnectionStatusCheck() ) + { + startConnectionStatusCheck(); + } + } + + } + } + else if ( ProcessMsg_connect.find ( "no default route, %defaultroute cannot cope!!!", 0, FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "No default route found, nesessary for %1!" ).arg ( IpsecType ) ); + GlobalConfig->appendLogEntry ( i18n ( "No default route found, nesessary for %1!" ).arg ( IpsecType ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( "SIOCADDRT: File exists", 0, FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( "[racoon err] " + i18n ( "setting route failed: route still exists" ), GlobalConfig->error ); + } + else if ( ProcessMsg_connect.find ( "SIOCDELRT: File exists", 0, FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( "[racoon err] " + i18n ( "deleting route failed: route dont exists" ), GlobalConfig->error ); + } + else if ( ProcessMsg_connect.find ( "fatal parse failure", 0, FALSE ) > -1 || ProcessMsg_connect.find ( "failed to parse configuration file", 0, FALSE ) > -1 || ProcessMsg_connect.find ( "fatal parse failure", 0, FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Error in generated configuration file for \"%1\", please contact KVpnc team." ).arg ( "racoon" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Error in generated configuration file for \"%1\", please contact KVpnc team." ).arg ( "racoon" ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( "ERROR: ", 0 , FALSE ) > -1 && ProcessMsg_connect.find ( "algorithm mismatched", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Algorithm mismatched, please select another one." ) ); + GlobalConfig->appendLogEntry ( i18n ( "[racoon err]: algorithm mismatched, please select another one." ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( "Error: Peer not responding", 0 , FALSE ) > -1 ) + { + //KMessageBox::error ( this, i18n ( "racoonctl: Peer not responding" ) ); + GlobalConfig->appendLogEntry ( i18n ( "racoonctl: Peer not responding" ) , GlobalConfig->error ); + abort =true; + } + // if ( pingtest ) { + // // mw->DebugOutput->append( "raw err (pingtest): " + ProcessMsg_connect ); + // if ( ProcessMsg_connect.find( "time=", 0, FALSE ) > -1 ) { + // GlobalConfig->appendLogEntry( "[ping] " + ProcessMsg_connect, GlobalConfig->success ); + // } else if ( ProcessMsg_connect.find( "100 % packet loss", 0, FALSE ) > -1 ) { + // GlobalConfig->appendLogEntry( "[ping err] " + ProcessMsg_connect, GlobalConfig->error ); + // } else { + // if ( ProcessMsg_connect.find( "failed to bind", 0, FALSE ) > -1 ) { + // KMessageBox::error( this, i18n( "Binding interface failed!" ) ); + // GlobalConfig->appendLogEntry( i18n( "Binding interface failed!" ) , GlobalConfig->error ); + // } + // if ( ProcessMsg_connect.find( "Destination Host Unreachable", 0, FALSE ) > -1 ) { + // KMessageBox::error( this, i18n( "Destination host is unreachable!" ) ); + // GlobalConfig->appendLogEntry( i18n( "Destination host is unreachable!" ) , GlobalConfig->error ); + // } + // } + // } + + if ( abort ) + { + GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "racoon" ) , GlobalConfig->error ); + disconnectClicked(); + } + + } +} + +void KVpnc::readFromStdout_racoon_helper() +{ + while ( RacoonHelperProcess && RacoonHelperProcess->canReadLineStdout() ) + { + ProcessMsg_connect = RacoonHelperProcess->readLineStdout(); + // QString ProcessMsg_connect = QString ( RacoonHelperProcess->readStdout() ); + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( "[racoon helper] " + ProcessMsg_connect, GlobalConfig->debug ); + } +} + +void KVpnc::readFromStderr_racoon_helper() +{ + + bool abort = false; + while ( RacoonHelperProcess && RacoonHelperProcess->canReadLineStderr() ) + { + ProcessMsg_connect = RacoonHelperProcess->readLineStderr(); +// QString ProcessMsg_connect = QString ( RacoonHelperProcess->readStderr() ); + GlobalConfig->appendLogEntry ( "[racoon helper err] " + ProcessMsg_connect, GlobalConfig->error ); + + bool wrong_algo=false; + + if ( ProcessMsg_connect.find ( "libipsec: syntax error while parsing", 0, FALSE ) > -1 && !wrong_algo ) + { + KMessageBox::error ( this, i18n ( "Error in generated configuration file for \%1\", please contact KVpnc team." ).arg ( "setkey" ) ); + GlobalConfig->appendLogEntry ( i18n ( "libipsec has found syntax error while parsing." ) , GlobalConfig->error ); + abort = true; + } +// if ( ProcessMsg_connect.find ( "algorithm mismatched") > -1) +// { +// KMessageBox::error ( this, i18n ( "Algorithms mismatched. Please select other values for authentication and encryption." ).arg ( "setkey" ) ); +// GlobalConfig->appendLogEntry ( i18n ( "Algorithms mismatched. Please select other values for authentication and encryption." ) , GlobalConfig->error ); +// wrong_algo = true; +// abort = true; +// } + if ( ProcessMsg_connect.find ( "invalid IP address") > -1) + { + KMessageBox::error ( this, i18n ( "invalid IP address" ).arg ( "setkey" ) ); + GlobalConfig->appendLogEntry ( i18n ( "invalid IP address" ) , GlobalConfig->error ); + wrong_algo = true; + abort = true; + } + if ( abort ) + { + GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "racoon" ) , GlobalConfig->error ); + disconnectClicked(); + } + } +} + +void KVpnc::readFromStdout_ipsec() +{ + if ( IpsecStartProcess == NULL ) + return; + while ( IpsecStartProcess != 0 && IpsecStartProcess->canReadLineStdout() ) + { + ProcessMsg_connect = IpsecStartProcess->readLineStdout(); + // QString ProcessMsg_connect = QString( IpsecStartProcess->readStdout() ); + + bool NormalMsg = true; + bool ErrorMsg = false; + bool abort = false; + + if ( pingtest ) + { + // if ( GlobalConfig->KvpncDebugLevel > 0 ) + // mw->DebugOutput->append( "raw out (pingtest): " + ProcessMsg_connect ); + + if ( ProcessMsg_connect.find ( "time=", 0, FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( "[ping] " + ProcessMsg_connect, GlobalConfig->success ); + } + else if ( ProcessMsg_connect.find ( "100 % packet loss", 0, FALSE ) > -1 ) + { + NormalMsg = false; + GlobalConfig->appendLogEntry ( "[ping err] " + ProcessMsg_connect, GlobalConfig->error ); + } + else + { + if ( ProcessMsg_connect.find ( "Destination Host Unreachable", 0, FALSE ) > -1 ) + { + NormalMsg = false; + KMessageBox::error ( this, i18n ( "Destination host is unreachable!" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Destination host is unreachable!" ), GlobalConfig->error ); + } + } + } + else + { + // FATAL ERROR: + if ( ProcessMsg_connect.find ( "failed to bind", 0, FALSE ) > -1|| ProcessMsg_connect.find ( "Address already in use", 0, FALSE ) > -1 ) + { + QString NameAndPid = Utils ( GlobalConfig ).getNameAndPidOfProgramListen ( 500 ); + GlobalConfig->appendLogEntry ( i18n ( "NameAndPid: %1" ).arg ( NameAndPid ) , GlobalConfig->debug ); + int pid = -1; + QString Name = ""; + if ( !NameAndPid.isEmpty() ) + { + pid = NameAndPid.section ( '/', 0, 0 ).toInt(); + Name = NameAndPid.section ( '/', 1, 1 ); + KMessageBox::error ( this, i18n ( "Binding port %1 failed. Program \"%2\" with PID \"%3\" is using it. You have to stop it first." ).arg ( QString().setNum ( 500 ) ).arg ( Name ).arg ( QString().setNum ( pid ) ) ); + } + else + KMessageBox::error ( this, i18n ( "Port binding failed" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Port binding failed" ) , GlobalConfig->error ); + abort = true; + IpsecGotError = true; + IpsecWhackStatusTimer.stop(); + } + + else if ( ProcessMsg_connect.find ( "error fetching interface information: Device not found", 0, FALSE ) > -1 ) + { + QString interfacemissing = ProcessMsg_connect.section(" ", 1,1).replace(':', ""); + KMessageBox::error ( this, i18n ( "Specified network device (%1) does not exist. Please specifiy an existing device or default at settings." ).arg(interfacemissing) ); + GlobalConfig->appendLogEntry ( i18n ( "Specified network device (%1) does not exist. Please specifiy an existing device or default at settings." ).arg(interfacemissing) , GlobalConfig->error ); + abort = true; + IpsecGotError = true; + IpsecWhackStatusTimer.stop(); + } + else if ( ProcessMsg_connect.find ( "apparently already active", 0 , FALSE ) > -1 || ProcessMsg_connect.find ( "ipsec_setup: Openswan IPsec apparently already active, start aborted", 0 , FALSE ) > -1 ) + { + // KMessageBox::error ( this, i18n ( "Unsupported card found. Please use a smartcard with openct support. This is a Openswan limitation, sorry." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Openswan seems still running, restart it." ) , GlobalConfig->info ); + // abort = true; + startStopIpsec ( true ); + sleep ( 5 ); + startStopIpsec(); + if ( !IpsecGotError) + ipsecStarted(); + } + + else if ( ProcessMsg_connect.find ( "no default route, %defaultroute cannot cope!!!", 0, FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "No default route found, nesessary for %1!" ).arg ( IpsecType ) ); + GlobalConfig->appendLogEntry ( i18n ( "No default route found, nessesary for %1!" ).arg ( IpsecType ) , GlobalConfig->error ); + abort = true; + ErrorMsg = true; + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( "[ipsec start] " + ProcessMsg_connect, GlobalConfig->debug ); + } + } + + // normal + if ( NormalMsg ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( "[ipsec] " + ProcessMsg_connect, GlobalConfig->debug ); + // if (GlobalConfig->KvpncDebugLevel > 0) + // GlobalConfig->appendLogEntry( "out: " + ProcessMsg_connect, GlobalConfig->debug ); + } + else if ( ErrorMsg ) + { + GlobalConfig->appendLogEntry ( "[ipsec err] " + ProcessMsg_connect, GlobalConfig->error ); + } + + if ( abort ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "ipsec" ) , GlobalConfig->debug ); + disconnectClicked(); + GlobalConfig->status = GlobalConfig->disconnected; + setGuiStatus ( disconnected ); + return ; + } + } +} + +void KVpnc::readFromStderr_ipsec() +{ + bool abort = false; + if ( IpsecStartProcess == NULL ) + return; + while ( IpsecStartProcess->canReadLineStderr() ) + { + ProcessMsg_connect = IpsecStartProcess->readLineStderr(); + // QString ProcessMsg_connect = QString( IpsecStartProcess->readStderr() ); + + if ( ProcessMsg_connect.find ( "failed to bind", 0, FALSE ) > -1|| ProcessMsg_connect.find ( "FATAL ERROR: bind() failed in find_raw_ifaces(). Errno 98: Address already in use", 0, FALSE ) > -1 ) + { + QString NameAndPid = Utils ( GlobalConfig ).getNameAndPidOfProgramListen ( 500 ); + GlobalConfig->appendLogEntry ( i18n ( "NameAndPid: %1" ).arg ( NameAndPid ) , GlobalConfig->debug ); + int pid = -1; + QString Name = ""; + if ( !NameAndPid.isEmpty() ) + { + pid = NameAndPid.section ( '/', 0, 0 ).toInt(); + Name = NameAndPid.section ( '/', 1, 1 ); + KMessageBox::error ( this, i18n ( "Binding port %1 failed. Program \"%2\" with PID \"%3\" is using it. You have to stop it first." ).arg ( QString().setNum ( 500 ) ).arg ( Name ).arg ( QString().setNum ( pid ) ) ); + } + else + KMessageBox::error ( this, i18n ( "Port binding failed" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Port binding failed" ) , GlobalConfig->error ); + abort = true; + IpsecGotError = true; + IpsecWhackStatusTimer.stop(); + } + else if ( ProcessMsg_connect.find ( "no default route, %defaultroute cannot cope!!!", 0, FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "No default route found, nesessary for %1!" ).arg ( IpsecType ) ); + GlobalConfig->appendLogEntry ( i18n ( "No default route found, nesessary for %1!" ).arg ( IpsecType ) , GlobalConfig->error ); + abort = true; + IpsecGotError = true; + IpsecWhackStatusTimer.stop(); + } + else if ( ProcessMsg_connect.find ( "SIOCADDRT: File exists", 0, FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( "[ipsec err] "+i18n ( "setting route failed: route still exists" ), GlobalConfig->error ); + // abort=true; + } + else if ( ProcessMsg_connect.find ( "SIOCDELRT: File exists", 0, FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( "[ipsec err] " + i18n ( "deleting route failed: route dont exists" ), GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( "we only support version 2", 0, FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( "[ipsec err] " + i18n ( "only version 2.x is supported " ), GlobalConfig->error ); + abort = true; + IpsecGotError = true; + IpsecWhackStatusTimer.stop(); + } + else if ( ProcessMsg_connect.find ( "error loading RSA private key file", 0, FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( "[ipsec err] " + i18n ( "RSA private key file could not be loaded." ), GlobalConfig->error ); + abort = true; + IpsecGotError = true; + IpsecWhackStatusTimer.stop(); + } + else if ( ProcessMsg_connect.find ( "unable to start strongSwan -- fatal errors in config", 0, FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Unable to start strongSwan -- fatal errors in config. Please contact the KVpnc author." ) ); + GlobalConfig->appendLogEntry ( "[ipsec err] " + i18n ( "Unable to start strongSwan -- fatal errors in config. Please contact the KVpnc author." ), GlobalConfig->error ); + abort = true; + IpsecGotError = true; + IpsecWhackStatusTimer.stop(); + } + else if ( ProcessMsg_connect.find ( "Starting strongSwan", 0, FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( "[ipsec] " + ProcessMsg_connect, GlobalConfig->info ); + } + else if ( ProcessMsg_connect.find ( "apparently already active", 0 , FALSE ) > -1 || ProcessMsg_connect.find ( "Openswan IPsec apparently already active, start aborted", 0 , FALSE ) > -1 ) + { +// KMessageBox::error ( this, i18n ( "Unsupported card found. Please use a smartcard with openct support. This is a Openswan limitation, sorry." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Openswan seems still running, restart it." ) , GlobalConfig->error ); +// abort = true; + startStopIpsec ( true ); + sleep ( 5 ); + startStopIpsec(); + if ( !IpsecGotError) + ipsecStarted(); + } + else if ( pingtest ) + { + // mw->DebugOutput->append( "raw err (pingtest): " + ProcessMsg_connect ); + if ( ProcessMsg_connect.find ( "time=", 0, FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( "[ping] " + ProcessMsg_connect, GlobalConfig->success ); + } + else if ( ProcessMsg_connect.find ( "100 % packet loss", 0, FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( "[ping err] " + ProcessMsg_connect, GlobalConfig->error ); + } + else + { + if ( ProcessMsg_connect.find ( "failed to bind", 0, FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Binding interface failed!" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Binding interface failed!" ) , GlobalConfig->error ); + } + if ( ProcessMsg_connect.find ( "Destination Host Unreachable", 0, FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Destination host is unreachable!" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Binding interface failed!" ) , GlobalConfig->error ); + } + } + } + else + { + GlobalConfig->appendLogEntry ( "[ipsec err] " + ProcessMsg_connect, GlobalConfig->error ); + } + + if ( abort ) + { + GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "l2tpd" ) , GlobalConfig->error ); + disconnectClicked(); + GlobalConfig->status = GlobalConfig->disconnected; + setGuiStatus ( disconnected ); + return ; + } + } +} + +void KVpnc::readFromStdout_ipsecwhack() +{ + while ( IpsecWhackProcess->canReadLineStdout() ) + { + ProcessMsg_connect = IpsecWhackProcess->readLineStdout(); + // QString ProcessMsg_connect = QString( IpsecWhackProcess->readStdout() ); + + bool NormalMsg = true; + bool ErrorMsg = false; + bool abort = false; + + if ( ProcessMsg_connect.find ( "encountered fatal error in state STATE_XAUTH", 0 , FALSE ) > -1 ) + { + // xauth failed openswan + ErrorMsg=true; + KMessageBox::error ( this, i18n ( "Authentication failed (%1)!" ).arg ( i18n ( "XAUTH" ) ) ); + GlobalConfig->appendLogEntry ( i18n ( "Authentication failed (%1)!" ).arg ( i18n ( "XAUTH" ) ) , GlobalConfig->error ); + AuthRetry = true; + GlobalConfig->haveUserData = false; + disconnectClicked(); + connectClicked(); + } + else if ( ProcessMsg_connect.find ( "extended authentication failed", 0 , FALSE ) > -1 || ( GlobalConfig->WaitingForXauth==true && ProcessMsg_connect.find ( "expected ISAKMP_CFG_SET, got ISAKMP_CFG_REQUEST", 0 , FALSE ) > -1 ) ) + { + // xauth failed strongswan + KMessageBox::error ( this, i18n ( "Authentication failed (%1)!" ).arg ( i18n ( "XAUTH" ) ) ); + GlobalConfig->appendLogEntry ( i18n ( "Authentication failed (%1)!" ).arg ( i18n ( "XAUTH" ) ) , GlobalConfig->error ); + AuthRetry = true; + GlobalConfig->haveUserData = false; + disconnectClicked(); + connectClicked(); + } + else if ( ProcessMsg_connect.find ( "Can't authenticate: no preshared key found", 0 , FALSE ) > -1 ) + { + ErrorMsg=true; + abort=true; + KMessageBox::error ( this, i18n ( "Preshared key not found for connection." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Preshared key not found for connection." ) , GlobalConfig->error ); + } + else if ( ProcessMsg_connect.find ( "prompt for Username:", 0 , FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "XAUTH username requested, send it..." ) , GlobalConfig->debug ); + + if ( GlobalConfig->KvpncDebugLevel > 5 ) + GlobalConfig->appendLogEntry ( i18n ( "XAUTH username: %1" ).arg ( GlobalConfig->TmpUsername ) , GlobalConfig->debug ); + + IpsecWhackProcess->writeToStdin ( GlobalConfig->TmpUsername+"\n" ); + } + else if ( ProcessMsg_connect.find ( "prompt for Password:", 0 , FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "XAUTH password requested, send it..." ) , GlobalConfig->debug ); + if ( GlobalConfig->KvpncDebugLevel > 5 ) + GlobalConfig->appendLogEntry ( i18n ( "XAUTH password: %1" ).arg ( GlobalConfig->TmpPassword ) , GlobalConfig->debug ); + + IpsecWhackProcess->writeToStdin ( GlobalConfig->TmpPassword+"\n" ); + } + else if ( ProcessMsg_connect.find ( "listening for IKE messages", 0 , FALSE ) > -1 ) + { + // strongswan after ipsec whack --listen + /* disconnect ( IpsecWhackProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_ipsecwhack() ) ); + disconnect ( IpsecWhackProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsecwhack() ) ); + delete(IpsecWhackProcess);*/ + putenv ( ( char* ) ( "LC_ALL=C" ) ); + IpsecWhackProcess = new QProcess ( this ); + IpsecWhackProcess->addArgument ( GlobalConfig->pathToIpsec ); + IpsecWhackProcess->addArgument ( "whack" ); + IpsecWhackProcess->addArgument ( "--name" ); + IpsecWhackProcess->addArgument ( GlobalConfig->currentProfile->getName() ); + IpsecWhackProcess->addArgument ( "--initiate" ); + + connect ( IpsecWhackProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_ipsecwhack() ) ); + connect ( IpsecWhackProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsecwhack() ) ); + connect ( IpsecWhackProcess, SIGNAL ( exited() ), this, SLOT ( ipsecwhack_exited() ) ); + + if ( !IpsecWhackProcess->start ( env ) ) + { + disconnect ( IpsecWhackProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_ipsecwhack() ) ); + disconnect ( IpsecWhackProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsecwhack() ) ); + disconnect ( IpsecWhackProcess, SIGNAL ( exited() ), this, SLOT ( ipsecwhack_exited() ) ); + delete IpsecWhackProcess; + IpsecWhackProcess=0L; + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( GlobalConfig->pathToIpsec+" whack' --name "+GlobalConfig->currentProfile->getName() +" --initiate" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( GlobalConfig->pathToIpsec+" whack' --name "+GlobalConfig->currentProfile->getName() +" --initiate" ) , GlobalConfig->error ); + disconnectClicked(); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( GlobalConfig->pathToIpsec+" whack --name "+GlobalConfig->currentProfile->getName() +" --initiate" ), GlobalConfig->debug ); + } + } + else if ( ProcessMsg_connect.find ( "added connection", 0 , FALSE ) > -1 ) + { +// XAUTH + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan && GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) + { + ToolInfo *IpsecToolInfo = Utils ( GlobalConfig ).getToolInfo ( "ipsec" ) ; + if ( IpsecToolInfo->Version.contains ( "Openswan" , false ) ) + { + sleep ( 3 ); + //openswan + putenv ( ( char* ) ( "LC_ALL=C" ) ); + IpsecWhackProcess = new QProcess ( this ); + IpsecWhackProcess->addArgument ( GlobalConfig->pathToIpsec ); + IpsecWhackProcess->addArgument ( "whack" ); + IpsecWhackProcess->addArgument ( "--name" ); + IpsecWhackProcess->addArgument ( GlobalConfig->currentProfile->getName() ); + IpsecWhackProcess->addArgument ( "--initiate" ); + + connect ( IpsecWhackProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_ipsecwhack() ) ); + connect ( IpsecWhackProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsecwhack() ) ); + connect ( IpsecWhackProcess, SIGNAL ( exited() ), this, SLOT ( ipsecwhack_exited() ) ); + + QString LogPassword=""; + if ( GlobalConfig->KvpncDebugLevel > 5 ) + LogPassword=GlobalConfig->TmpPassword; + else + LogPassword="*****"; + if ( !IpsecWhackProcess->start ( env ) ) + { + disconnect ( IpsecWhackProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_ipsecwhack() ) ); + disconnect ( IpsecWhackProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsecwhack() ) ); + disconnect ( IpsecWhackProcess, SIGNAL ( exited() ), this, SLOT ( ipsecwhack_exited() ) ); + delete IpsecWhackProcess; + IpsecWhackProcess=0L; + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( GlobalConfig->pathToIpsec+" whack' --name "+GlobalConfig->currentProfile->getName() +" --initiate" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( GlobalConfig->pathToIpsec+" whack' --name "+GlobalConfig->currentProfile->getName() +" --initiate" ) , GlobalConfig->error ); + disconnectClicked(); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( GlobalConfig->pathToIpsec+" whack --name "+GlobalConfig->currentProfile->getName() +" --initiate" ), GlobalConfig->debug ); + } + } + } + + } + else if ( ProcessMsg_connect.find ( "XAUTH: Successfully Authenticated", 0 , FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( i18n ( "Authentication succeded." ) , GlobalConfig->info ); + } + else if ( ProcessMsg_connect.find ( "parsing XAUTH status", 0 , FALSE ) > -1 ) + { + GlobalConfig->WaitingForXauth=true; + } + else if ( ProcessMsg_connect.find ( "added connection", 0 , FALSE ) > -1 ) + { +// XAUTH + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan && GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) + { + ToolInfo *IpsecToolInfo = Utils ( GlobalConfig ).getToolInfo ( "ipsec" ) ; + if ( IpsecToolInfo->Version.contains ( "Openswan" , false ) ) + { + sleep ( 3 ); + //openswan + putenv ( ( char* ) ( "LC_ALL=C" ) ); + IpsecWhackProcess = new QProcess ( this ); + IpsecWhackProcess->addArgument ( GlobalConfig->pathToIpsec ); + IpsecWhackProcess->addArgument ( "whack" ); + IpsecWhackProcess->addArgument ( "--name" ); + IpsecWhackProcess->addArgument ( GlobalConfig->currentProfile->getName() ); + IpsecWhackProcess->addArgument ( "--initiate" ); + + connect ( IpsecWhackProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_ipsecwhack() ) ); + connect ( IpsecWhackProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsecwhack() ) ); + connect ( IpsecWhackProcess, SIGNAL ( exited() ), this, SLOT ( ipsecwhack_exited() ) ); + + QString LogPassword=""; + if ( GlobalConfig->KvpncDebugLevel > 5 ) + LogPassword=GlobalConfig->TmpPassword; + else + LogPassword="*****"; + if ( !IpsecWhackProcess->start ( env ) ) + { + disconnect ( IpsecWhackProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_ipsecwhack() ) ); + disconnect ( IpsecWhackProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsecwhack() ) ); + disconnect ( IpsecWhackProcess, SIGNAL ( exited() ), this, SLOT ( ipsecwhack_exited() ) ); + delete IpsecWhackProcess; + IpsecWhackProcess=0L; + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( GlobalConfig->pathToIpsec+" whack' --name "+GlobalConfig->currentProfile->getName() +" --initiate" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( GlobalConfig->pathToIpsec+" whack' --name "+GlobalConfig->currentProfile->getName() +" --initiate" ) , GlobalConfig->error ); + disconnectClicked(); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( GlobalConfig->pathToIpsec+" whack --name "+GlobalConfig->currentProfile->getName() +" --initiate" ), GlobalConfig->debug ); + } + } + } + + } + else if ( ProcessMsg_connect.find ( "ISAKMP SA established", 0 , FALSE ) > -1 ) + { + + if (IpsecPhase2Up) + return; + + if (IpsecPhase1Up) + return; + else + IpsecPhase1Up=true; + timer.stop(); + IpsecWhackStatusTimer.stop(); + abort = false; + if (GlobalConfig->KvpncDebugLevel > 1) + { + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan ) + { + GlobalConfig->appendLogEntry ( "[ipsec] " + i18n ( "IPSec phase 1 established." ), GlobalConfig->info ); + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { + GlobalConfig->appendLogEntry ( "[ipsec] " + i18n ( "Low level IPsec phase 1 established." ), GlobalConfig->info ); + } + } + + } + else if ( ProcessMsg_connect.find ( "IPsec SA established", 0 , FALSE ) > -1 ) + { + ipsecPhase2Established(); + } + else if ( ProcessMsg_connect.find ( "XAUTH: Successfully Authenticated", 0 , FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( i18n ( "Authentication succeded." ) , GlobalConfig->info ); + } + else if ( ProcessMsg_connect.find ( "apparently already active", 0 , FALSE ) > -1 ) + { +// KMessageBox::error ( this, i18n ( "Openswan seems still running, restart it." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Openswan seems still running, restart it." ) , GlobalConfig->info ); +// abort = true; + startStopIpsec ( true ); + sleep ( 5 ); + startStopIpsec(); + if ( !IpsecGotError) + ipsecStarted(); + } + else if ( ProcessMsg_connect.find ( "no default route, %defaultroute cannot cope!!!", 0, FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "No default route found, nesessary for %1!" ).arg ( IpsecType ) ); + GlobalConfig->appendLogEntry ( i18n ( "No default route found, nessesary for %1!" ).arg ( IpsecType ) , GlobalConfig->error ); + abort = true; + ErrorMsg = true; + IpsecGotError = true; + IpsecWhackStatusTimer.stop(); + } + else if ( ProcessMsg_connect.find ( "ignoring informational payload, type NO_PROPOSAL_CHOSEN", 0 , FALSE ) > -1 ) + { + if ( !stopContinue ) + { + KMessageBox::error ( this, i18n ( "Wrong connection parameters used. Please verify the connection settings." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Peer reported that we use wrong connection parameters." ) , GlobalConfig->error ); + abort = true; + stopContinue = true; + IpsecGotError = true; + IpsecWhackStatusTimer.stop(); + } + } + else if ( ProcessMsg_connect.find ( "perhaps peer likes no proposal", 0 , FALSE ) > -1 ) + { + if ( !stopContinue ) + { + KMessageBox::error ( this, i18n ( "Wrong connection parameters used. Please verify in IPSec settings." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Peer reported that we use wrong connection parameters." ) , GlobalConfig->error ); + abort = true; + stopContinue = true; + IpsecGotError = true; + IpsecWhackStatusTimer.stop(); + } + } + else if ( ProcessMsg_connect.find ( "INVALID_ID_INFORMATION", 0 , FALSE ) > -1 ) + { + if ( !stopContinue ) + { + KMessageBox::error ( this, i18n ( "Peer refused ID settings. Please verify the local ID in IPsec and remote network in Network - General settings." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Peer refused ID settings. Please verify the local ID in IPsec and remote network in Network - General settings." ) , GlobalConfig->error ); + abort = true; + stopContinue = true; + IpsecGotError = true; + IpsecWhackStatusTimer.stop(); + } + } + else if ( ProcessMsg_connect.find ( "cannot initiate connection with ID wildcards", 0 , FALSE ) > -1 ) + { + if ( !stopContinue ) + { + KMessageBox::error ( this, i18n ( "Cannot initiate connection with ID wildcards. Please verify the connection settings." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Cannot initiate connection with ID wildcards." ) , GlobalConfig->error ); + abort = true; + stopContinue = true; + IpsecGotError = true; + IpsecWhackStatusTimer.stop(); + } + } + else if ( ProcessMsg_connect.find ( "Can not opportunistically initiate", 0 , FALSE ) > -1 ) + { + if ( !stopContinue ) + { + KMessageBox::error ( this, i18n ( "Can not opportunistically initiate. Please verify the connection settings." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Can not opportunistically initiate." ) , GlobalConfig->error ); + abort = true; + stopContinue = true; + IpsecGotError = true; + IpsecWhackStatusTimer.stop(); + } + } + else if ( ProcessMsg_connect.find ( "unable to locate my private key", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Private key could not be found. Please check certificate settings." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Private key could not be found. Please check certificate settings." ) , GlobalConfig->error ); + abort = true; + IpsecGotError = true; + IpsecWhackStatusTimer.stop(); + } + else if ( ProcessMsg_connect.find ( "SMARTCARD support is deactivated in pluto/Makefile", 0 , FALSE ) > -1 || ProcessMsg_connect.find ( "Smartcard not supported", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "SMARTCARD support is deactivated. Please enable smartcard support in %1 package" ).arg ( IpsecType ) ); + GlobalConfig->appendLogEntry ( i18n ( "SMARTCARD support is deactivated. Please enable smartcard support in %1 package" ).arg ( IpsecType ) , GlobalConfig->error ); + abort = true; + IpsecGotError = true; + IpsecWhackStatusTimer.stop(); + } + else if ( ProcessMsg_connect.find ( "Unsupported card", 0 , FALSE ) > -1 && ProcessMsg_connect.find ( "pkcs15", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Unsupported card found. Please use a smartcard with openct support. This is a Openswan limitation, sorry." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Unsupported card found. Please use a smartcard with openct support. This is a Openswan limitation, sorry." ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( "we require peer to have ID", 0 , FALSE ) > -1 && ProcessMsg_connect.find ( "but peer declares", 0 , FALSE ) > -1 ) + { + QString PeerID = ProcessMsg_connect.section ( '\'', 3, 3 ); + QString OurID = ProcessMsg_connect.section ( '\'', 1, 1 ); + KMessageBox::error ( this, i18n ( "Wrong ID \"%1\" from peer got, we expect \"%2\"." ).arg ( PeerID ).arg ( OurID ) ); + GlobalConfig->appendLogEntry ( i18n ( "Wrong ID \"%1\" from peer got, we expect \"%2\"." ).arg ( PeerID ).arg ( OurID ) , GlobalConfig->error ); + int result = KMessageBox::questionYesNo ( this, i18n ( "Do you want to use \"%1\" instead of \"%2\" as remote ID and reconnect?" ).arg ( PeerID ).arg ( OurID ), i18n ( "Fix remote ID?" ) ); + if ( result == 3 ) // Yes + { + disconnectClicked(); + GlobalConfig->currentProfile->setUseSpecialRemoteID ( true ); + GlobalConfig->currentProfile->setSpecialRemoteID ( PeerID ); + GlobalConfig->currentProfile->setRemoteIDType ( "user" ); + saveSessionClicked(); + connectClicked(); + } + else + { + if ( !stopContinue ) + { + + abort = true; + stopContinue = true; + } + } + } + else if ( ProcessMsg_connect.find ( "no connection named", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Connection not found. This seems like the configuration is invalid or too fast connect/disconnect." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Connection not found. This seems like the configuration is invalid or too fast connect/disconnect." ) , GlobalConfig->error ); + abort = true; + IpsecGotError = true; + IpsecWhackStatusTimer.stop(); + } + else if ( ProcessMsg_connect.find ( "deleting state (STATE_QUICK_I1)", 0 , FALSE ) > -1 || ProcessMsg_connect.find ( "deleting state (STATE_MAIN_I3)", 0 , FALSE ) > -1 || ProcessMsg_connect.find ( "deleting state (STATE_MAIN_I2)", 0 , FALSE ) > -1 ) + { + //KMessageBox::error ( this, i18n ( "Phase 1 was deleted. Disconnecting." ).arg ( IpsecType ) ); + GlobalConfig->appendLogEntry ( i18n ( "Phase 1 was deleted. Disconnecting." ).arg ( IpsecType ) , GlobalConfig->error ); + abort = true; + IpsecGotError = true; + IpsecWhackStatusTimer.stop(); + } + + // normal + if ( NormalMsg ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( "[ipsec whack] " + ProcessMsg_connect, GlobalConfig->debug ); + // if (GlobalConfig->KvpncDebugLevel > 0) + // GlobalConfig->appendLogEntry( "out: " + ProcessMsg_connect, GlobalConfig->debug ); + } + else if ( ErrorMsg ) + { + GlobalConfig->appendLogEntry ( "[ipsec whack err] " + ProcessMsg_connect, GlobalConfig->error ); + } + + if ( abort ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "ipsec whack --listen" ) , GlobalConfig->debug ); + disconnectClicked(); + GlobalConfig->status = GlobalConfig->disconnected; + setGuiStatus ( disconnected ); + return ; + } + + } + +} + +void KVpnc::readFromStderr_ipsecwhack() +{ + while ( IpsecWhackProcess->canReadLineStderr() ) + { + bool NormalMsg = true; + bool ErrorMsg = false; + bool abort = false; + + ProcessMsg_connect = IpsecWhackProcess->readLineStderr(); + // QString ProcessMsg_connect = QString( IpsecWhackProcess->readStderr() ); + + + GlobalConfig->appendLogEntry ( "[ipsec whack err] " + ProcessMsg_connect, GlobalConfig->error ); + +// // binding to port failed +// if ( ProcessMsg_connect.find ( "ERROR: failed to bind to address", 0 , FALSE ) > -1 ) +// { + + // if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_ipsec ) + // { + // if (IpsecProcess != 0 && IpsecProcess->isRunning()) + // IpsecProcess->kill(); + // } + // + // if (GlobalConfig->doKillIpsecIfStillRunning) + // { + // QProcess killipsecprocess(this); + // killipsecprocess.addArgument(GlobalConfig->pathToKillall); + // killipsecprocess.addArgument("ipsec"); + // + // if (!killipsecprocess.start()) + // { + // GlobalConfig->appendLogEntry( i18n( "%1 could not be killed." ).arg("ipsec") ,GlobalConfig->error); + // GlobalConfig->appendLogEntry ( QString( "[ipsec err] " + i18n( "Bind to given port has been failed. Another %1 process is running. Please stop %1 first." ).arg("ipsec") ) , GlobalConfig->debug ); + // abort = true; + // } + // else + // { + // while (killipsecprocess.isRunning()) + // parent->processEvents(); +// delete killipsecprocess; +// killipsecprocess=0L; + // + // // restart ipsec + // // if ( IpsecProcess != 0) + // // IpsecProcess->kill(); + // + // putenv( ( char* ) ( "LC_ALL=C" ) ); + // IpsecProcess = new QProcess ( this ); + // IpsecProcess->addArgument( GlobalConfig->pathToIpsec ); + // IpsecProcess->addArgument( "-F" ); // foreground we want :) + // IpsecProcess->addArgument( "-f" ); + // IpsecProcess->addArgument( tmpPath + "ipsec." + GlobalConfig->currentProfile->getName() + ".conf" ); + // IpsecProcess->addArgument( "-l" ); // logfile (we get content with tail process) + // IpsecProcess->addArgument( tmpPath + "ipsec." + GlobalConfig->currentProfile->getName() + ".log" ); + // if ( GlobalConfig->KvpncDebugLevel > 0 ) + // GlobalConfig->appendLogEntry ( "ipsec: " + GlobalConfig->pathToIpsec + " -f " + tmpPath + "/ipsec" + GlobalConfig->currentProfile->getName() + ".conf", GlobalConfig->debug ); + // + // if ( !IpsecProcess->start(env) ) + // { + // if ( GlobalConfig->KvpncDebugLevel > 0 ) + // GlobalConfig->appendLogEntry ( i18n( "\"%1\" start failed!" ).arg( "l2tpd" ), GlobalConfig->error ); + // + // GlobalConfig->appendLogEntry ( QString( "[ipsec err] " + i18n( "Bind to given port has been failed. Another %1 process is running. Please stop %1 first." ).arg("ipsec") ) , GlobalConfig->debug ); + // abort=false; + // } + // else + // { + // if ( GlobalConfig->KvpncDebugLevel > 0 ) + // GlobalConfig->appendLogEntry ( i18n( "%1 was already running. It was killed and restarted." ).arg( "ipsec" ), GlobalConfig->debug ); + // } + // } + // } + // else +// { +// KMessageBox::error ( this, i18n ( "Port binding failed" ) ); +// GlobalConfig->appendLogEntry ( i18n ( "Port binding failed" ) , GlobalConfig->error ); +// abort = true; +// } +// } + + + if ( ProcessMsg_connect.find ( "failed to bind", 0, FALSE ) > -1|| ProcessMsg_connect.find ( "Address already in use", 0, FALSE ) > -1 ) + { + QString NameAndPid = Utils ( GlobalConfig ).getNameAndPidOfProgramListen ( 500 ); + GlobalConfig->appendLogEntry ( i18n ( "NameAndPid: %1" ).arg ( NameAndPid ) , GlobalConfig->debug ); + int pid = -1; + QString Name = ""; + if ( !NameAndPid.isEmpty() ) + { + pid = NameAndPid.section ( '/', 0, 0 ).toInt(); + Name = NameAndPid.section ( '/', 1, 1 ); + KMessageBox::error ( this, i18n ( "Binding port %1 failed. Program \"%2\" with PID \"%3\" is using it. You have to stop it first." ).arg ( QString().setNum ( 500 ) ).arg ( Name ).arg ( QString().setNum ( pid ) ) ); + } + else + KMessageBox::error ( this, i18n ( "Port binding failed" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Port binding failed" ) , GlobalConfig->error ); + abort = true; + } + + else if ( ProcessMsg_connect.find ( "no default route, %defaultroute cannot cope!!!", 0, FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "No default route found, nesessary for %1!" ).arg ( IpsecType ) ); + GlobalConfig->appendLogEntry ( i18n ( "No default route found, nessesary for %1!" ).arg ( IpsecType ) , GlobalConfig->error ); + abort = true; + ErrorMsg = true; + } + else if ( ProcessMsg_connect.find ( "ignoring informational payload, type NO_PROPOSAL_CHOSEN", 0 , FALSE ) > -1 ) + { + if ( !stopContinue ) + { + KMessageBox::error ( this, i18n ( "Wrong connection parameters used. Please verify the connection settings." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Peer reported that we use wrong connection parameters." ) , GlobalConfig->error ); + abort = true; + stopContinue = true; + } + } + else if ( ProcessMsg_connect.find ( "perhaps peer likes no proposal", 0 , FALSE ) > -1 ) + { + if ( !stopContinue ) + { + KMessageBox::error ( this, i18n ( "Wrong connection parameters used. Please verify in IPSec settings." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Peer reported that we use wrong connection parameters." ) , GlobalConfig->error ); + abort = true; + stopContinue = true; + } + } + else if ( ProcessMsg_connect.find ( "INVALID_ID_INFORMATION", 0 , FALSE ) > -1 ) + { + if ( !stopContinue ) + { + KMessageBox::error ( this, i18n ( "Peer refused ID settings. Please verify the local ID in IPsec and remote network in Network - General settings." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Peer refused ID settings. Please verify the local ID in IPsec and remote network in Network - General settings." ) , GlobalConfig->error ); + abort = true; + stopContinue = true; + IpsecGotError = true; + IpsecWhackStatusTimer.stop(); + } + } + else if ( ProcessMsg_connect.find ( "cannot initiate connection with ID wildcards", 0 , FALSE ) > -1 ) + { + if ( !stopContinue ) + { + KMessageBox::error ( this, i18n ( "Cannot initiate connection with ID wildcards. Please verify the connection settings." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Cannot initiate connection with ID wildcards." ) , GlobalConfig->error ); + abort = true; + stopContinue = true; + IpsecGotError = true; + IpsecWhackStatusTimer.stop(); + } + } + else if ( ProcessMsg_connect.find ( "Can not opportunistically initiate", 0 , FALSE ) > -1 ) + { + if ( !stopContinue ) + { + KMessageBox::error ( this, i18n ( "Can not opportunistically initiate. Please verify the connection settings." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Can not opportunistically initiate." ) , GlobalConfig->error ); + abort = true; + stopContinue = true; + IpsecGotError = true; + IpsecWhackStatusTimer.stop(); + } + } + else if ( ProcessMsg_connect.find ( "unable to locate my private key", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Private key could not be found. Please check certificate settings." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Private key could not be found. Please check certificate settings." ) , GlobalConfig->error ); + abort = true; + IpsecGotError = true; + IpsecWhackStatusTimer.stop(); + } + else if ( ProcessMsg_connect.find ( "SMARTCARD support is deactivated in pluto/Makefile", 0 , FALSE ) > -1 || ProcessMsg_connect.find ( "Smartcard not supported", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "SMARTCARD support is deactivated. Please enable smartcard support in %1 package" ).arg ( IpsecType ) ); + GlobalConfig->appendLogEntry ( i18n ( "SMARTCARD support is deactivated. Please enable smartcard support in %1 package" ).arg ( IpsecType ) , GlobalConfig->error ); + abort = true; + IpsecGotError = true; + IpsecWhackStatusTimer.stop(); + } + else if ( ProcessMsg_connect.find ( "Unsupported card", 0 , FALSE ) > -1 && ProcessMsg_connect.find ( "pkcs15", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Unsupported card found. Please use a smartcard with openct support. This is a Openswan limitation, sorry." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Unsupported card found. Please use a smartcard with openct support. This is a Openswan limitation, sorry." ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( "we require peer to have ID", 0 , FALSE ) > -1 && ProcessMsg_connect.find ( "but peer declares", 0 , FALSE ) > -1 ) + { + QString PeerID = ProcessMsg_connect.section ( '\'', 3, 3 ); + QString OurID = ProcessMsg_connect.section ( '\'', 1, 1 ); + KMessageBox::error ( this, i18n ( "Wrong ID \"%1\" from peer got, we expect \"%2\"." ).arg ( PeerID ).arg ( OurID ) ); + GlobalConfig->appendLogEntry ( i18n ( "Wrong ID \"%1\" from peer got, we expect \"%2\"." ).arg ( PeerID ).arg ( OurID ) , GlobalConfig->error ); + int result = KMessageBox::questionYesNo ( this, i18n ( "Do you want to use \"%1\" instead of \"%2\" as remote ID and reconnect?" ).arg ( PeerID ).arg ( OurID ), i18n ( "Fix remote ID?" ) ); + if ( result == 3 ) // Yes + { + disconnectClicked(); + GlobalConfig->currentProfile->setUseSpecialRemoteID ( true ); + GlobalConfig->currentProfile->setSpecialRemoteID ( PeerID ); + GlobalConfig->currentProfile->setRemoteIDType ( "user" ); + saveSessionClicked(); + connectClicked(); + } + else + { + if ( !stopContinue ) + { + + abort = true; + stopContinue = true; + } + } + } + if ( abort ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "ipsec whack --initiate" ) , GlobalConfig->debug ); + disconnectClicked(); + GlobalConfig->status = GlobalConfig->disconnected; + setGuiStatus ( disconnected ); + return ; + } + } +} + +void KVpnc::readFromStdout_ipsecwhacklisten() +{ + if ( IpsecWhackListenProcess == 0 || IpsecGotError ) + return; + while ( IpsecWhackListenProcess->canReadLineStdout() ) + { + ProcessMsg_connect = IpsecWhackListenProcess->readLineStdout(); + // QString ProcessMsg_connect = QString( IpsecWhackListenProcess->readStdout() ); + + bool NormalMsg = true; + bool ErrorMsg = false; + bool abort = false; + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( "[ipsec whack listen] " + ProcessMsg_connect, GlobalConfig->debug ); + + if ( ProcessMsg_connect.find ( "listening for IKE messages", 0 , FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( "[ipsec whack listen] " + i18n ( "Listen was successful." ), GlobalConfig->debug ); + start_ipsec_initiate(); + } + else if ( ProcessMsg_connect.find ( "ISAKMP SA established", 0 , FALSE ) > -1 || ProcessMsg_connect.find ( "transition from state STATE_QUICK_I1 to state STATE_QUICK_I2", 0 , FALSE ) > -1 ) + { + + timer.stop(); + IpsecWhackStatusTimer.stop(); + + if ( IpsecPhase1Up ) + return; + else + IpsecPhase1Up=true; + timer.stop(); + IpsecWhackStatusTimer.stop(); + abort = false; + if ( GlobalConfig->KvpncDebugLevel > 1 ) + { + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan ) + { + GlobalConfig->appendLogEntry ( "[ipsec] " + i18n ( "IPSec phase 1 established." ), GlobalConfig->info ); + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { + GlobalConfig->appendLogEntry ( "[ipsec] " + i18n ( "Low level IPsec phase 1 established." ), GlobalConfig->info ); + } + } + + if (GlobalConfig->currentProfile->getUseLeftSourceIp()) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Adding virtual IP address" ), GlobalConfig->debug ); + doAddRemoveVirtualIp("add"); + } + doPingKickupTunnel(); + + } + else if ( ProcessMsg_connect.find ( "IPsec SA established", 0 , FALSE ) > -1 ) + { + timer.stop(); + IpsecWhackStatusTimer.stop(); + + if ( IpsecPhase2Up ) + return; + else + IpsecPhase2Up=true; + abort = false; + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + { + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan ) + { + GlobalConfig->appendLogEntry ( "[ipsec] " + i18n ( "IPSec phase 2 established." ), GlobalConfig->info ); + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { + GlobalConfig->appendLogEntry ( "[ipsec] " + i18n ( "Low level IPsec phase 2 established." ), GlobalConfig->info ); + } + } + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan ) + { + GlobalConfig->appendLogEntry ( "[ipsec] " + i18n ( "Connection established." ), GlobalConfig->success ); + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { + GlobalConfig->appendLogEntry ( "[ipsec] " + i18n ( "Low level IPsec connection established." ), GlobalConfig->success ); + } + + doIptablesFreeswan(); + addRouteIpsec(); + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { + start_l2tpd(); + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan ) + { + sec = hour = min = 0; + + GlobalConfig->status = GlobalConfig->connected; + + disconnect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + connect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + durationTimer.start ( 1000, FALSE ); + setGuiStatus ( connected ); + + + setFirewallAfterConnect(); + if ( GlobalConfig->currentProfile->getExecuteCmdAfterConnect() ) + executeCommandAfterConnect(); + + if ( GlobalConfig->currentProfile->getUseAdditionalNetworkRoutes() && !GlobalConfig->currentProfile->getAdditionalNetworkRoutes().isEmpty() ) + addAdditionalNetworkRoutes(); + + if ( GlobalConfig->currentProfile->getUseConnectionStatusCheck() ) + { + startConnectionStatusCheck(); + } + } + } + + + +// // normal +// if ( NormalMsg ) +// { +// if ( GlobalConfig->KvpncDebugLevel > 1 ) +// GlobalConfig->appendLogEntry ( "[ipsec whack listen] " + ProcessMsg_connect, GlobalConfig->debug ); +// // if (GlobalConfig->KvpncDebugLevel > 0) +// // GlobalConfig->appendLogEntry( "out: " + ProcessMsg_connect, GlobalConfig->debug ); +// } +// else if ( ErrorMsg ) +// { +// GlobalConfig->appendLogEntry ( "[ipsec whack listen err] " + ProcessMsg_connect, GlobalConfig->error ); +// } + +// if ( abort ) +// { +// IpsecGotError = true; +// IpsecWhackStatusTimer.stop(); +// if ( GlobalConfig->KvpncDebugLevel > 0 ) +// GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "ipsec whack --listen" ) , GlobalConfig->debug ); +// disconnectClicked(); +// GlobalConfig->status = GlobalConfig->disconnected; +// setGuiStatus ( disconnected ); +// return ; +// } + } +} + +void KVpnc::readFromStderr_ipsecwhacklisten() +{ + bool abort = false; + if ( IpsecWhackListenProcess ==0 || IpsecGotError ) + return; + while ( IpsecWhackListenProcess->canReadLineStderr() ) + { + ProcessMsg_connect = IpsecWhackListenProcess->readLineStderr(); + // QString ProcessMsg_connect = QString( IpsecWhackListenProcess->readStderr() ); + +// GlobalConfig->appendLogEntry ( "[ipsec whack listen err] " + ProcessMsg_connect, GlobalConfig->error ); + + + if ( ProcessMsg_connect.find ( "Pluto is not running", 0 , FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( "[ipsec whack listen " + i18n ( "Waiting for pluto" ), GlobalConfig->debug ); + if ( connectCounter > 25 ) + { + GlobalConfig->appendLogEntry ( "[ipsec whack listen " + i18n ( "Waiting for pluto needs too long" ), GlobalConfig->debug ); + abort=true; + IpsecGotError = true; + IpsecWhackStatusTimer.stop(); + } + else + { + // we have to give some time to sleep and try again... + connect ( IpsecWhackListenProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_ipsecwhacklisten() ) ); + connect ( IpsecWhackListenProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsecwhacklisten() ) ); + IpsecWhackListenProcess->tryTerminate(); + sleep ( 2 ); + if ( IpsecWhackListenProcess->isRunning() ) + { + IpsecWhackListenProcess->kill(); + sleep ( 1 ); + } + connectCounter++; + if ( !IpsecGotError) + ipsecStarted(); + } + return; + } + if ( ProcessMsg_connect.find ( "listening for IKE messages", 0 , FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( "[ipsec whack listen] " + i18n ( "Listen was successful." ), GlobalConfig->debug ); + start_ipsec_initiate(); + } + else + { + GlobalConfig->appendLogEntry ( "[ipsec whack listen err] " + ProcessMsg_connect, GlobalConfig->error ); + } + + if ( abort ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "ipsec whack --listen" ) , GlobalConfig->debug ); + disconnectClicked(); + GlobalConfig->status = GlobalConfig->disconnected; + setGuiStatus ( disconnected ); + return ; + } + } +} + +void KVpnc::readFromStdout_ipsecwhackstatus() +{ + if ( IpsecWhackStatusProcess ==0 || IpsecGotError ) + return; +// QString ProcessMsg_connect_full = QString( IpsecWhackStatusProcess->readStdout() ); +// QStringList ProcessMsg_connect_list = QStringList::split('\n', ProcessMsg_connect_full); + while ( IpsecWhackStatusProcess !=0 && IpsecWhackStatusProcess->canReadLineStdout() ) +// for ( QStringList::Iterator it = ProcessMsg_connect_list.begin(); it != ProcessMsg_connect_list.end(); ++it ) + { +// QString ProcessMsg_connect = *it; + QString ProcessMsg_connect = IpsecWhackStatusProcess->readLineStdout(); + // QString ProcessMsg_connect = QString( IpsecWhackStatusProcess->readStdout() ); + + bool NormalMsg = true; + bool ErrorMsg = false; + bool abort = false; + + if ( GlobalConfig->KvpncDebugLevel > 5 ) + GlobalConfig->appendLogEntry ( "[ipsec whack status] " + ProcessMsg_connect, GlobalConfig->debug ); + + if ( ProcessMsg_connect.find ( QString ( GlobalConfig->currentProfile->getName() ), 0, FALSE ) > -1 ) + { + + if ( ProcessMsg_connect.find ( "ISAKMP SA established", 0 , FALSE ) > -1 || ProcessMsg_connect.find ( "transition from state STATE_QUICK_I1 to state STATE_QUICK_I2", 0 , FALSE ) > -1 ) + { + + timer.stop(); + IpsecWhackStatusTimer.stop(); + + if ( IpsecPhase2Up ) + return; + + if ( IpsecPhase1Up ) + return; + else + IpsecPhase1Up=true; + + + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + { + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan ) + { + GlobalConfig->appendLogEntry ( "[ipsec] " + i18n ( "IPSec phase 1 established." ), GlobalConfig->info ); + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { + GlobalConfig->appendLogEntry ( "[ipsec] " + i18n ( "Low level IPsec phase 1 established." ), GlobalConfig->info ); + } + } + if (GlobalConfig->currentProfile->getUseLeftSourceIp()) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Adding virtual IP address" ), GlobalConfig->debug ); + doAddRemoveVirtualIp("add"); + } + doPingKickupTunnel(); + } + + else if ( ProcessMsg_connect.find ( "IPsec SA established", 0 , FALSE ) > -1 ) + { + ipsecPhase2Established(); + } + } + +// // normal +// if ( GlobalConfig->KvpncDebugLevel > 3 ) +// { +// if ( NormalMsg ) +// { +// GlobalConfig->appendLogEntry ( "[ipsec whack status] " + ProcessMsg_connect, GlobalConfig->debug ); +// // if (GlobalConfig->KvpncDebugLevel > 0) +// // GlobalConfig->appendLogEntry( "out: " + ProcessMsg_connect, GlobalConfig->debug ); +// } +// } +// else if ( ErrorMsg ) +// { +// GlobalConfig->appendLogEntry ( "[ipsec whack status err] " + ProcessMsg_connect, GlobalConfig->error ); +// } +// +// if ( abort ) +// { +// if ( GlobalConfig->KvpncDebugLevel > 0 ) +// GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "ipsec whack status" ) , GlobalConfig->debug ); +// disconnectClicked(); +// GlobalConfig->status = GlobalConfig->disconnected; +// setGuiStatus ( disconnected ); +// return ; +// } + } +} + +void KVpnc::readFromStderr_ipsecwhackstatus() +{ + if ( IpsecWhackStatusProcess ==0 || IpsecGotError ) + return; +// bool abort = false; + while ( IpsecWhackStatusProcess !=0 && IpsecWhackStatusProcess->canReadLineStderr() ) + { + ProcessMsg_connect = IpsecWhackStatusProcess->readLineStderr(); + // QString ProcessMsg_connect = QString( IpsecWhackStatusProcess->readStderr() ); + +// if ( ProcessMsg_connect.find ( "failed to bind", 0, FALSE ) > -1|| ProcessMsg_connect.find ("FATAL ERROR: bind() failed in find_raw_ifaces(). Errno 98: Address already in use", 0, FALSE ) > -1 ) +// { +// +// } + + + if ( IpsecStatusCheck==true ) + { + + if ( GlobalConfig->KvpncDebugLevel > 6 ) + GlobalConfig->appendLogEntry ( "[ipsec whack status err] " + ProcessMsg_connect, GlobalConfig->error ); + + + if ( ProcessMsg_connect.find ( "Pluto is not running", 0, FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( i18n ( "ipsec daemon is not running, restarting it..." ), GlobalConfig->info ); + startStopIpsec ( true ); + sleep ( 1 ); + startStopIpsec ( false ); + } + + + + } + else + { + GlobalConfig->appendLogEntry ( "[ipsec whack status err] " + ProcessMsg_connect, GlobalConfig->error ); + + if ( ProcessMsg_connect.find ( "Pluto is not running", 0, FALSE ) > -1 ) + { + if ( !IpsecStartingInProgress ) + { + GlobalConfig->appendLogEntry ( i18n ( "ipsec daemon is not running, restarting it..." ), GlobalConfig->info ); + startStopIpsec ( true ); + sleep ( 1 ); + startStopIpsec ( false ); + } + } + } + +// if ( abort ) +// { +// GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "l2tpd" ) , GlobalConfig->error ); +// disconnectClicked(); +// GlobalConfig->status = GlobalConfig->disconnected; +// setGuiStatus ( disconnected ); +// return ; +// } + } +} + +void KVpnc::readFromStdout_ipsecwhackdelete() +{ + while ( IpsecWhackDeleteProcess->canReadLineStdout() ) + { + ProcessMsg_connect = IpsecWhackDeleteProcess->readLineStdout(); + // QString ProcessMsg_connect = QString( IpsecWhackDeleteProcess->readStdout() ); + + bool NormalMsg = true; + bool ErrorMsg = false; + bool abort = false; + + // normal + if ( NormalMsg ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( "[ipsec whack delete] " + ProcessMsg_connect, GlobalConfig->debug ); + // if (GlobalConfig->KvpncDebugLevel > 0) + // GlobalConfig->appendLogEntry( "out: " + ProcessMsg_connect, GlobalConfig->debug ); + } + else if ( ErrorMsg ) + { + GlobalConfig->appendLogEntry ( "[ipsec whack delete err] " + ProcessMsg_connect, GlobalConfig->error ); + } + + if ( abort ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "ipsec whack --delete" ) , GlobalConfig->debug ); + + return ; + } + } +} + +void KVpnc::readFromStderr_ipsecwhackdelete() +{ + bool abort = false; + while ( IpsecWhackDeleteProcess->canReadLineStderr() ) + { + ProcessMsg_connect = IpsecWhackDeleteProcess->readLineStderr(); + // QString ProcessMsg_connect = QString( IpsecWhackDeleteProcess->readStderr() ); + + + GlobalConfig->appendLogEntry ( "[ipsec whack delete err] " + ProcessMsg_connect, GlobalConfig->error ); + + if ( abort ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "ipsec whack --delete" ) , GlobalConfig->debug ); + + return ; + } + } +} + +void KVpnc::readFromStdout_tail_racoon() +{ + // QString ProcessMsg_connect = QString( RacoonTailProcess->readStdout() ); + while ( RacoonTailProcess->canReadLineStdout() ) + { + QString ProcessMsg_connect = RacoonTailProcess->readLineStdout() + "\n"; + // QString ProcessMsg_connect = RacoonTailProcess->readStdout(); + bool abort = false; + bool error_found = false; + + if ( ProcessMsg_connect.find ( "ERROR", 0 , FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( "[racoon tail err] " + ProcessMsg_connect, GlobalConfig->error ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + { + if ( ProcessMsg_connect.find ( "ERROR", 0 , FALSE ) == -1 ) + GlobalConfig->appendLogEntry ( "[racoon tail] " + ProcessMsg_connect, GlobalConfig->debug ); + } + } + +// // binding to port failed +// if ( ProcessMsg_connect.find ( "ERROR: failed to bind to address", 0 , FALSE ) > -1 || ProcessMsg_connect.find ( "ERROR: no address could be bound.", 0 , FALSE ) > -1) +// { +// +// if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) +// { +// if ( L2tpdProcess != 0 && L2tpdProcess->isRunning() ) +// L2tpdProcess->kill(); +// } +// +// QString NameAndPid = Utils ( GlobalConfig ).getNameAndPidOfProgramListen ( 500 ); +// GlobalConfig->appendLogEntry ( i18n ( "NameAndPid: %1" ).arg ( NameAndPid ) , GlobalConfig->debug ); +// int pid = -1; +// QString Name = ""; +// if ( !NameAndPid.isEmpty() ) +// { +// pid = NameAndPid.section ( '/', 0, 0 ).toInt(); +// Name = NameAndPid.section ( '/', 1, 1 ); +// +// if ( Name == "racoon" ) +// { +// +// //RacoonProcess->setCommunication ( QProcess::Stdin | QProcess::Stdout | QProcess::Stderr | QProcess::DupStderr ); +// // disconnect ( RacoonProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_racoon() ) ); +// // disconnect ( RacoonProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_racoon() ) ); +// +// if ( GlobalConfig->doKillRacoonIfStillRunning && abort == false ) +// { +// if ( GlobalConfig->KvpncDebugLevel > 3 ) +// GlobalConfig->appendLogEntry ( i18n ( "%1 could not bind too port, tring to kill it...." ).arg ( "racoon" ) , GlobalConfig->error ); +// +// QProcess killracoonprocess ( this ); +// killracoonprocess.addArgument ( GlobalConfig->pathToKillall ); +// killracoonprocess.addArgument ( "racoon" ); +// +// if ( !killracoonprocess.start() ) +// { +// GlobalConfig->appendLogEntry ( i18n ( "%1 could not be killed." ).arg ( "racoon" ) , GlobalConfig->error ); +// GlobalConfig->appendLogEntry ( QString ( "[racoon err] " + i18n ( "Bind to given port has been failed. Another %1 process is running. Please stop %1 first." ).arg ( "racoon" ) ) , GlobalConfig->error ); +// abort = true; +// } +// else +// { +// while ( killracoonprocess.isRunning() ) +// // parent->processEvents(); +// usleep ( 500 ); +// sleep ( 2 ); +// +// // restart racoon +// // if ( RacoonProcess != 0) +// { +// // RacoonProcess->kill(); +// delete RacoonProcess; +// RacoonProcess=0L; +// } +// +// putenv ( ( char* ) ( "LC_ALL=C" ) ); +// RacoonProcess = new QProcess ( this ); +// RacoonProcess->addArgument ( GlobalConfig->pathToRacoon ); +// /*RacoonProcess->addArgument ( "-F" )*/; // foreground we want :) +// // RacoonProcess->addArgument ( "-v" ); +// RacoonProcess->addArgument ( "-f" ); +// RacoonProcess->addArgument ( tmpPath + "racoon." + GlobalConfig->currentProfile->getName() + ".conf" ); +// // RacoonProcess->addArgument ( "-l" ); // logfile (we get content with tail process) +// // RacoonProcess->addArgument ( tmpPath + "racoon." + GlobalConfig->currentProfile->getName() + ".log" ); +// if ( GlobalConfig->KvpncDebugLevel > 0 ) +// GlobalConfig->appendLogEntry ( "racoon: " + GlobalConfig->pathToRacoon + " -f " + tmpPath + "/racoon" + GlobalConfig->currentProfile->getName() + ".conf", GlobalConfig->debug ); +// +// +// //RacoonProcess->setCommunication ( QProcess::Stdin | QProcess::Stdout | QProcess::Stderr | QProcess::DupStderr ); +// // connect ( RacoonProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_racoon() ) ); +// // connect ( RacoonProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_racoon() ) ); +// +// if ( !RacoonProcess->start(env) ) +// { +// if ( GlobalConfig->KvpncDebugLevel > 0 ) +// GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "racoon" ), GlobalConfig->error ); +// +// GlobalConfig->appendLogEntry ( QString ( "[racoon err] " + i18n ( "Bind to given port has been failed. Another %1 process is running. Please stop %1 first." ).arg ( "racoon" ) ) , GlobalConfig->error ); +// abort = false; +// } +// else +// { +// if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) +// { +// start_l2tpd(); +// if ( GlobalConfig->KvpncDebugLevel > 0 ) +// GlobalConfig->appendLogEntry ( i18n ( "%1 was already running. %2 and %3 are killed and restarted." ).arg ( "racoon" ).arg ( "racoon" ).arg ( "l2tpd" ), GlobalConfig->debug ); +// } +// else +// { +// doTailRacoonLog(); +// racoonStarted(); +// if ( GlobalConfig->KvpncDebugLevel > 0 ) +// GlobalConfig->appendLogEntry ( i18n ( "%1 was already running. It was killed and restarted." ).arg ( "racoon" ), GlobalConfig->debug ); +// } +// } +// } +// } +// else +// { +// KMessageBox::error ( this, i18n ( "Binding port %1 failed. Program \"%2\" with PID \"%3\" is using it. You have to stop it first." ).arg ( QString().setNum ( 500 ) ).arg ( Name ).arg ( QString().setNum ( pid ) ) ); +// GlobalConfig->appendLogEntry ( i18n ( "Port binding failed" ) , GlobalConfig->error ); +// abort = true; +// } +// } +// else +// { +// KMessageBox::error ( this, i18n ( "Binding port %1 failed. Program \"%2\" with PID \"%3\" is using it. You have to stop it first." ).arg ( QString().setNum ( 500 ) ).arg ( Name ).arg ( QString().setNum ( pid ) ) ); +// abort = true; +// } +// } +// else +// { +// KMessageBox::error ( this, i18n ( "Port binding failed" ) ); +// GlobalConfig->appendLogEntry ( i18n ( "Port binding failed" ) , GlobalConfig->error ); +// abort = true; +// } +// +// } + + if ( ProcessMsg_connect.find ( "ERROR: failed to bind to address", 0 , FALSE ) > -1 || ProcessMsg_connect.find ( "ERROR: no address could be bound.", 0 , FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( i18n ( "Port binding failed" ) , GlobalConfig->error ); + abort=true; + } + + else if ( ProcessMsg_connect.find ( "ERROR: couldn't find the pskey for", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "The pre shared key couldn't not found, check PSK settings." ) ); + GlobalConfig->appendLogEntry ( i18n ( "PSK is missing, aborting." ) , GlobalConfig->error ); + + abort = true; + } + else if ( ProcessMsg_connect.find ( "ERROR: failed to process packet.", 0 , FALSE ) > -1 ) + { + // KMessageBox::error( this, i18n( "failed to process packet" ) ); + GlobalConfig->appendLogEntry ( i18n ( "failed to process packet" ) , GlobalConfig->error ); + + abort = true; + } + else if ( ProcessMsg_connect.find ( "ERROR: phase1 negotiation failed.", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Phase 1 negotiation of IPSec connection has been failed. Please check encryption and hash algorithm." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Phase 1 negotiation of IPSec connection has been failed." ) , GlobalConfig->error ); + + abort = true; + } + else if ( ProcessMsg_connect.find ( "ERROR: delete phase1 handle.", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Phase 1 negotiation of IPSec connection has been failed. Please check encryption of phase 1 and hash algorithm." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Phase 1 negotiation of IPSec connection has been failed. Please check encryption of phase 1 and hash algorithm." ) , GlobalConfig->error ); + + abort = true; + } + else if ( ProcessMsg_connect.find ( "ERROR: reject the packet, received unexpecting payload type 0", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Phase 1 negotiation of IPSec connection has been failed. Please check encryption and hash algorithm." ) ); + GlobalConfig->appendLogEntry ( i18n ( "ERROR: reject the packet, received unexpecting payload type 0" ) , GlobalConfig->error ); + + abort = true; + } + else if ( ProcessMsg_connect.find ( "ERROR: unknown notify message", 0 , FALSE ) > -1 ) + { + // KMessageBox::error( this, i18n( "ERROR: unknown notify message, no phase2 handle found. " ) ); + GlobalConfig->appendLogEntry ( i18n ( "ERROR: unknown notify message, no phase2 handle found. " ) , GlobalConfig->error ); + + abort = true; + } + else if ( ProcessMsg_connect.find ( "ERROR: phase2 negotiation failed due to time up waiting for phase1", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Phase 2 negotiation of IPSec connection has been failed. Please check encryption and hash algorithm." ) ); + GlobalConfig->appendLogEntry ( i18n ( "ERROR: phase2 negotiation failed due to time up waiting for phase1" ) , GlobalConfig->error ); + + abort = true; + } + else if ( ProcessMsg_connect.find ( "ERROR: the peer's certificate is not verified", 0 , FALSE ) > -1 ) + { + // KMessageBox::error( this, i18n( "ERROR: the peer's certificate is not verified" ) ); + GlobalConfig->appendLogEntry ( i18n ( "ERROR: the peer's certificate is not verified" ) , GlobalConfig->error ); + + abort = true; + } + else if ( ProcessMsg_connect.find ( "ERROR: no configuration found for", 0 , FALSE ) > -1 ) + { + // KMessageBox::error( this, i18n( "ERROR: no configuration found" ) ); + GlobalConfig->appendLogEntry ( i18n ( "ERROR: no configuration found" ) , GlobalConfig->error ); + + abort = true; + } + else if ( ProcessMsg_connect.find ( "ERROR: no peer's CERT payload found.", 0 , FALSE ) > -1 ) + { + // KMessageBox::error( this, i18n( "ERROR: no peer's CERT payload found." ) ); + GlobalConfig->appendLogEntry ( i18n ( "ERROR: no peer's CERT payload found." ) , GlobalConfig->error ); + + abort = true; + } + else if ( ProcessMsg_connect.find ( "ERROR: failed to get subjectAltName", 0 , FALSE ) > -1 ) + { + // KMessageBox::error( this, i18n( "ERROR: failed to get subjectAltName" ) ); + GlobalConfig->appendLogEntry ( i18n ( "ERROR: failed to get subjectAltName" ) , GlobalConfig->error ); + + abort = true; + } + else if ( ProcessMsg_connect.find ( "ERROR: such a cert type isn't supported:", 0 , FALSE ) > -1 ) + { + ////KMessageBox::error( this, i18n( "ERROR: such a cert type isn't supported:" ) ); + //GlobalConfig->appendLogEntry ( i18n ( "ERROR: such a cert type isn't supported:" ) , GlobalConfig->error ); + // + //abort = true; + } + else if ( ProcessMsg_connect.find ( "ignore information because ISAKMP-SAhas not been established yet.", 0 , FALSE ) > -1 || ProcessMsg_connect.find ( "ignore information because ISAKMP-SA has not been established yet.", 0 , FALSE ) > -1 ) + { + //KMessageBox::error( this, i18n( "ERROR: fatal parse failure" ) ); + KMessageBox::error ( this, i18n ( "Phase 2 negotiation of IPSec connection has been failed. Please check encryption and hash algorithm." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Phase 2 negotiation of IPSec connection has been failed. Please check encryption and hash algorithm." ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( "has weak file permission", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Wrong file permission. Aborting." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Wrong file permission. Aborting." ) , GlobalConfig->error ); + + abort = true; + } + else if ( ProcessMsg_connect.find ( "ERROR: fatal INVALID-ID-INFORMATION", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Peer refused ID settings. Please verify the local ID in racoon and remote network in Network - General settings." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Peer refused ID settings. Please verify the local ID in racoon and remote network in Network - General settings." ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( "STATE: phase1 up", 0 , FALSE ) > -1 || ProcessMsg_connect.find ( "ISAKMP-SA established", 0 , FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Phase1 is now up." ) , GlobalConfig->debug ); + doPingKickupTunnel(); + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon && GlobalConfig->currentProfile->getUseLeftSourceIp()) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Adding virtual IP address" ), GlobalConfig->debug ); + doAddRemoveVirtualIp("add"); + } + } + else if ( ProcessMsg_connect.find ( "STATE: phase1 down", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Phase1 negotiation failed due to time up." ) ); + GlobalConfig->appendLogEntry ( i18n ( "ERROR: phase1 negotiation failed due to time up." ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( "IPsec-SA established", 0 , FALSE ) > -1 || ProcessMsg_connect.find ( "STATE: upscript finished", 0 , FALSE ) > -1 ) + { + racoon_tunnel_state++; + if ( racoon_tunnel_state == 1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( "[racoon tail] " + i18n ( "First tunnel is now up, waiting for second one..." ), GlobalConfig->debug ); + + + + } + else if ( racoon_tunnel_state == 2 ) + { + + if ( GlobalConfig->currentProfile->getUseModeConfig() ) + { + QFile ModeCfgFile ( QString ( tmpPath + "/racoon-" + GlobalConfig->currentProfile->getName() + ".modecfg" ) ); + if ( ModeCfgFile.exists() ) + { + QString TmpDns1=""; + QString TmpDns2=""; + QString internal_addr4=""; + QString internal_netmask4=""; + QString internal_cidr4=""; + QString internal_dns4=""; + QString internal_dns4_list=""; + QString internal_wins4=""; + QString internal_wins4_list=""; + QString split_include=""; + QString split_local=""; + QString default_domain=""; + QString resolvtemp=""; + if ( ModeCfgFile.open ( IO_ReadOnly ) ) + { + QTextStream stream ( &ModeCfgFile ); + QString line=""; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' + if ( GlobalConfig->KvpncDebugLevel > 5 ) + GlobalConfig->appendLogEntry ( "[ModeCfg] "+line, GlobalConfig->debug ); + + QString ModeCfgVar=line.section ( '=',0,0 ); + QString ModeCfgVal=line.section ( '=',1,-1 ); + if ( ModeCfgVal=="INTERNAL_ADDR4" ) + internal_addr4 = ModeCfgVal; + else if ( ModeCfgVal=="INTERNAL_NETMASK4" ) + internal_netmask4=ModeCfgVal; + else if ( ModeCfgVal=="INTERNAL_CIDR4" ) + internal_cidr4=ModeCfgVal; + else if ( ModeCfgVal=="INTERNAL_DNS4" ) + internal_dns4=ModeCfgVal; + else if ( ModeCfgVal=="INTERNAL_DNS4_LIST" ) + internal_dns4_list=ModeCfgVal; + else if ( ModeCfgVal=="INTERNAL_WINS4" ) + internal_wins4=ModeCfgVal; + else if ( ModeCfgVal=="INTERNAL_WINS4_LIST" ) + internal_wins4_list=ModeCfgVal; + else if ( ModeCfgVal=="SPLIT_INCLUDE" ) + split_include=ModeCfgVal; + else if ( ModeCfgVal=="SPLIT_LOCAL" ) + split_local=ModeCfgVal; + else if ( ModeCfgVal=="DEFAULT_DOMAIN" ) + default_domain=ModeCfgVal; + } + ModeCfgFile.close(); + } + + // tmp + TmpDns1 = internal_dns4; + + + QFile racoonupfile ( tmpPath + "racoon." + GlobalConfig->currentProfile->getName() + ".up" ); + QTextStream racoonupstream ( &racoonupfile ); + if ( racoonupfile.open ( IO_WriteOnly ) ) + { + QString DefaultDevice = NetworkInterface ( GlobalConfig,parent ).getDefaultInterface(); + /* update dns? */ + if ( GlobalConfig->currentProfile->getUseDnsUpdate() ) + { + racoonupstream << "if [ -x /sbin/resolvconf ] ; then\n"; + racoonupstream << " dev=$1\n"; + racoonupstream << " if [ -z $dev ] ; then\n"; + racoonupstream << " dev=\""+DefaultDevice+"\"\n"; + racoonupstream << "fi\n"; + bool no_nameserver=true; + if ( !TmpDns1.isEmpty() || !TmpDns2.isEmpty() ) + { + no_nameserver=false; + racoonupstream << "if [ -x /sbin/resolvconf ] ; then\n"; + if ( TmpDns2.isEmpty() ) + { + resolvtemp += "nameserver " + TmpDns1+ "\n"; + } + else + { + resolvtemp += "nameserver " + TmpDns1 + "\nnameserver " + TmpDns2+"\n"; + } + if (no_nameserver == true) + { + racoonupstream << " cat " + tmpPath + "/resolv.conf.before.kvpnc_" + GlobalConfig->currentProfile->getName() + " | grep nameserver >> " + tmpPath + "+resolvconf." + GlobalConfig->currentProfile->getName() + "\n"; + } + racoonupstream << " cat " + tmpPath + "+resolvconf." + GlobalConfig->currentProfile->getName()+ " | /sbin/resolvconf -a $dev\n"; + + racoonupstream << "else" << "\n"; + racoonupstream << " echo >> /etc/resolv.conf\n"; + racoonupstream << " echo \"# generated by kvpnc. Do not edit it.\" > /etc/resolv.conf" << "\n"; + racoonupstream << " echo \"# profile: " + GlobalConfig->currentProfile->getName() << "\" >> /etc/resolv.conf" << "\n"; + racoonupstream << " echo \"nameserver " << TmpDns1 << "\" >> /etc/resolv.conf" << "\n"; + if ( !TmpDns2.isEmpty() ) + { + racoonupstream << " echo \"nameserver " << TmpDns2 << "\" >> /etc/resolv.conf" << "\n"; + } + + if (no_nameserver == true) + { + racoonupstream << " cat " << tmpPath + "/resolv.conf.before.kvpnc_" + GlobalConfig->currentProfile->getName() + " | grep nameserver >> /etc/resolv.conf\n"; + } + racoonupstream << "fi" << "\n"; + + } + QProcess *pppdUpProcess = new QProcess ( this ); + pppdUpProcess->addArgument ( GlobalConfig->InterpreterShell ); + pppdUpProcess->addArgument ( tmpPath + "pppd." + GlobalConfig->currentProfile->getName() + ".up" ); + + if ( !pppdUpProcess->start ( env ) ) + { + KMessageBox::sorry ( this, i18n ( "\"%1\" (%2) start failed!" ).arg ( "PppdUpScript" ).arg ( tmpPath + "pppd." + GlobalConfig->currentProfile->getName() + ".up" ) ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" (%2) started." ).arg ( "PppdUpScript" ).arg ( tmpPath + "pppd." + GlobalConfig->currentProfile->getName() + ".up" ) , GlobalConfig->debug ); + while ( pppdUpProcess->isRunning() ) + { + parent->QApplication::processEvents(); + sleep ( 1 ); + } + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" (%2) finished." ).arg ( "PppdUpScript" ).arg ( tmpPath + "pppd." + GlobalConfig->currentProfile->getName() + ".up" ) , GlobalConfig->debug ); + + Utils ( GlobalConfig, this ).doChmod ( racoonupfile.name(), "u+x" ); + } + delete pppdUpProcess; + pppdUpProcess=0L; + } + } + + + } + } + + doIptablesRacoon(); + addRouteRacoon(); + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon ) + { + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + { + GlobalConfig->appendLogEntry ( "[racoon tail] " + i18n ( "IPSec phase 2 established." ), GlobalConfig->info ); + } + GlobalConfig->appendLogEntry ( "[racoon tail] " + i18n ( "Connection established." ), GlobalConfig->success ); + + sec = hour = min = 0; + + GlobalConfig->status = GlobalConfig->connected; + + disconnect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + connect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + durationTimer.start ( 1000, FALSE ); + setGuiStatus ( connected ); + + + doIptablesRacoon(); + addRouteRacoon(); + + setFirewallAfterConnect(); + if ( GlobalConfig->currentProfile->getExecuteCmdAfterConnect() ) + executeCommandAfterConnect(); + + if ( GlobalConfig->currentProfile->getUseAdditionalNetworkRoutes() && !GlobalConfig->currentProfile->getAdditionalNetworkRoutes().isEmpty() ) + addAdditionalNetworkRoutes(); + + if ( GlobalConfig->currentProfile->getUseConnectionStatusCheck() ) + { + startConnectionStatusCheck(); + } + } + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { + GlobalConfig->appendLogEntry ( "[racoon tail] " + i18n ( "Low level IPsec connection established." ), GlobalConfig->success ); + start_l2tpd(); + } + + } + } + else if ( ProcessMsg_connect.find ( "ISAKMP-SA expired", 0 , FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Phase1 expired" ) , GlobalConfig->debug ); + abort = false; + } + else if ( ProcessMsg_connect.find ( "Reading configuration from", 0 , FALSE ) > -1 ) + { +// GlobalConfig->appendLogEntry ( i18n ( "Reading configuration from got" ) , GlobalConfig->debug ); +// sleep(3); +// racoonStarted(); + } + else if ( ProcessMsg_connect.find ( "ERROR: none message must be encrypted", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Phase 1 negotiation of IPSec connection has been failed. Please check encryption of phase 1 and hash algorithm." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Phase 1 negotiation of IPSec connection has been failed. Please check encryption of phase 1 and hash algorithm." ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( "ERROR: fatal NO-PROPOSAL-CHOSEN", 0 , FALSE ) > -1 ) + { + if (!error_found) + KMessageBox::error ( this, i18n ( "Wrong connection parameters used. Please verify the connection settings." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Peer reported that we use wrong connection parameters." ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( "ERROR: phase1 negotiation failed due to time up.", 0 , FALSE ) > -1 ) + { + if (!error_found) + KMessageBox::error ( this, i18n ( "Phase1 negotiation failed due to time up." ) ); + GlobalConfig->appendLogEntry ( i18n ( "ERROR: phase1 negotiation failed due to time up." ) , GlobalConfig->error ); + abort = true; + } + + if ( abort ) + { + GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "racoon" ) , GlobalConfig->error ); + disconnectClicked(); + } + + } +} + +void KVpnc::readFromStderr_tail_racoon() +{ + // QString ProcessMsg_connect = QString( RacoonTailProcess->readStderr() ); + while ( RacoonTailProcess->canReadLineStderr() ) + { + bool error_found =false; + bool abort = false; + QString ProcessMsg_connect = RacoonTailProcess->readLineStderr() + "\n"; + //QString ProcessMsg_connect = RacoonTailProcess->readStderr(); + // if ( GlobalConfig->KvpncDebugLevel > 0 ) + { + GlobalConfig->appendLogEntry ( "[racoon tail err] " + ProcessMsg_connect, GlobalConfig->error ); + } + if ( ProcessMsg_connect.find ( "ERROR: phase1 negotiation failed due to time up.", 0 , FALSE ) > -1 ) + { + if (!error_found) + KMessageBox::error ( this, i18n ( "Phase1 negotiation failed due to time up." ) ); + GlobalConfig->appendLogEntry ( i18n ( "ERROR: phase1 negotiation failed due to time up." ) , GlobalConfig->error ); + abort = true; + } + if ( abort ) + { + GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "racoon" ) , GlobalConfig->error ); + disconnectClicked(); + } + } +} + +void KVpnc::readFromStdout_racoonctl() +{ + // QString ProcessMsg_connect = QString( RacoonctlProcess->readStdout() ); + while ( RacoonctlProcess->canReadLineStdout() ) + { + bool abort = false; + + QString ProcessMsg_connect = RacoonctlProcess->readLineStdout() + "\n"; + //QString ProcessMsg_connect = RacoonctlProcess->readStdout(); +// if ( GlobalConfig->KvpncDebugLevel > 3 ) + { + GlobalConfig->appendLogEntry ( "[racoonctl] " + ProcessMsg_connect, GlobalConfig->debug ); + } + if ( ProcessMsg_connect.find ( "ERROR", 0 , FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( "[racoonctl err] " + ProcessMsg_connect, GlobalConfig->error ); + } + if ( ProcessMsg_connect.find ( "send: Bad file descriptor", 0 , FALSE ) > -1 ) + { + +// KMessageBox::error ( this, i18n ( "Racoon seem not running!" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Racoon seem not running!" ) , GlobalConfig->error ); + +// if (GlobalConfig->KvpncDebugLevel > 3) +// GlobalConfig->appendLogEntry ( i18n ( "Racoon seem not running!" ) , GlobalConfig->debug ); + +// if (RacoonctlConnectCounter > 25) +// { +// GlobalConfig->appendLogEntry ( "[racoonctl] " + i18n("Waiting for racoon needs too long"), GlobalConfig->debug ); +// abort=true; +// } +// else +// { +// +// if (GlobalConfig->KvpncDebugLevel > 3) +// GlobalConfig->appendLogEntry ( i18n ( "Racoon seem not running, waiting" ) , GlobalConfig->debug ); +// +// // we have to give some time to sleep and try again... +// RacoonctlProcess->tryTerminate(); +// sleep(2); +// if (RacoonctlProcess->isRunning()) +// { +// disconnect( RacoonctlProcess, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdout_racoonctl() ) ); +// disconnect( RacoonctlProcess, SIGNAL( readyReadStderr() ), this, SLOT( readFromStderr_racoonctl() ) ); +// disconnect ( RacoonctlProcess, SIGNAL ( processExited () ), this, SLOT ( racoonctlExited() ) ); +// RacoonctlProcess->kill(); +// sleep(1); +// racoonStarted(); +// } +// RacoonctlConnectCounter++; +// } + +// abort =true; + } + else if ( ProcessMsg_connect.find ( "racoonctl: Cannot send combuf", 0 , FALSE ) > -1 ) + { + //KMessageBox::error ( this, i18n ( "racoonctl: Cannot send combuf" ) ); + GlobalConfig->appendLogEntry ( i18n ( "racoonctl: Cannot send combuf" ) , GlobalConfig->error ); + abort =true; + } + else if ( ProcessMsg_connect.find ( "Error: Peer not responding", 0 , FALSE ) > -1 ) + { + //KMessageBox::error ( this, i18n ( "racoonctl: Peer not responding" ) ); + GlobalConfig->appendLogEntry ( i18n ( "racoonctl: Peer not responding" ) , GlobalConfig->error ); + abort =true; + } + if ( ProcessMsg_connect.find ( "Password:", 0 , FALSE ) > -1 ) + { + if ( GlobalConfig->VpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[racoonctl] " + i18n ( "User password requested, send it...\n" ), GlobalConfig->debug ); + + QString UserPassStr = ""; +// if ( !GlobalConfig->currentProfile->getSaveUserPassword() || AuthRetry ) + UserPassStr = GlobalConfig->TmpPassword; +// else +// UserPassStr = GlobalConfig->currentProfile->getUserPassword(); + + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( "[racoonctl] " + i18n ( "User password: %1\n" ).arg ( UserPassStr ), GlobalConfig->debug ); + + + RacoonctlProcess->writeToStdin ( UserPassStr ); + RacoonctlProcess->writeToStdin ( "\n" ); + } + else if ( ProcessMsg_connect.find ( "VPN connexion terminated", 0 , FALSE ) > -1 ) + { + //KMessageBox::error ( this, i18n ( "VPN connexion terminated" ) ); + GlobalConfig->appendLogEntry ( i18n ( "VPN connexion terminated" ) , GlobalConfig->debug ); + abort =false; + } + else if ( ProcessMsg_connect.find ( "VPN connexion established", 0 , FALSE ) > -1 ) + { + // racoonctl tells it but its only phase1 => useless +// if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) +// { +// GlobalConfig->appendLogEntry ( "[racoon] " + i18n ( "Low level connection established." ), GlobalConfig->success ); +// racoon_tunnel_state=1; +// start_l2tpd(); +// } +// else +// { +// GlobalConfig->appendLogEntry ( "[racoon] " + i18n ( "Connection established." ), GlobalConfig->success ); +// +// sec = hour = min = 0; +// +// GlobalConfig->status = GlobalConfig->connected; +// +// connect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); +// durationTimer.start ( 1000, FALSE ); +// setGuiStatus ( connected ); +// +// setFirewallAfterConnect(); +// if ( GlobalConfig->currentProfile->getExecuteCmdAfterConnect() ) +// executeCommandAfterConnect(); +// +// if ( GlobalConfig->currentProfile->getUseAdditionalNetworkRoutes() && !GlobalConfig->currentProfile->getAdditionalNetworkRoutes().isEmpty() ) +// addAdditionalNetworkRoutes(); +// +// if ( GlobalConfig->currentProfile->getUseConnectionStatusCheck() ) +// { +// startConnectionStatusCheck(); +// } +// } + } + if ( abort ) + { + GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "racoon" ) , GlobalConfig->error ); + disconnectClicked(); + } + } +} + +void KVpnc::readFromStderr_racoonctl() +{ + // QString ProcessMsg_connect = QString( RacoonctlProcess->readStderr() ); + while ( RacoonctlProcess->canReadLineStderr() ) + { + bool abort = false; + QString ProcessMsg_connect = RacoonctlProcess->readLineStderr() + "\n"; + //QString ProcessMsg_connect = RacoonctlProcess->readStderr(); + // if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[racoonctl err] " + ProcessMsg_connect, GlobalConfig->error ); + + if ( ProcessMsg_connect.find ( "send: Bad file descriptor", 0 , FALSE ) > -1 ) + { +// KMessageBox::error ( this, i18n ( "Racoon seem not running!" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Racoon seem not running!" ) , GlobalConfig->error ); +// abort =true; + } + else if ( ProcessMsg_connect.find ( "racoonctl: Cannot send combuf", 0 , FALSE ) > -1 ) + { +// KMessageBox::error ( this, i18n ( "racoonctl: Cannot send combuf" ) ); + GlobalConfig->appendLogEntry ( i18n ( "racoonctl: Cannot send combuf" ) , GlobalConfig->error ); +// abort =true; + } + if ( ProcessMsg_connect.find ( "Password:", 0 , FALSE ) > -1 ) + { + if ( GlobalConfig->VpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[racoonctl err] " + i18n ( "User password requested, send it...\n" ), GlobalConfig->debug ); + + QString UserPassStr = ""; +// if ( !GlobalConfig->currentProfile->getSaveUserPassword() || AuthRetry ) + UserPassStr = GlobalConfig->TmpPassword; +// else +// UserPassStr = GlobalConfig->currentProfile->getUserPassword(); + + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( "[racoonctl err] " + i18n ( "User password: %1\n" ).arg ( UserPassStr ), GlobalConfig->debug ); + + + RacoonctlProcess->writeToStdin ( UserPassStr ); + RacoonctlProcess->writeToStdin ( "\n" ); + } + + + if ( abort ) + { + GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "racoon" ) , GlobalConfig->error ); + disconnectClicked(); + } + } +} + +void KVpnc::readFromStdout_pptp() +{ + while ( PptpProcess->canReadLineStdout() ) + { + ProcessMsg_connect = PptpProcess->readLineStdout(); + + if ( !ProcessMsg_connect.isEmpty() && GlobalConfig->KvpncDebugLevel > 4 ) + { + GlobalConfig->appendLogEntry ( "[pptp raw]: "+ProcessMsg_connect, GlobalConfig->debug ); + } + + bool abort = false; + bool connectSuccess = false; + bool allowReconnect = false; + + + if ( ProcessMsg_connect.find ( "could not find module", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Module not found." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Module not found." ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( "Connection terminated.", 0 , FALSE ) > -1 ) + { + //KMessageBox::error( this, i18n( "Connection has been terminated." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Connection has been terminated." ), GlobalConfig->info ); + abort = true; + allowReconnect = true; + } + else if ( ProcessMsg_connect.find ( "Modem hangup", 0 , FALSE ) > -1 || ProcessMsg_connect.find ( "Modem hung up", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Remote modem has hung up. Connection was terminated." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Remote modem has hung up. Connection was terminated." ) , GlobalConfig->error ); + abort = true; + allowReconnect = true; + } + else if ( ProcessMsg_connect.find ( "connect: Connection refused", 0 , FALSE ) > -1 ) + { + KMessageBox::error(this, i18n("Connection has been refused. Terminate.")); + GlobalConfig->appendLogEntry(i18n("Connection has been refused. Terminate.") , GlobalConfig->error); + abort = true; + } + else if ( ProcessMsg_connect.find ( "No route to host", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "No route to host." ) ); + GlobalConfig->appendLogEntry ( i18n ( "No route to host." ), GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( "Authentication failure", 0 , FALSE ) > -1 || ProcessMsg_connect.find ( "MS-CHAP authentication failed:", 0 , FALSE ) > -1) + { + timer.stop(); + connectCounter=0; + // disconnect ( &timer, SIGNAL ( timeout() ), this, SLOT ( slotConnectTimedOut() ) ); + KMessageBox::error ( this, i18n ( "Authentication has been failed." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Authentication has been failed." ) , GlobalConfig->error ); + //abort = true; + AuthRetry = true; + GlobalConfig->haveUserData = false; + connectClicked(); + } + else if ( ProcessMsg_connect.find ( "peer refused to authenticate", 0 , FALSE ) > -1 ) + { + timer.stop(); + connectCounter=0; + // disconnect ( &timer, SIGNAL ( timeout() ), this, SLOT ( slotConnectTimedOut() ) ); + KMessageBox::error ( this, i18n ( "The peer refused to authenticate." ) ); + GlobalConfig->appendLogEntry ( i18n ( "The peer refused to authenticate." ) , GlobalConfig->error ); + abort = true; + //abort = true; + AuthRetry = true; + GlobalConfig->haveUserData = false; + connectClicked(); + } + else if ( ProcessMsg_connect.find ( "EAP: peer reports authentication failure", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "The peer refused to authenticate (it wants EAP). Please check username, password and EAP settings." ) ); + GlobalConfig->appendLogEntry ( i18n ( "The peer refused to authenticate (it wants EAP). Please check username, password and EAP settings." ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( "Call manager exited with error", 0 , FALSE ) > -1 ) + { + //KMessageBox::error( this, i18n( "Call manager exited with a error." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Call manager exited with error." ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( "Input/output error", 0 , FALSE ) > -1 ) + { + //KMessageBox::error( this, i18n( "Input/output error" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Input/output error" ) , GlobalConfig->error ); + abort = true; + allowReconnect = true; + } + else if ( ProcessMsg_connect.find ( "Using interface", 0 , FALSE ) > -1 ) + { + PppdDevice = ProcessMsg_connect.right ( ProcessMsg_connect.length() - 16 ); + if ( GlobalConfig->PppdDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Tunnel device: %1\n" ).arg ( PppdDevice ), GlobalConfig->debug ); + GlobalConfig->currentProfile->setNetworkDevice ( PppdDevice ); + // + // + // NetworkInterface iface(GlobalConfig,parent); + // TunnelInterfaceIP = iface.getInterfaceIP( PppdDevice ); + // if (GlobalConfig->VpncDebugLevel > 0 ) + // GlobalConfig->appendLogEntry( "[pppd] "+i18n( "Tunnel IP:" ).arg(TunnelInterfaceIP) , GlobalConfig->debug); + // + + abort = false; + } + else if ( ProcessMsg_connect.find ( "tcflush failed: Bad file descriptor", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Sending data has failed. Connection was terminated." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Sending data has failed. Connection was terminated." ) , GlobalConfig->error ); + abort = true; + allowReconnect = true; + } + else if ( ProcessMsg_connect.find ( "Modem hangup", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Remote modem has hung up. Connection was terminated." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Remote modem has hung up. Connection was terminated." ) , GlobalConfig->error ); + abort = true; + allowReconnect = true; + } + else if ( ProcessMsg_connect.find ( "primary DNS address", 0 , FALSE ) > -1 ) + { + // example: primary DNS address 132.210.*.2 secondary DNS address 132.210.**.2 + bool got2dns = false; + QString DNS1 = ProcessMsg_connect.section ( ' ', 3, 3 ); + QString DNS2 = ProcessMsg_connect.section ( ' ', 7, 7 ); + + got2dns = Utils ( GlobalConfig ).isValidIPv4Address ( DNS2 ); + + if ( got2dns ) + { + TmpDns1 = DNS1; + TmpDns2 = DNS2; + } + else + TmpDns1 = DNS2; + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + { + if ( got2dns ) + GlobalConfig->appendLogEntry ( i18n ( "Got DNS1: %1, DNS2: %2" ).arg ( DNS1 ).arg ( DNS2 ) , GlobalConfig->debug ); + else + GlobalConfig->appendLogEntry ( i18n ( "Got DNS1: %1" ).arg ( DNS1 ) , GlobalConfig->debug ); + } + abort = false; + } + else if ( ProcessMsg_connect.find ( "CHAP authentication succeeded", 0 , FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "CHAP authentication succeeded.\n" ), GlobalConfig->debug ); + abort = false; + } + else if ( ProcessMsg_connect.find ( "MPPE 128-bit stateless compression enabled", 0 , FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "MPPE 128-bit stateless compression enabled.\n" ), GlobalConfig->debug ); + abort = false; + } + else if ( ProcessMsg_connect.find ( "local", 0 , FALSE ) > -1 ) + { + // if (GlobalConfig->KvpncDebugLevel > 0) + // GlobalConfig->appendLogEntry ( i18n( "adr: %1\n" ).arg( ProcessMsg_connect), GlobalConfig->debug); + TunnelInterfaceIP = ProcessMsg_connect.simplifyWhiteSpace().section ( ' ', 3, 3 ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Tunnel IP address: %1\n" ).arg ( TunnelInterfaceIP ), GlobalConfig->debug ); + abort = false; + } + else if ( ProcessMsg_connect.find ( "Loopback detected", 0 , FALSE ) > -1 ) + { + // KMessageBox::error ( this, i18n ( "Loopback detected. Reconnecting." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Loopback detected. Reconnecting." ) , GlobalConfig->error ); + abort = true; + connectClicked(); + } + else if ( ProcessMsg_connect.find ( "remote IP address", 0, FALSE ) > -1 ) + connectSuccess = true; + + // success + if ( connectSuccess ) + { + + sec = hour = min = 0; + + GlobalConfig->status = GlobalConfig->connected; + + disconnect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + connect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + durationTimer.start ( 1000, FALSE ); + setGuiStatus ( connected ); + connectSuccess = false; + + GlobalConfig->appendLogEntry ( i18n ( "Connection established." ), GlobalConfig->success ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Tunnel interface IP address: %1" ).arg ( TunnelInterfaceIP ), GlobalConfig->debug ); + + // GlobalConfig->appendLogEntry( QString("connectstring: "+ProcessMsg_connect), GlobalConfig->debug ); + + QString pppdev = ""; + if ( !PppdDevice.isEmpty() ) + pppdev = PppdDevice; + else + pppdev = "ppp0"; + + + // write pppd..up + QFile pppdupfile ( tmpPath + "pppd." + GlobalConfig->currentProfile->getName() + ".up" ); + QTextStream pppdupstream ( &pppdupfile ); + if ( pppdupfile.open ( IO_WriteOnly ) ) + { + pppdupstream << "#!"<< GlobalConfig->InterpreterShell << "\n"; + pppdupstream << "# generated by kvpnc. Do not edit it." << "\n"; + pppdupstream << "# profile: " + GlobalConfig->currentProfile->getName() << "\n\n"; + pppdupstream << "cat /etc/resolv.conf > " << tmpPath + "resolv.conf." + GlobalConfig->currentProfile->getName() << "\n"; + /* update dns? */ + if ( GlobalConfig->currentProfile->getUseDnsUpdate() ) + { + pppdupstream << "if [ -x /sbin/resolvconf ] ; then\n"; + pppdupstream << " echo > /dev/null" << "\n"; + pppdupstream << "else" << "\n"; + pppdupstream << " echo \"# generated by kvpnc. Do not edit it.\" > /etc/resolv.conf" << "\n"; + pppdupstream << "fi\n"; + + QString resolvtemp=""; + bool no_nameserver=true; + if ( !GlobalConfig->currentProfile->getUseDnsServer() ) + { + pppdupstream << "if [ -x /sbin/resolvconf ] ; then\n"; + pppdupstream << " dev=$1\n"; + pppdupstream << " if [ -z $dev ] ; then\n"; + pppdupstream << " dev=\"ppp0\"\n"; + pppdupstream << "fi\n"; + if ( !TmpDns1.isEmpty() || !TmpDns2.isEmpty() ) + { + no_nameserver=false; + pppdupstream << "if [ -x /sbin/resolvconf ] ; then\n"; + if ( TmpDns2.isEmpty() ) + { + resolvtemp += "nameserver " + TmpDns1+ "\n"; + pppdupstream << "echo \"nameserver " << TmpDns1 << "\"" << " " << "$dev\" > "+tmpPath + "+resolvconf." + GlobalConfig->currentProfile->getName() + "\n"; + } + else + { + resolvtemp += "nameserver " + TmpDns1 + "\nnameserver " + TmpDns2+"\n"; + pppdupstream << "echo \"nameserver " << TmpDns1 << "\"\nnameserver " << TmpDns2 << " " << "$dev\" > "+tmpPath + "+resolvconf." + GlobalConfig->currentProfile->getName() + "\n"; + } + + pppdupstream << "else" << "\n"; + pppdupstream << " echo >> /etc/resolv.conf\n"; + pppdupstream << " echo \"# generated by kvpnc. Do not edit it.\" > /etc/resolv.conf" << "\n"; + pppdupstream << " echo \"# profile: " + GlobalConfig->currentProfile->getName() << "\" >> /etc/resolv.conf" << "\n"; + pppdupstream << " echo \"nameserver " << TmpDns1 << "\" >> /etc/resolv.conf" << "\n"; + if ( !TmpDns2.isEmpty() ) + pppdupstream << " echo \"nameserver " << TmpDns2 << "\" >> /etc/resolv.conf" << "\n"; + } + + pppdupstream << "fi" << "\n"; + + pppdupstream << "# " << "\n"; + } + if ( ( GlobalConfig->currentProfile->getUseDnsServer() && !GlobalConfig->currentProfile->getDnsServer().isEmpty() ) || ( GlobalConfig->currentProfile->getUseSearchDomainInResolvConf() && ! GlobalConfig->currentProfile->getSearchDomainInResolvConf().isEmpty() ) || ( GlobalConfig->currentProfile->getUseDomainInResolvConf() && ! GlobalConfig->currentProfile->getDomainInResolvConf().isEmpty() ) ) + { + pppdupstream << "if [ -x /sbin/resolvconf ] ; then\n"; + pppdupstream << " dev=$1\n"; + pppdupstream << " if [ -z $dev ] ; then\n"; + pppdupstream << " dev=\"ppp0\"\n"; + pppdupstream << " fi\n"; + + if ( GlobalConfig->currentProfile->getUseDnsServer() && !GlobalConfig->currentProfile->getDnsServer().isEmpty() ) + { + resolvtemp+= "nameserver "+GlobalConfig->currentProfile->getDnsServer() +"\n"; + no_nameserver=false; + } + if ( GlobalConfig->currentProfile->getUseSearchDomainInResolvConf() && !GlobalConfig->currentProfile->getSearchDomainInResolvConf().isEmpty() ) + resolvtemp+= "search "+GlobalConfig->currentProfile->getSearchDomainInResolvConf() +"\n"; + if ( GlobalConfig->currentProfile->getUseDomainInResolvConf() && !GlobalConfig->currentProfile->getDomainInResolvConf().isEmpty() ) + resolvtemp+= "domain "+GlobalConfig->currentProfile->getDomainInResolvConf() +"\n"; + + pppdupstream << "else\n"; + if ( GlobalConfig->currentProfile->getUseDnsServer() && !GlobalConfig->currentProfile->getDnsServer().isEmpty() ) + { + pppdupstream << "echo \"nameserver " << GlobalConfig->currentProfile->getDnsServer() + "\" >> /etc/resolv.conf\n"; + no_nameserver=false; + } + if ( GlobalConfig->currentProfile->getUseSearchDomainInResolvConf() && !GlobalConfig->currentProfile->getSearchDomainInResolvConf().isEmpty() ) + pppdupstream << "echo \"search " << GlobalConfig->currentProfile->getSearchDomainInResolvConf() + "\" >> /etc/resolv.conf\n"; + if ( GlobalConfig->currentProfile->getUseDomainInResolvConf() && !GlobalConfig->currentProfile->getDomainInResolvConf().isEmpty() ) + pppdupstream << "echo \"domain " << GlobalConfig->currentProfile->getDomainInResolvConf() + "\" >> /etc/resolv.conf\n"; + pppdupstream << "fi\n"; + } + + + pppdupstream << "if [ -x /sbin/resolvconf ] ; then\n"; + pppdupstream << " echo \""+resolvtemp+"\" > "+tmpPath + "resolv.conf." + GlobalConfig->currentProfile->getName() << "\n"; + if (no_nameserver == true) + { + pppdupstream << " cat " + tmpPath + "/resolv.conf.before.kvpnc_" + GlobalConfig->currentProfile->getName() + " | grep nameserver >> " + tmpPath + "+resolvconf." + GlobalConfig->currentProfile->getName() + "\n"; + } + pppdupstream << " cat "+tmpPath + "resolv.conf." + GlobalConfig->currentProfile->getName() + " | /sbin/resolvconf -a $dev\n"; + + /* crissi: -u seems not nessesary */ + //pppdupstream << " cat "+tmpPath + "resolv.conf." + GlobalConfig->currentProfile->getName() " | /sbin/resolvconf -u\n"; + + if (!GlobalConfig->holdGeneratedScripts) + pppdupstream << " rm -f "+tmpPath + "resolv.conf." + GlobalConfig->currentProfile->getName() + "\n"; + + if ( no_nameserver==true ) + { + pppdupstream << "else\n"; + pppdupstream << " cat " << tmpPath + "/resolv.conf.before.kvpnc_" + GlobalConfig->currentProfile->getName() + " | grep nameserver >> /etc/resolv.conf\n"; + } + + pppdupstream << "fi\n"; + // pppdupstream << "chmod u-w /etc/resolv.conf\n"; + } + else + { + /* dont update dns */ + setenv ( "DNS_UPDATE", "NO",1 ); + } + if ( GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Replacing default route: %1" ).arg ( i18n ( "yes" ) ), GlobalConfig->debug ); + + if ( ! pppdHasReplacedefaultrouteSupport ) + { + // pppdupstream << GlobalConfig->pathToIp + " route replace default dev " + pppdev + "\n"; + pppdupstream << GlobalConfig->pathToRoute << " del default " << "\n"; + pppdupstream << GlobalConfig->pathToRoute << " add default " << pppdev << "\n"; + } + + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Setting extra route: %1 over %2 gw %3" ).arg ( GlobalConfig->currentProfile->getGateway() ).arg ( GlobalConfig->OldDefaultDev ).arg ( GlobalConfig->OldDefaultGw ), GlobalConfig->debug ); + + pppdupstream << GlobalConfig->pathToIp + " route add " + GlobalConfig->currentProfile->getGateway() + "/32 via " << GlobalConfig->OldDefaultGw << " dev " << GlobalConfig->OldDefaultDev << "\n"; + + NetworkInterface iface ( GlobalConfig , parent ); + int defaultroutecount = iface.getDefaultRouteCount(); + if ( defaultroutecount <1 ) + { + // pppdupstream << GlobalConfig->pathToIp + " route add 0.0.0.0 via " << GlobalConfig->OldDefaultGw << " dev " << pppdev << "\n"; + pppdupstream << GlobalConfig->pathToRoute << " add default " << pppdev << "\n"; + + if ( GlobalConfig->KvpncDebugLevel > 4 ) + GlobalConfig->appendLogEntry ( i18n ( "default route count: %1" ).arg ( QString().setNum ( defaultroutecount ) ), GlobalConfig->debug ); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "No default route found but replace it was requested, adding one over device %1 with gateway %2..." ).arg ( pppdev ).arg ( GlobalConfig->NewDefaultGw ), GlobalConfig->debug ); + + } + if ( defaultroutecount > 1 ) + { + pppdupstream << "newdefaultgw=$("<< GlobalConfig->pathToIp <<" route show default | grep default | grep -v "+ GlobalConfig->OldDefaultGw+")" << "\n"; + pppdupstream << "if [ -z $newdefaultgw ]; then" << "\n"; + pppdupstream << " newdefaultgw=\"" << GlobalConfig->OldDefaultGw << "\"" << "\n"; + pppdupstream << "fi" << "\n"; + for ( int i=0;ipathToRoute << " del default" << "\n"; + } + // pppdupstream << GlobalConfig->pathToIp + " route add 0.0.0.0 via " << GlobalConfig->OldDefaultGw << " dev " << pppdev << "\n"; + pppdupstream << GlobalConfig->pathToRoute << " add default " << pppdev << "\n"; + + if ( GlobalConfig->KvpncDebugLevel > 4 ) + GlobalConfig->appendLogEntry ( i18n ( "default route count: %1" ).arg ( QString().setNum ( defaultroutecount ) ), GlobalConfig->debug ); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "More than one default route found, deleting all and adding one over device %1 with gateway %2..." ).arg ( pppdev ).arg ( GlobalConfig->NewDefaultGw ), GlobalConfig->debug ); + + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 4 ) + GlobalConfig->appendLogEntry ( i18n ( "default route count : %1" ).arg ( "1" ), GlobalConfig->debug ); + } + + + + // NetworkInterface iface(GlobalConfig,GlobalConfig->appPointer, this); + // GlobalConfig->NewDefaultGw = iface.getGatewayOfDefaultInterface(); + // + // if (GlobalConfig->NewDefaultGw != "0.0.0.0") + // { + // if ( GlobalConfig->KvpncDebugLevel > 3 ) + // GlobalConfig->appendLogEntry ( i18n ( "Setting extra route: %1 over %2 gw %3" ).arg ( "0.0.0.0" ).arg( pppdev ).arg( GlobalConfig->NewDefaultGw), GlobalConfig->debug ); + // pppdupstream << GlobalConfig->pathToIp + " route add 0.0.0.0 via " << GlobalConfig->NewDefaultGw << " dev " << pppdev << "\n"; + // } + pppdupfile.close(); + } + + + QProcess *pppdUpProcess = new QProcess ( this ); + pppdUpProcess->addArgument ( GlobalConfig->InterpreterShell ); + pppdUpProcess->addArgument ( tmpPath + "pppd." + GlobalConfig->currentProfile->getName() + ".up" ); + + if ( !pppdUpProcess->start ( env ) ) + { + KMessageBox::sorry ( this, i18n ( "\"%1\" (%2) start failed!" ).arg ( "PppdUpScript" ).arg ( tmpPath + "pppd." + GlobalConfig->currentProfile->getName() + ".up" ) ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" (%2) started." ).arg ( "PppdUpScript" ).arg ( tmpPath + "pppd." + GlobalConfig->currentProfile->getName() + ".up" ) , GlobalConfig->debug ); + while ( pppdUpProcess->isRunning() ) + { + parent->QApplication::processEvents(); + sleep ( 1 ); + } + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" (%2) finished." ).arg ( "PppdUpScript" ).arg ( tmpPath + "pppd." + GlobalConfig->currentProfile->getName() + ".up" ) , GlobalConfig->debug ); + } + + delete pppdUpProcess; + pppdUpProcess=0L; + + QString iplocal=getenv ( "IPLOCAL" ); + QString ipremote=getenv ( "IPREMOTE" ); + QString ifname=getenv ( "IFNAME" ); + QString speed=getenv ( "SPEED" ); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Local IP address: %1, remote IP address: %2, device: %3, speed: %4" ).arg ( TunnelInterfaceIP ).arg ( ipremote ).arg ( ifname ).arg ( speed ), GlobalConfig->debug ); + + setFirewallAfterConnect(); + if ( GlobalConfig->currentProfile->getExecuteCmdAfterConnect() ) + executeCommandAfterConnect(); + + + // if ( GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + // { + // if (! pppdHasReplacedefaultrouteSupport) + // { + // tmpPath = locateLocal ( "data", "kvpnc/" ); + // QString PppdReplaceDefaultRouteScript = tmpPath + "pppd_replace_defaultroute." + GlobalConfig->currentProfile->getName() + ".sh"; + // + // QFile file ( PppdReplaceDefaultRouteScript ); + // QTextStream stream ( &file ); + // if ( file.open ( IO_WriteOnly ) ) + // { + // stream << "# generated by kvpnc. Do not edit it." << "\n"; + // stream << "\n"; + // file.close(); + // ReplaceDefaultRouteProcess = new QProcess ( this ); + // ReplaceDefaultRouteProcess->addArgument ( GlobalConfig->InterpreterShell ); + // ReplaceDefaultRouteProcess->addArgument ( PppdReplaceDefaultRouteScript ); + // if ( !ReplaceDefaultRouteProcess->start(env) ) + // { + // KMessageBox::sorry ( this, i18n ( "\"%1\" %2 start failed!" ).arg ( i18n ( "pppd replace route process" )).arg( tmpPath + "pppd_replace_defaultroute." + GlobalConfig->currentProfile->getName() + ".sh") ); + // // disconnectClicked(); + // // setGuiStatus(disconnected); + // } + // else + // { + // if ( GlobalConfig->KvpncDebugLevel > 1 ) + // GlobalConfig->appendLogEntry ( i18n ( "\"%1\" (%2) started." ).arg ( i18n ( "pppd replace route process" )).arg( tmpPath + "pppd_replace_defaultroute." + GlobalConfig->currentProfile->getName() + ".sh") , GlobalConfig->debug ); + // while (ReplaceDefaultRouteProcess->isRunning()) + // { + // sleep(1); + // } + // delete ReplaceDefaultRouteProcess; + // ReplaceDefaultRouteProcess=0L; + // } + // } + // else + // { + // GlobalConfig->appendLogEntry ( i18n ( "Could not write: \"%1\" (%2)!" ).arg ( i18n ( "pppd replace route script" )).arg(PppdReplaceDefaultRouteScript), GlobalConfig->error ); + // } + // + // } + // { + // if ( GlobalConfig->KvpncDebugLevel > 1 ) + // GlobalConfig->appendLogEntry ( i18n ( "pppd supports replacedefaultroute and replace the route it" ) , config->debug ); + // } + // } + // PptpRouteProcess = new QProcess( this ); + // PptpRouteProcess->addArgument( GlobalConfig->pathToRoute ); + // PptpRouteProcess->addArgument( "add" ); + // PptpRouteProcess->addArgument( "-net" ); + // PptpRouteProcess->addArgument( GlobalConfig->currentProfile->getRemoteNetAddr() + "/" + GlobalConfig->currentProfile->getRemoteNetMask() ); + // PptpRouteProcess->addArgument( pppdev ); + + // if ( !PptpRouteProcess->start(env) ) + // { + // KMessageBox::sorry( this, i18n( "\"%1\" start failed!" ).arg( i18n( "pppd route process" ) ) ); + // disconnectClicked(); + // setGuiStatus(disconnected); + // } + // else + // { + // while (PptpRouteProcess->isRunning()) + // { + // usleep(500); + // } + // delete PptpRouteProcess; + // PptpRouteProcess=0L; + // GlobalConfig->appendLogEntry ( i18n( "\"%1\" started." ).arg( i18n( "pppd route process" ) ), GlobalConfig->info ); + + if ( GlobalConfig->currentProfile->getUseAdditionalNetworkRoutes() && !GlobalConfig->currentProfile->getAdditionalNetworkRoutes().isEmpty() ) + addAdditionalNetworkRoutes(); + + if ( GlobalConfig->currentProfile->getUseConnectionStatusCheck() ) + { + startConnectionStatusCheck(); + } + } + } + // GlobalConfig->appPointer->processEvents(); + + if ( abort ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "pppd" ) , GlobalConfig->debug ); + //terminateConnection ( PptpProcess ); + disconnectClicked(); + GlobalConfig->status = GlobalConfig->disconnected; + setGuiStatus ( disconnected ); + + + // // remove password entries + // if (GlobalConfig->currentProfile->getAuthMethod() == "chap" || GlobalConfig->currentProfile->getAuthMethod() == "mschap" || GlobalConfig->currentProfile->getAuthMethod() == "mschap-v2" ) + // { + // // remove kvpnc entries from chap-secerets + // QFile ChapSecretsFile ( "/etc/ppp/chap-secrets" ); + // if ( GlobalConfig->KvpncDebugLevel > 0 ) + // GlobalConfig->appendLogEntry ( i18n ( "pppd secrets file: %1").arg("/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + // QTextStream stream ( &ChapSecretsFile ); + // if ( ChapSecretsFile.open ( IO_ReadOnly ) ) + // { + // QString line = ""; + // QString chapsecret_content = ""; + // bool kvpnc_start_marker_found = false; + // bool kvpnc_end_marker_found = false; + // while ( !stream.atEnd() ) + // { + // line = stream.readLine(); // line of text excluding '\n' + // if ( line == "# --- generated by kvpnc. Do not edit it." ) + // { + // kvpnc_end_marker_found = true; + // if ( GlobalConfig->KvpncDebugLevel > 2 ) + // GlobalConfig->appendLogEntry ( i18n ( "End marker in %1 found" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + // } + // if ( line == "# +++ generated by kvpnc. Do not edit it." ) + // { + // kvpnc_start_marker_found = true; + // if ( GlobalConfig->KvpncDebugLevel > 2 ) + // GlobalConfig->appendLogEntry ( i18n ( "Start marker in %1 found" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + // } + // + // if ( kvpnc_start_marker_found == false ) + // { + // chapsecret_content += line; + // chapsecret_content += '\n'; + // } + // } + // ChapSecretsFile.close(); + // if ( ChapSecretsFile.remove() ) + // { + // if ( GlobalConfig->KvpncDebugLevel > 2 ) + // GlobalConfig->appendLogEntry ( i18n ( "File %1 successfully removed" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + // // ChapSecretsFile.setName("/etc/ppp/chap-secrets2"); + // if ( ChapSecretsFile.open ( IO_WriteOnly ) ) + // { + // stream.setDevice ( &ChapSecretsFile ); + // stream << chapsecret_content; + // ChapSecretsFile.close(); + // if ( GlobalConfig->KvpncDebugLevel > 2 ) + // GlobalConfig->appendLogEntry ( i18n ( "File %1 sucessfully rewritten" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + // } + // else + // { + // if ( GlobalConfig->KvpncDebugLevel > 2 ) + // GlobalConfig->appendLogEntry ( i18n ( "File %1 rewrite failed" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->error ); + // } + // } + // else + // { + // if ( GlobalConfig->KvpncDebugLevel > 2 ) + // GlobalConfig->appendLogEntry ( i18n ( "File %1 remove failed" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->error ); + // } + // + // } + // else + // { + // GlobalConfig->appendLogEntry ( i18n ( "File %1 could not opened!" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->error ); + // } + // } + // if (GlobalConfig->currentProfile->getAuthMethod() == "pap") + // { + // // remove kvpnc entries from pap-secerets + // QFile papSecretsFile ( "/etc/ppp/pap-secrets" ); + // if ( GlobalConfig->KvpncDebugLevel > 0 ) + // GlobalConfig->appendLogEntry ( i18n ( "pppd secrets file: %1").arg("/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + // QTextStream stream ( &papSecretsFile ); + // if ( papSecretsFile.open ( IO_ReadOnly ) ) + // { + // QString line = ""; + // QString papsecret_content = ""; + // bool kvpnc_start_marker_found = false; + // bool kvpnc_end_marker_found = false; + // while ( !stream.atEnd() ) + // { + // line = stream.readLine(); // line of text excluding '\n' + // if ( line == "# --- generated by kvpnc. Do not edit it." ) + // { + // kvpnc_end_marker_found = true; + // if ( GlobalConfig->KvpncDebugLevel > 2 ) + // GlobalConfig->appendLogEntry ( i18n ( "End marker in %1 found" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + // } + // if ( line == "# +++ generated by kvpnc. Do not edit it." ) + // { + // kvpnc_start_marker_found = true; + // if ( GlobalConfig->KvpncDebugLevel > 2 ) + // GlobalConfig->appendLogEntry ( i18n ( "Start marker in %1 found" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + // } + // + // if ( kvpnc_start_marker_found == false ) + // { + // papsecret_content += line; + // papsecret_content += '\n'; + // } + // } + // papSecretsFile.close(); + // if ( papSecretsFile.remove() ) + // { + // if ( GlobalConfig->KvpncDebugLevel > 2 ) + // GlobalConfig->appendLogEntry ( i18n ( "File %1 successfully removed" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + // // papSecretsFile.setName("/etc/ppp/pap-secrets2"); + // if ( papSecretsFile.open ( IO_WriteOnly ) ) + // { + // stream.setDevice ( &papSecretsFile ); + // stream << papsecret_content; + // papSecretsFile.close(); + // if ( GlobalConfig->KvpncDebugLevel > 2 ) + // GlobalConfig->appendLogEntry ( i18n ( "File %1 sucessfully rewritten" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + // } + // else + // { + // if ( GlobalConfig->KvpncDebugLevel > 2 ) + // GlobalConfig->appendLogEntry ( i18n ( "File %1 rewrite failed" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->error ); + // } + // } + // else + // { + // if ( GlobalConfig->KvpncDebugLevel > 2 ) + // GlobalConfig->appendLogEntry ( i18n ( "File %1 remove failed" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->error ); + // } + // + // } + // else + // { + // GlobalConfig->appendLogEntry ( i18n ( "File %1 could not opened!" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->error ); + // } + // } + + if ( allowReconnect && GlobalConfig->currentProfile->getDoReconnectAfterConnectionLost() ) + { + if ( GlobalConfig->currentProfile->getUseReconnectDelay() ) + { + GlobalConfig->appendLogEntry ( i18n ( "Waiting %1s for reconnect..." ).arg ( GlobalConfig->currentProfile->getReconnectDelay() ), GlobalConfig->info ); + for ( int time = 0; time <= GlobalConfig->currentProfile->getReconnectDelay() * 1000;time += 200 ) + { + usleep ( 200 ); + GlobalConfig->appPointer->processEvents(); + } + } + // if (GlobalConfig->KvpncDebugLevel > 0) + GlobalConfig->appendLogEntry ( i18n ( "Reconnect after connection lost enabled, reconnecting..." ), GlobalConfig->info ); + connectClicked(); + } + + } + } +} + +void KVpnc::readFromStderr_pptp() +{ + while ( PptpProcess->canReadLineStderr() ) + { + ProcessMsg_connect = PptpProcess->readLineStderr(); + if ( !ProcessMsg_connect.isEmpty() && GlobalConfig->KvpncDebugLevel > 4 ) + { + GlobalConfig->appendLogEntry ( "[pptp err raw]: "+ProcessMsg_connect, GlobalConfig->debug ); + } + + bool abort = false; + bool allowReconnect = false; + bool error_found=false; + + if ( ProcessMsg_connect.find ( "DNS address", 0, FALSE ) || ProcessMsg_connect.find ( "Script /etc/ppp/ip-up started", 0, FALSE ) ) + GlobalConfig->appendLogEntry ( "[pppd] " + ProcessMsg_connect, GlobalConfig->debug ); + else + GlobalConfig->appendLogEntry ( "[pppd err] " + ProcessMsg_connect, GlobalConfig->error ); + + if ( ProcessMsg_connect.find ( "authentication failed", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Authentication has been failed." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Authentication has been failed." ) , GlobalConfig->error ); + abort = true; + error_found=true; + } + else if ( ProcessMsg_connect.find ( "MPPE required but not available", 0 , FALSE ) > -1 ) + { + if ( error_found==false ) + KMessageBox::error ( this, i18n ( "MPPE required but not available" ) ); + GlobalConfig->appendLogEntry ( i18n ( "MPPE required but not available" ) , GlobalConfig->error ); + abort = true; + error_found=true; + } + else if ( ProcessMsg_connect.find ( "peer refused to authenticate", 0 , FALSE ) > -1 ) + { + if ( error_found==false ) + KMessageBox::error ( this, i18n ( "The peer refused to authenticate." ) ); + GlobalConfig->appendLogEntry ( i18n ( "The peer refused to authenticate." ) , GlobalConfig->error ); + abort = true; + error_found=true; + } + else if ( ProcessMsg_connect.find ( "could not find module", 0 , FALSE ) > -1 ) + { + if ( error_found==false ) + KMessageBox::error ( this, i18n ( "Module not found." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Module not found." ), GlobalConfig->error ); + abort = true; + error_found=true; + } + else if ( ProcessMsg_connect.find ( "Connection terminated.", 0 , FALSE ) > -1 ) + { + //if (error_found==false) + // KMessageBox::error( this, i18n( "Connection has been terminated." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Connection has been terminated." ), GlobalConfig->info ); + abort = true; + allowReconnect = true; + error_found=true; + } + else if ( ProcessMsg_connect.find ( "tcflush failed: Bad file descriptor", 0 , FALSE ) > -1 ) + { + if ( error_found==false ) + KMessageBox::error ( this, i18n ( "Sending data has failed. Connection was terminated." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Sending data has failed. Connection was terminated." ), GlobalConfig->error ); + abort = true; + allowReconnect = true; + error_found=true; + } + else if ( ProcessMsg_connect.find ( "MPPE required, but kernel has no support", 0 , FALSE ) > -1 ) + { + if ( error_found==false ) + KMessageBox::error ( this, i18n ( "MPPE required, but kernel has no support. Please use a kernel with mppe support." ) ); + GlobalConfig->appendLogEntry ( i18n ( "MPPE required, but kernel has no support. Please use a kernel with mppe support." ) , GlobalConfig->error ); + abort = true; + error_found=true; + } + else if ( ProcessMsg_connect.find ( "unrecognized option 'mppe'", 0 , FALSE ) > -1 ) + { + if ( error_found==false ) + KMessageBox::error ( this, i18n ( "MPPE required, but pppd has no MPPE support. Please install a pppd with MPPE support." ) ); + GlobalConfig->appendLogEntry ( i18n ( "MPPE required, but pppd has no support. Please install a pppd with MPPE support." ) , GlobalConfig->error ); + abort = true; + error_found=true; + } + else if ( ProcessMsg_connect.find ( "Input/output error", 0 , FALSE ) > -1 ) + { + //if (error_found==false) + //KMessageBox::error( this, i18n( "Input/output error" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Input/output error" ) , GlobalConfig->error ); + abort = true; + allowReconnect = true; + error_found=true; + } + else if ( ProcessMsg_connect.find ( "local IP address", 0 , FALSE ) > -1 ) + { + TunnelInterfaceIP = ProcessMsg_connect.simplifyWhiteSpace().section ( ' ', 3, 3 ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Tunnel IP address: %1\n" ).arg ( TunnelInterfaceIP ), GlobalConfig->debug ); + abort = false; + error_found=true; + } + else if ( ProcessMsg_connect.find ( "No auth is possible sent", 0 , FALSE ) > -1 ) + { + if ( error_found==false ) + KMessageBox::error ( this, i18n ( "No password was send. Please check if there is a password set in user settings." ) ); + GlobalConfig->appendLogEntry ( i18n ( "No password was send. Please check if there is a password set in user settings." ) , GlobalConfig->error ); + abort = true; + error_found=true; + } + + GlobalConfig->appendLogEntry ( QString ( "[pppd err] " + ProcessMsg_connect ) , GlobalConfig->error ); + + if ( abort ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "pppd" ) , GlobalConfig->debug ); + //terminateConnection ( PptpProcess ); + disconnectClicked(); + GlobalConfig->status = GlobalConfig->disconnected; + setGuiStatus ( disconnected ); + + if ( allowReconnect && GlobalConfig->currentProfile->getDoReconnectAfterConnectionLost() ) + { + if ( GlobalConfig->currentProfile->getUseReconnectDelay() ) + { + GlobalConfig->appendLogEntry ( i18n ( "Waiting %1s for reconnect..." ).arg ( GlobalConfig->currentProfile->getReconnectDelay() ), GlobalConfig->info ); + for ( int time = 0; time <= GlobalConfig->currentProfile->getReconnectDelay() * 1000;time += 200 ) + { + usleep ( 200 ); + GlobalConfig->appPointer->processEvents(); + } + } + // if (GlobalConfig->KvpncDebugLevel > 0) + GlobalConfig->appendLogEntry ( i18n ( "Reconnect after connection lost enabled, reconnecting..." ), GlobalConfig->info ); + connectClicked(); + } + } + // GlobalConfig->appPointer->processEvents(); + } +} + +void KVpnc::readOutput_openvpn() +{ + + QString ProcessMsg = ""; + bool stderr = false; + bool connectSuccess = false; + QString NetworkDevice = ""; + + while ( OpenvpnProcess != 0L && OpenvpnProcess->canReadLineStdout() ) + { + ProcessMsg = QString ( OpenvpnProcess->readLineStdout() ); + + + // ProcessMsg = QString( OpenvpnProcess->readStdout() ); + + if ( !ProcessMsg.isEmpty() && GlobalConfig->KvpncDebugLevel > 4 ) + { + GlobalConfig->appendLogEntry ( "[openvpn raw]: "+ProcessMsg, GlobalConfig->debug ); + } + // else + // { + // stderr=true; + // ProcessMsg = QString( OpenvpnProcess->readStderr() ); + // GlobalConfig->appendLogEntry ( "stderr openvpn: "+ProcessMsg, GlobalConfig->debug ); + // } + + + if ( ProcessMsg.find ( "refused", 0 , FALSE ) > -1 && !stderr ) + GlobalConfig->appendLogEntry ( "[openvpn] " + ProcessMsg, GlobalConfig->error ); + else + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[openvpn] " + ProcessMsg, GlobalConfig->debug ); + + bool abort = false; + + if ( ProcessMsg.find ( "Connection timed out", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Connection has been timed out. Terminate." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Connection has been timed out. Terminate." ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg.find ( "[ECONNREFUSED]: Connection refused", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Connection has been refused. Terminate." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Connection has been refused. Terminate." ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg.find ( "AUTH: Received AUTH_FAILED", 0, FALSE ) > -1 ) + { + AuthRetry = true; + GlobalConfig->haveUserData = false; + disconnect ( OpenvpnProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readOutput_openvpn() ) ); + // disconnect( OpenvpnProcess, SIGNAL( readyReadStderr() ), this, SLOT( readOutput_openvpn() ) ); + connectClicked(); + // KMessageBox::error( this, i18n( "Authentication failed (%1)!" ).arg(i18n("user password") )); + GlobalConfig->appendLogEntry ( i18n ( "Authentication failed (%1)!" ).arg ( i18n ( "user password" ) ) , GlobalConfig->error ); + // abort=true; + } + else if ( ProcessMsg.find ( "ERROR: could not read Auth username/password from management interface", 0, FALSE ) > -1 ) + { + ; + disconnect ( OpenvpnProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readOutput_openvpn() ) ); + // disconnect( OpenvpnProcess, SIGNAL( readyReadStderr() ), this, SLOT( readOutput_openvpn() ) ); + connectClicked(); + // KMessageBox::error( this, i18n( "Authentication failed (%1)!" ).arg(i18n("user password") )); + GlobalConfig->appendLogEntry ( i18n ( "Username and password could not read from management interface!" ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg.find ( "ERROR: could not read eToken token username/password/ok from management interface", 0, FALSE ) > -1 ) + { + disconnect ( OpenvpnProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readOutput_openvpn() ) ); + // disconnect( OpenvpnProcess, SIGNAL( readyReadStderr() ), this, SLOT( readOutput_openvpn() ) ); + connectClicked(); + // KMessageBox::error( this, i18n( "Authentication failed (%1)!" ).arg(i18n("user password") )); + GlobalConfig->appendLogEntry ( i18n ( "eToken password could not read from management interface!" ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg.find ( "Insufficient key material or header text not found", 0, FALSE ) > -1 ) + { + AuthRetry = true; + GlobalConfig->haveUserData = false; + disconnect ( OpenvpnProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readOutput_openvpn() ) ); + // disconnect( OpenvpnProcess, SIGNAL( readyReadStderr() ), this, SLOT( readOutput_openvpn() ) ); + connectClicked(); + // KMessageBox::error( this, i18n( "Authentication failed (%1)!" ).arg(i18n("user password") )); + GlobalConfig->appendLogEntry ( i18n ( "Insufficient key material or header text not found!" ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg.find ( "not found", 0, FALSE ) > -1 && ProcessMsg.find ( "Message hash algorithm", 0, FALSE ) > -1 ) + { + QString hash_algo= ProcessMsg.section ( "'",1,1 ); + KMessageBox::error ( this, i18n ( "Hash algorithm \"%1\"not found! Please choose another one." ).arg ( hash_algo ) ); + GlobalConfig->appendLogEntry ( i18n ( "Hash algorithm \"%1\"not found! Please choose another one." ).arg ( hash_algo ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg.find ( "Cannot load private key file", 0 , FALSE ) > -1 ) + { + //KMessageBox::error( this, i18n( "Auth username is empty." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Private key file could not loaded!" ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg.find ( "'dev-type' is used inconsistently, local='dev-type tun', remote='dev-type tap'", 0 , FALSE ) > -1 ) + { + // KMessageBox::error( this, i18n( "Local network type is %1 but remote network type is %2. This must be fixed.\nGo to OpenVPN settings and change it to %2." ).arg( "tun" ).arg( "tap" ) ); + // GlobalConfig->appendLogEntry( i18n( "Local network type is %1 but remote network type is %2. This must be fixed." ).arg( "tun" ).arg( "tap" ) , GlobalConfig->error ); + // abort = true; + + GlobalConfig->appendLogEntry ( i18n ( "Local network type is %1 but remote network type is %2. This will be fixed." ).arg ( "tun" ).arg ( "tap" ), GlobalConfig->info ); + GlobalConfig->currentProfile->setTunnelDeviceType ( "tap" ); + GlobalConfig->saveOptions(true, GlobalConfig->currentProfile->getName()); + disconnectClicked(); + connectClicked(); + } + else if ( ProcessMsg.find ( "'dev-type' is used inconsistently, local='dev-type tap', remote='dev-type tun'", 0 , FALSE ) > -1 ) + { + // KMessageBox::error( this, i18n( "Local network type is %1 but remote network type is %2. This must be fixed.\nGo to OpenVPN settings and change it to %2." ).arg( "tap" ).arg( "tun" ) ); + // GlobalConfig->appendLogEntry( i18n( "Local network type is %1 but remote network type is %2. This must be fixed." ).arg( "tap" ).arg( "tun" ), GlobalConfig->error ); + // abort = true; + + GlobalConfig->appendLogEntry ( i18n ( "Local network type is %1 but remote network type is %2. This will be fixed." ).arg ( "tap" ).arg ( "tun" ), GlobalConfig->info ); + GlobalConfig->currentProfile->setTunnelDeviceType ( "tun" ); + GlobalConfig->saveOptions(true, GlobalConfig->currentProfile->getName()); + disconnectClicked(); + connectClicked(); + } + else if ( ProcessMsg.find ( "connect to " + QString ( GlobalConfig->currentProfile->getHttpProxy() + ":" + QString().setNum ( GlobalConfig->currentProfile->getHttpProxyPort() ) + " failed" ), 0, FALSE ) > -1 ) + { + // else if ( ProcessMsg.find( "Connection refused", 0, FALSE ) > -1 ) { + // if ( ProcessMsg.find( "failed", 0, FALSE ) > -1 ) { + GlobalConfig->appendLogEntry ( i18n ( "Connection to HTTP proxy (%1:%2) failed!" ).arg ( GlobalConfig->currentProfile->getHttpProxy() ).arg ( GlobalConfig->currentProfile->getHttpProxyPort() ) , GlobalConfig->error ); + KMessageBox::error ( this, i18n ( "Connection to HTTP proxy (%1:%2) failed!" ).arg ( GlobalConfig->currentProfile->getHttpProxy() ).arg ( GlobalConfig->currentProfile->getHttpProxyPort() ) ); + abort = true; + // } + } + else if ( ProcessMsg.find ( "SIGTERM[soft,init_instance] received", 0, FALSE ) > -1 ) + { + + GlobalConfig->appendLogEntry ( i18n ( "Connection was rejected (wrong HTTP proxy auth data?)." ).arg ( GlobalConfig->currentProfile->getHttpProxy() ).arg ( GlobalConfig->currentProfile->getHttpProxyPort() ) , GlobalConfig->error ); + KMessageBox::error ( this, i18n ( "Connection was rejected (wrong HTTP proxy auth data?)." ) ); + abort = true; + } + else if ( ProcessMsg.find ( "MANAGEMENT: Cannot bind TCP socket", 0, FALSE ) > -1 ) + { + +// GlobalConfig->appendLogEntry ( i18n ( "The management port cant bind, please try again later." ).arg ( GlobalConfig->currentProfile->getHttpProxy() ).arg ( GlobalConfig->currentProfile->getHttpProxyPort() ) , GlobalConfig->error ); +// KMessageBox::error ( this, i18n ( "The management port cant bind, please try again later." ) ); + QString NameAndPid = Utils ( GlobalConfig ).getNameAndPidOfProgramListen ( GlobalConfig->OpenvpnManagementPort ); + GlobalConfig->appendLogEntry ( i18n ( "NameAndPid: %1" ).arg ( NameAndPid ) , GlobalConfig->debug ); + int pid = -1; + QString Name = ""; + if ( !NameAndPid.isEmpty() ) + { + pid = NameAndPid.section ( '/', 0, 0 ).toInt(); + Name = NameAndPid.section ( '/', 1, 1 ); + KMessageBox::error ( this, i18n ( "Binding port %1 failed. Program \"%2\" with PID \"%3\" is using it. You have to stop it first." ).arg ( QString().setNum ( GlobalConfig->OpenvpnManagementPort ) ).arg ( Name ).arg ( QString().setNum ( pid ) ) ); + } + else + KMessageBox::error ( this, i18n ( "Port binding failed" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Port binding failed" ) , GlobalConfig->error ); + + abort = true; + } + else if ( ProcessMsg.find ( QString ( "MANAGEMENT: Socket bind failed on local address 127.0.0.1:"+QString().setNum ( GlobalConfig->OpenvpnManagementPort ) +": Address already in use" ), 0, FALSE ) > -1 ) + { + +// GlobalConfig->appendLogEntry ( i18n ( "The management port cant bind, please try again later." ) ) , GlobalConfig->error ); +// KMessageBox::error ( this, i18n ( "The management port cant bind, please try again later." ) ); + + QString NameAndPid = Utils ( GlobalConfig ).getNameAndPidOfProgramListen ( GlobalConfig->OpenvpnManagementPort ); + GlobalConfig->appendLogEntry ( i18n ( "NameAndPid: %1" ).arg ( NameAndPid ) , GlobalConfig->debug ); + int pid = -1; + QString Name = ""; + if ( !NameAndPid.isEmpty() ) + { + pid = NameAndPid.section ( '/', 0, 0 ).toInt(); + Name = NameAndPid.section ( '/', 1, 1 ); + KMessageBox::error ( this, i18n ( "Binding port %1 failed. Program \"%2\" with PID \"%3\" is using it. You have to stop it first." ).arg ( QString().setNum ( GlobalConfig->OpenvpnManagementPort ) ).arg ( Name ).arg ( QString().setNum ( pid ) ) ); + } + else + { + KMessageBox::error ( this, i18n ( "Port binding failed" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Port binding failed" ) , GlobalConfig->error ); + } + abort = true; + // managementhandler->closeConnection(); + } + else if ( ProcessMsg.find ( "TLS key negotiation failed to occur within 60 seconds", 0 , FALSE ) > -1 || ProcessMsg.find ( "TLS Error: TLS handshake failed", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "TLS key negotiation failed to occur within 60 seconds" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Port binding failed" ) , GlobalConfig->error ); + abort=true; + } + /* + else if ( ProcessMsg.find( "authentication failed", 0 , FALSE ) > -1 ) + { + KMessageBox::error( this, i18n( "Authentication has been failed." ) ); + abort = true; + } + */ + else if ( ProcessMsg.find ( "Enter Private Key Password", 0, FALSE ) > -1 ) + { + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Private key password requested, send it...\n" ), GlobalConfig->debug ); + + QString PrivKeyPassStr = ""; + // if (GlobalConfig->currentProfile->getSavePsk()) + PrivKeyPassStr = GlobalConfig->currentProfile->getPrivateKeyPass(); + // else + // PrivKeyPassStr = TmpPrivKeyPassStr; + if ( PrivKeyPassStr.isEmpty() ) + { + GlobalConfig->TmpPrivateKeyPass = ""; + QString pass=""; + EnterXauthInteractivePasscodeDialog dlg ( 0); + dlg.setCaption( i18n ( "Enter private key password" ) ); + dlg.main->DescriptionLabel->setText ( i18n ( "Enter private key password to unlock private key:" ) ); + dlg.main->LabelPassword->setText ( i18n ( "Private key password:" ) ); + dlg.main->SavePasswordCheckBox->setText ( i18n ( "Save private key password" ) ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[openvpn] " + i18n ( "Password for private key requested...\n" ), GlobalConfig->debug ); + if ( dlg.exec() ) + { + + pass = dlg.main->PasswordEdit->text(); + if ( !pass.isEmpty() ) + { + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( "OpenvpnManagementHandler: " + i18n ( "private key password got from user" ), GlobalConfig->debug ); + + if ( dlg.main->SavePasswordCheckBox->isChecked() ) + { + GlobalConfig->currentProfile->setSavePrivateKeyPassword ( true ); + GlobalConfig->currentProfile->setPrivateKeyPass ( QString ( pass ) ); + } + + GlobalConfig->TmpPrivateKeyPass = QString ( pass ); + + // if ( GlobalConfig->KvpncDebugLevel > 5 ) + // GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: private key password: " + GlobalConfig->TmpPrivateKeyPass, GlobalConfig->debug ); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( "OpenvpnManagementHandler: " + i18n ( "Send private key password..." ), GlobalConfig->debug ); + + OpenvpnProcess->writeToStdin ( PrivKeyPassStr ); + OpenvpnProcess->writeToStdin ( "\n" ); + } + else + { + GlobalConfig->appendLogEntry ( "OpenvpnManagementHandler: password empty, stop.", GlobalConfig->error ); + return; + } + } + } + else + { + OpenvpnProcess->writeToStdin ( PrivKeyPassStr ); + OpenvpnProcess->writeToStdin ( "\n" ); + return ; + } + } + else if ( ProcessMsg.find ( "Enter Auth Username", 0 , FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "User name requested, send it...\n" ), GlobalConfig->debug ); + + QString UsernameStr = ""; + if ( !GlobalConfig->currentProfile->getUserName().isEmpty() ) + UsernameStr = GlobalConfig->currentProfile->getUserName(); + else + UsernameStr = GlobalConfig->TmpUsername; + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "OpenVPN Auth User name: " + UsernameStr , GlobalConfig->debug ); + + OpenvpnProcess->writeToStdin ( UsernameStr ); + OpenvpnProcess->writeToStdin ( "\n" ); + + return ; + } + else if ( ProcessMsg.find ( "Enter Auth Password:", 0 , FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "User password requested, send it...\n" ), GlobalConfig->debug ); + + if ( !GlobalConfig->currentProfile->getSaveUserPassword() && !AuthRetry ) + OpenvpnProcess->writeToStdin ( GlobalConfig->currentProfile->getUserPassword() ); + else + { + // if ( GlobalConfig->KvpncDebugLevel > 0 ) + // GlobalConfig->appendLogEntry ( "OpenVPN Auth Pass: " + GlobalConfig->TmpPassword , GlobalConfig->debug ); + + + OpenvpnProcess->writeToStdin ( GlobalConfig->TmpPassword ); + OpenvpnProcess->writeToStdin ( "\n" ); + } + + } + else if ( ProcessMsg.find ( "Cannot resolve host address", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Host could not be resolved." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Host could not be resolved." ), GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg.find ( "could not find module", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Module not found." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Module not found." ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg.find ( "Socket bind failed on local address", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Binding to socket on local address failed." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Binding to socket on local address failed." ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg.find ( "No route to host", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "No route to host found." ) ); + GlobalConfig->appendLogEntry ( i18n ( "No route to host found." ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg.find ( "Connection terminated", 0 , FALSE ) > -1 ) + { + // KMessageBox::error( this, i18n( "Connection has been terminated." ) ); + abort = true; + } + else if ( ProcessMsg.find ( "Cannot open file key file", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Cannot open the preshared key file." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Cannot open the preshared key file." ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg.find ( "Authenticate/Decrypt packet error: cipher final failed", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Authentication has been failed because decryption failure. Please check OpenVPN settings." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Authentication has been failed because decryption failure. Please check OpenVPN settings." ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg.find ( "'auth' is used inconsistently", 0 , FALSE ) > -1 ) + { + QString LocalAuth = ProcessMsg.section ( '=', 1, 1 ).section ( ',', 0, 0 ).section ( ' ', 1, 1 ).remove ( "'" ); + QString PeerAuth = ProcessMsg.section ( '=', 2, 2 ).section ( ' ', 1, 1 ).remove ( "'" ); + // KMessageBox::error( this, i18n( "Wrong authentication method used. We use \"%1\" but peer want \"%2\". Please change it in %3 settings." ).arg( LocalAuth ).arg( PeerAuth ).arg( i18n( "OpenVPN" ) ) ); + // GlobalConfig->appendLogEntry( i18n( "Wrong authentication method used. We use \"%1\" but peer want \"%2\". Please change it in %3 settings." ).arg( LocalAuth ).arg( PeerAuth ).arg( i18n( "OpenVPN" ) ) , GlobalConfig->error ); + // abort = true; + + GlobalConfig->appendLogEntry ( i18n ( "Wrong authentication method used. We use \"%1\" but peer want \"%2\", this will be fixed." ).arg ( LocalAuth ).arg ( PeerAuth ) , GlobalConfig->info ); + GlobalConfig->currentProfile->setUseAuthenticationAlgorithm ( true ); + GlobalConfig->currentProfile->setAuthenticationAlgorithm ( PeerAuth ); + GlobalConfig->saveOptions(true, GlobalConfig->currentProfile->getName()); + disconnectClicked(); + connectClicked(); + } + else if ( ProcessMsg.find ( "WARNING: 'cipher' is used inconsistently", 0 , FALSE ) > -1 ) + { + // example: WARNING: 'cipher' is used inconsistently, local='cipher BF-CBC', remote='cipher AES-128-CBC' + QString LocalCipher = ProcessMsg.section ( '=', 1, 1 ).section ( ',', 0, 0 ).section ( ' ', 1, 1 ).remove ( "'" ); + QString PeerCipher = ProcessMsg.section ( '=', 2, 2 ).section ( ' ', 1, 1 ).remove ( "'" ); + // KMessageBox::error( this, i18n( "Wrong cipher used. We use \"%1\" but peer want \"%2\". Please change it in %3 settings." ).arg( LocalCipher ).arg( PeerCipher ).arg( i18n( "OpenVPN" ) ) ); + // GlobalConfig->appendLogEntry( i18n( "Wrong chiper used. We use \"%1\" but peer want \"%2\". Please change it in %3 settings." ).arg( LocalCipher ).arg( PeerCipher ).arg( i18n( "OpenVPN" ) ) , GlobalConfig->error ); + // abort = true; + + GlobalConfig->appendLogEntry ( i18n ( "Wrong chipher used. We use \"%1\" but peer want \"%2\", this will be fixed." ).arg ( LocalCipher ).arg ( PeerCipher ) , GlobalConfig->info ); + GlobalConfig->currentProfile->setUserdefiniedCipher ( PeerCipher ); + GlobalConfig->currentProfile->setUseUserdefiniedCipher ( true ); + GlobalConfig->saveOptions(true, GlobalConfig->currentProfile->getName()); + disconnectClicked(); + connectClicked(); + } + else if ( ProcessMsg.find ( "Options error: Unrecognized option or missing parameter(s) in [PUSH-OPTIONS]", 0 , FALSE ) > -1 ) + { + // KMessageBox::error( this, i18n( "OpenVPN configuration error. Unrecognized option or missing parameter(s) in [PUSH-OPTIONS]" ) ); + // GlobalConfig->appendLogEntry( i18n( "OpenVPN configuration error. Unrecognized option or missing parameter(s) in [PUSH-OPTIONS]" ), GlobalConfig->error ); + // abort = true; + GlobalConfig->appendLogEntry ( i18n ( "OpenVPN configuration error. Unrecognized option or missing parameter(s) in [PUSH-OPTIONS]" ), GlobalConfig->info ); + abort = false; + } + else if ( ProcessMsg.find ( "Options error: Unrecognized option or missing parameter", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "OpenVPN configuration error. Unrecognized option or missing parameter" ) ); + GlobalConfig->appendLogEntry ( i18n ( "OpenVPN configuration error. Unrecognized option or missing parameter" ), GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg.find ( "Options error: Parameter", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "OpenVPN configuration error. Wrong parameter in config file. Please contact the KVpnc author." ) ); + GlobalConfig->appendLogEntry ( i18n ( "OpenVPN configuration error. Wrong parameter in config file. Please contact the KVpnc author." ), GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg.find ( "Options error: --auth-user-pass requires --pull", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "OpenVPN configuration error. Wrong parameter in config file. Please contact the KVpnc author." ) ); + GlobalConfig->appendLogEntry ( i18n ( "OpenVPN configuration error. Wrong parameter in config file. Please contact the KVpnc author." ), GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg.find ( "TCP connection established", 0 , FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( "[openvpn]: "+i18n ( "Low level connection to %1 established." ).arg ( GlobalConfig->currentProfile->getGateway() ), GlobalConfig->info ); + } + else if ( ProcessMsg.find ( "UDP connection established", 0 , FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( "[openvpn]: "+i18n ( "Low level connection to %1 established." ).arg ( GlobalConfig->currentProfile->getGateway() ),GlobalConfig->info ); + } + // else if ( ProcessMsg.find( "Options error", 0 , FALSE ) > -1 ) + // { + // KMessageBox::error( this, i18n( "OpenVPN configuration error." ) ); + // GlobalConfig->appendLogEntry( i18n( "OpenVPN configuration error." ), GlobalConfig->error ); + // GlobalConfig->currentProfile->setDoReconnectAfterConnectionLost( false ); + // abort = true; + // } + else if ( ProcessMsg.find ( "refused", 0 , FALSE ) > -1 ) + { + //KMessageBox::error( this, i18n( "Connection to OpenVPN server was refused." ) ); + abort = false; + } + else if ( ProcessMsg.find ( "Connection timed out", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Connection has been timed out. Terminate." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Connection has been timed out. Terminate." ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg.find ( "Cannot load certificate file", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Certificate file (%1) could not be load. Please check path of it." ).arg ( GlobalConfig->currentProfile->getX509Certificate() ) ); + GlobalConfig->appendLogEntry ( i18n ( "Certificate file (%1) could not be load. Please check path of it." ).arg ( GlobalConfig->currentProfile->getX509Certificate() ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg.find ( "ifconfig failed", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "ifconfig has been failed." ) ); + GlobalConfig->appendLogEntry ( i18n ( "ifconfig has been failed." ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg.find ( "Auth username is empty", 0 , FALSE ) > -1 ) + { + //KMessageBox::error( this, i18n( "Auth username is empty." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Auth username is empty." ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg.find ( "Cannot load private key file", 0 , FALSE ) > -1 ) + { + //KMessageBox::error( this, i18n( "Auth username is empty." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Private key file could not loaded!" ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg.find ( "Need 'token-insertion-request' confirmation MSG:Please insert SLOT", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Need token to be insert. Please insert token in SLOT...." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Need token to be insert. Please insert token in SLOT...." ), GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg.find ( "process exiting", 0 , FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "%1 is shutting down." ).arg ( "openvpn" ), GlobalConfig->debug ); + + connectionEnded(); + setGuiStatus ( disconnected ); + } + else if ( ProcessMsg.find ( "Initialization Sequence Completed", 0, FALSE ) > -1 ) + { + connectSuccess = true; + } + else if ( ProcessMsg.find ( "TUN/TAP device", 0, FALSE ) > -1 ) + { + // TUN/TAP device tun0 opened + NetworkDevice = ProcessMsg.section ( ' ', -2, -2 ); // tun0 + OpenvpnDevice = ProcessMsg.section ( ' ', -2, -2 ); // tun0 + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + { + GlobalConfig->appendLogEntry ( i18n ( "Tunnel device: %1\n" ).arg ( OpenvpnDevice ), GlobalConfig->debug ); + + } + NetworkInterface iface ( GlobalConfig, parent ); + TunnelInterfaceIP = iface.getInterfaceIP ( OpenvpnDevice ); + } + else if ( ProcessMsg.find ( "ifconfig ", 0, FALSE ) > -1 ) + { + TunnelInterfaceIP = ProcessMsg.section ( ' ', -4, -4 ); // ip + GlobalConfig->appendLogEntry ( i18n ( "Tunnel interface IP: %1\n" ).arg ( TunnelInterfaceIP ), GlobalConfig->debug ); + } + + // success + if ( connectSuccess ) + { + + GlobalConfig->appendLogEntry ( i18n ( "Connection established." ), GlobalConfig->success ); + + sec = hour = min = 0; + + GlobalConfig->status = GlobalConfig->connected; + + disconnect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + connect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + durationTimer.start ( 1000, FALSE ); + setGuiStatus ( connected ); + connectSuccess = false; + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[openvpn] " + i18n ( "Using %1 as tunnel device." ).arg ( OpenvpnDevice ) , GlobalConfig->debug ); + + setFirewallAfterConnect(); + if ( GlobalConfig->currentProfile->getExecuteCmdAfterConnect() ) + executeCommandAfterConnect(); + + if ( GlobalConfig->currentProfile->getUseAdditionalNetworkRoutes() && !GlobalConfig->currentProfile->getAdditionalNetworkRoutes().isEmpty() ) + { + addAdditionalNetworkRoutes(); + // GlobalConfig->appendLogEntry( i18n( "Add additional network routes..." ), GlobalConfig->debug ); + } + else + { + // GlobalConfig->appendLogEntry( i18n( "No additional routes to add." ), GlobalConfig->debug ); + } + if ( GlobalConfig->currentProfile->getUseConnectionStatusCheck() ) + { + startConnectionStatusCheck(); + } + } + + if ( abort ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "openvpn" ), GlobalConfig->debug ); + + disconnectClicked(); + + return ; + } + + } + + while ( OpenvpnProcess != 0L && OpenvpnProcess->canReadLineStderr() ) + { + ProcessMsg = QString ( OpenvpnProcess->readLineStderr() ); + + + // ProcessMsg = QString( OpenvpnProcess->readStdout() ); + + if ( !ProcessMsg.isEmpty() && GlobalConfig->KvpncDebugLevel > 2 ) + { + GlobalConfig->appendLogEntry ( "[openvpn stderr raw]: "+ProcessMsg, GlobalConfig->debug ); + } + } +} + +void KVpnc::readFromStdout_l2tpd() +{ + L2tpdBufferStdoutString += QString ( L2tpdProcess->readStdout() ); + emit L2tpdStdoutRecieved(); + return; + +} + +void KVpnc::readFromStderr_l2tpd() +{ + L2tpdBufferStderrString += QString ( L2tpdProcess->readStderr() ); + emit L2tpdStderrRecieved(); + return; + +} + +void KVpnc::processStdout_l2tpd() +{ + + QString ProcessMsg_connect_raw = L2tpdBufferStdoutString; + QStringList ProcessMsg_connect_list = QStringList::split ( '\n',ProcessMsg_connect_raw ); + L2tpdBufferStdoutString =""; + for ( QStringList::Iterator it = ProcessMsg_connect_list.begin(); it != ProcessMsg_connect_list.end(); ++it ) + { + bool NormalMsg = true; + bool ErrorMsg = false; + QString ProcessMsg_connect = *it; + + if ( GlobalConfig->KvpncDebugLevel > 7 ) + GlobalConfig->appendLogEntry ( QString ( "[l2tpd raw] " + ProcessMsg_connect ) , GlobalConfig->debug ); + + + bool abort = false; + bool connectSuccess = false; + + if ( ProcessMsg_connect.find ( "init_network: Unable to bind socket. Terminating", 0 , FALSE ) > -1 || ProcessMsg_connect.find ( "Unable to bind socket: Address already in use", 0 , FALSE ) > -1 ) + { + bool kill_l2tpd=true; + + QString deamon="xl2tpd"; + if ( !GlobalConfig->pathToXl2tpd.isEmpty() && QFile ( GlobalConfig->pathToXl2tpd ).exists() ) + { + deamon="xl2tpd"; + if ( !GlobalConfig->doKillXl2tpdIfStillRunning ) + { + GlobalConfig->appendLogEntry ( QString ( "[l2tpd err] " + i18n ( "Bind to given port has been failed. Another %1 process is running. Please stop %1 first." ).arg ( deamon ) ) , GlobalConfig->debug ); + abort = true; + kill_l2tpd=false; + } + } + else + { + deamon="l2tpd"; + if ( !GlobalConfig->doKillL2tpdIfStillRunning ) + { + GlobalConfig->appendLogEntry ( QString ( "[l2tpd err] " + i18n ( "Bind to given port has been failed. Another %1 process is running. Please stop %1 first." ).arg ( deamon ) ) , GlobalConfig->debug ); + abort = true; + kill_l2tpd=false; + } + } + + if ( kill_l2tpd == true ) + { + QProcess killl2tpdprocess ( this ); + killl2tpdprocess.addArgument ( GlobalConfig->pathToKillall ); + if ( !GlobalConfig->pathToXl2tpd.isEmpty() && QFile ( GlobalConfig->pathToXl2tpd ).exists() ) + killl2tpdprocess.addArgument ( "xl2tpd" ); + else + killl2tpdprocess.addArgument ( "l2tpd" ); + + if ( !killl2tpdprocess.start() ) + { + GlobalConfig->appendLogEntry ( i18n ( "%1 could not be killed." ).arg ( "l2tpd" ) , GlobalConfig->error ); + GlobalConfig->appendLogEntry ( QString ( "[l2tpd err] " + i18n ( "Bind to given port has been failed. Another %1 process is running. Please stop %1 first." ).arg ( deamon ) ) , GlobalConfig->debug ); + abort = true; + } + else + { + while ( killl2tpdprocess.isRunning() ) + { + usleep ( 500 ); + // parent->processEvents(); + } + // restart l2tpd + // if ( L2tpdProcess != 0) + // L2tpdProcess->kill(); + + sleep ( 1 ); + + L2tpdProcess = new QProcess ( this ); + // + if ( !GlobalConfig->pathToXl2tpd.isEmpty() && QFile ( GlobalConfig->pathToXl2tpd ).exists() ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Using %1." ).arg ( "xl2tpd" ),GlobalConfig->debug ); + L2tpdProcess->addArgument ( GlobalConfig->pathToXl2tpd ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Using %1." ).arg ( "l2tpd" ),GlobalConfig->debug ); + L2tpdProcess->addArgument ( GlobalConfig->pathToL2tpd ); + } + L2tpdProcess->addArgument ( "-p" ); + L2tpdProcess->addArgument ( "/var/run/l2tpd" + GlobalConfig->currentProfile->getName() + ".pid" ); + L2tpdProcess->addArgument ( "-c" ); + L2tpdProcess->addArgument ( tmpPath + "l2tpd." + GlobalConfig->currentProfile->getName() + ".conf" ); + L2tpdProcess->addArgument ( "-s" ); + L2tpdProcess->addArgument ( tmpPath + "l2tp-secrets" + GlobalConfig->currentProfile->getName() ); + L2tpdProcess->addArgument ( "-D" ); + + if ( !L2tpdProcess->start ( env ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "l2tpd" ), GlobalConfig->error ); + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( "l2tpd" ) ); + setGuiStatus ( disconnected ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "%1 was already running. It was killed and restarted." ).arg ( "l2tpd" ), GlobalConfig->info ); + } + + abort = false; + } + } + } + else if ( ProcessMsg_connect.find ( "Connection closed to", 0 , FALSE ) > -1 ) + { + ErrorMsg=true; + GlobalConfig->appendLogEntry ( QString ( "[l2tpd err] " + i18n ( "Connection was closed." ) ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( "pppd exited for call", 0 , FALSE ) > -1 ) + { + ErrorMsg=true; + GlobalConfig->appendLogEntry ( QString ( "[l2tpd err] " + i18n ( "pppd exited for call" ) ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( "unrecognized option", 0 , FALSE ) > -1 ) + { + ErrorMsg=true; + GlobalConfig->appendLogEntry ( QString ( "[l2tpd err] " + i18n ( "unknown option in generated config file, please report to maintainer." ) ) , GlobalConfig->error ); + abort = true; + } + + + // normal + if ( NormalMsg ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( "[l2tpd] " + ProcessMsg_connect, GlobalConfig->debug ); + } + else if ( ErrorMsg ) + { + GlobalConfig->appendLogEntry ( "[l2tpd err] " + ProcessMsg_connect, GlobalConfig->error ); + } + + if ( abort ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "pppd" ) , GlobalConfig->debug ); + //terminateConnection ( L2tpdProcess ); + disconnectClicked(); + GlobalConfig->status = GlobalConfig->disconnected; + setGuiStatus ( disconnected ); + + + // remove kvpnc entries from secrets file + if ( GlobalConfig->currentProfile->getAuthMethod() == "chap" || GlobalConfig->currentProfile->getAuthMethod() == "mschap" || GlobalConfig->currentProfile->getAuthMethod() == "mschap-v2" ) + { + // remove kvpnc entries from chap-secerets + QFile ChapSecretsFile ( "/etc/ppp/chap-secrets" ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "pppd secrets file: %1" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + QTextStream stream ( &ChapSecretsFile ); + if ( ChapSecretsFile.open ( IO_ReadOnly ) ) + { + QString line = ""; + QString chapsecret_content = ""; + bool kvpnc_start_marker_found = false; + bool kvpnc_end_marker_found = false; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' + if ( line == "# --- generated by kvpnc. Do not edit it." ) + { + kvpnc_end_marker_found = true; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "End marker in %1 found" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + } + if ( line == "# +++ generated by kvpnc. Do not edit it." ) + { + kvpnc_start_marker_found = true; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Start marker in %1 found" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + } + + if ( kvpnc_start_marker_found == false ) + { + chapsecret_content += line; + chapsecret_content += '\n'; + } + } + ChapSecretsFile.close(); + if ( ChapSecretsFile.remove() ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 successfully removed" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + // ChapSecretsFile.setName("/etc/ppp/chap-secrets2"); + if ( ChapSecretsFile.open ( IO_WriteOnly ) ) + { + stream.setDevice ( &ChapSecretsFile ); + stream << chapsecret_content; + ChapSecretsFile.close(); + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 sucessfully rewritten" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 rewrite failed" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->error ); + } + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 remove failed" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->error ); + } + + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "File %1 could not opened!" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->error ); + } + } + if ( GlobalConfig->currentProfile->getAuthMethod() == "pap" ) + { + // remove kvpnc entries from pap-secerets + QFile papSecretsFile ( "/etc/ppp/pap-secrets" ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "pppd secrets file: %1" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + QTextStream stream ( &papSecretsFile ); + if ( papSecretsFile.open ( IO_ReadOnly ) ) + { + QString line = ""; + QString papsecret_content = ""; + bool kvpnc_start_marker_found = false; + bool kvpnc_end_marker_found = false; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' + if ( line == "# --- generated by kvpnc. Do not edit it." ) + { + kvpnc_end_marker_found = true; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "End marker in %1 found" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + } + if ( line == "# +++ generated by kvpnc. Do not edit it." ) + { + kvpnc_start_marker_found = true; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Start marker in %1 found" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + } + + if ( kvpnc_start_marker_found == false ) + { + papsecret_content += line; + papsecret_content += '\n'; + } + } + papSecretsFile.close(); + if ( papSecretsFile.remove() ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 successfully removed" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + // papSecretsFile.setName("/etc/ppp/pap-secrets2"); + if ( papSecretsFile.open ( IO_WriteOnly ) ) + { + stream.setDevice ( &papSecretsFile ); + stream << papsecret_content; + papSecretsFile.close(); + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 sucessfully rewritten" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 rewrite failed" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->error ); + } + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 remove failed" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->error ); + } + + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "File %1 could not opened!" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->error ); + } + } + + } + else + { + // success + if ( connectSuccess ) + { + + sec = hour = min = 0; + + GlobalConfig->status = GlobalConfig->connected; + + disconnect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + connect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + durationTimer.start ( 1000, FALSE ); + setGuiStatus ( connected ); + + + setFirewallAfterConnect(); + if ( GlobalConfig->currentProfile->getExecuteCmdAfterConnect() ) + executeCommandAfterConnect(); + + sleep ( 2 ); + + if ( GlobalConfig->currentProfile->getUseAdditionalNetworkRoutes() && !GlobalConfig->currentProfile->getAdditionalNetworkRoutes().isEmpty() ) + addAdditionalNetworkRoutes(); + + //FIXME make it better + PppdDevice = "ppp0"; + NetworkInterface iface ( GlobalConfig, parent ); + if ( iface.interfaceExist ( PppdDevice ) ) + { + TunnelInterfaceIP = iface.getInterfaceIP ( PppdDevice ); + GlobalConfig->appendLogEntry ( i18n ( "Tunnel device: %1\n" ).arg ( PppdDevice ), GlobalConfig->debug ); + if ( !TunnelInterfaceIP.isEmpty() ) + GlobalConfig->appendLogEntry ( i18n ( "Tunnel interface IP address: %1\n" ).arg ( TunnelInterfaceIP ), GlobalConfig->debug ); + } + + + if ( GlobalConfig->currentProfile->getUseConnectionStatusCheck() ) + { + startConnectionStatusCheck(); + } + } + + } +// if (GlobalConfig->appPointer->hasPendingEvents ()) +// GlobalConfig->appPointer->processEvents(); + } +} + +void KVpnc::processStderr_l2tpd() +{ + QString ProcessMsg_connect_raw = L2tpdBufferStderrString; + QStringList ProcessMsg_connect_list = QStringList::split ( '\n',ProcessMsg_connect_raw ); + L2tpdBufferStderrString =""; + + for ( QStringList::Iterator it = ProcessMsg_connect_list.begin(); it != ProcessMsg_connect_list.end(); ++it ) + { + + bool NormalMsg = true; + bool ErrorMsg = false; + QString ProcessMsg_connect = *it; + bool abort = false; + bool connectSuccess = false; + + + + if ( GlobalConfig->KvpncDebugLevel > 7 ) + GlobalConfig->appendLogEntry ( QString ( "[l2tpd err raw] " + ProcessMsg_connect ) , GlobalConfig->debug ); + // +// if ( ProcessMsg_connect.length() > 3 ) + { + + // GlobalConfig->appendLogEntry ( QString( "[l2tpd err] " + ProcessMsg_connect ) , GlobalConfig->error ); + + if ( ProcessMsg_connect.find ( "Maximum retries exceeded for tunnel", 0 , FALSE ) > -1 ) + { + ErrorMsg=true; + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( QString ( "[l2tpd] " + i18n ( "Maximum retries of L2TP connect try exceeded for tunnel, waiting a moment..." ) ) , GlobalConfig->debug ); + // abort=true; + } + else if ( ProcessMsg_connect.find ( "l2tp_call:Connecting to host", 0 , FALSE ) > -1 ) + { + NormalMsg=true; + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( QString ( "[l2tpd] " + i18n ( "l2tp_call:Connecting to host" ) ) , GlobalConfig->debug ); + // abort=true; + } + else if ( ProcessMsg_connect.find ( "maximum retries exceeded.", 0 , FALSE ) > -1 ) + { + ErrorMsg=true; + GlobalConfig->appendLogEntry ( QString ( "[l2tpd err] " + i18n ( "Maximum of L2TP connect retries exceeded, giving up." ) ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( "Connection closed to", 0 , FALSE ) > -1 ) + { + ErrorMsg=true; + GlobalConfig->appendLogEntry ( QString ( "[l2tpd err] " + i18n ( "Connection was closed." ) ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( "pppd exited for call", 0 , FALSE ) > -1 ) + { + ErrorMsg=true; + GlobalConfig->appendLogEntry ( QString ( "[l2tpd err] " + i18n ( "pppd exited for call" ) ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( "Unable to load config file", 0 , FALSE ) > -1 ) + { + ErrorMsg=true; + KMessageBox::error ( this, i18n ( "Syntax error in config detected. Please report that to the KVpnc maintainer." ) ); + GlobalConfig->appendLogEntry ( QString ( "[l2tpd err] " + i18n ( "Error in generated config file for l2tpd, please report to maintainer." ) ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( "init_network: Unable to bind socket. Terminating", 0 , FALSE ) > -1 || ProcessMsg_connect.find ( "Unable to bind socket: Address already in use", 0 , FALSE ) > -1 ) + { + ErrorMsg=true; + bool kill_l2tpd=true; + + QString deamon="xl2tpd"; + if ( !GlobalConfig->pathToXl2tpd.isEmpty() && QFile ( GlobalConfig->pathToXl2tpd ).exists() ) + { + deamon="xl2tpd"; + if ( !GlobalConfig->doKillXl2tpdIfStillRunning ) + { + GlobalConfig->appendLogEntry ( QString ( "[l2tpd err] " + i18n ( "Bind to given port has been failed. Another %1 process is running. Please stop %1 first." ).arg ( deamon ) ) , GlobalConfig->debug ); + abort = true; + kill_l2tpd=false; + } + } + else + { + deamon="l2tpd"; + if ( !GlobalConfig->doKillL2tpdIfStillRunning ) + { + GlobalConfig->appendLogEntry ( QString ( "[l2tpd err] " + i18n ( "Bind to given port has been failed. Another %1 process is running. Please stop %1 first." ).arg ( deamon ) ) , GlobalConfig->debug ); + abort = true; + kill_l2tpd=false; + } + } + + if ( kill_l2tpd == true ) + { + QProcess killl2tpdprocess ( this ); + killl2tpdprocess.addArgument ( GlobalConfig->pathToKillall ); + if ( !GlobalConfig->pathToXl2tpd.isEmpty() && QFile ( GlobalConfig->pathToXl2tpd ).exists() ) + killl2tpdprocess.addArgument ( "xl2tpd" ); + else + killl2tpdprocess.addArgument ( "l2tpd" ); + + if ( !killl2tpdprocess.start() ) + { + GlobalConfig->appendLogEntry ( i18n ( "%1 could not be killed." ).arg ( "l2tpd" ) , GlobalConfig->error ); + GlobalConfig->appendLogEntry ( QString ( "[l2tpd err] " + i18n ( "Bind to given port has been failed. Another %1 process is running. Please stop %1 first." ).arg ( deamon ) ) , GlobalConfig->debug ); + abort = true; + } + else + { + while ( killl2tpdprocess.isRunning() ) + { + usleep ( 500 ); + // parent->processEvents(); + } + // restart l2tpd + // if ( L2tpdProcess != 0) + // L2tpdProcess->kill(); + + sleep ( 1 ); + + L2tpdProcess = new QProcess ( this ); + // + if ( !GlobalConfig->pathToXl2tpd.isEmpty() && QFile ( GlobalConfig->pathToXl2tpd ).exists() ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Using %1." ).arg ( "xl2tpd" ),GlobalConfig->debug ); + L2tpdProcess->addArgument ( GlobalConfig->pathToXl2tpd ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Using %1." ).arg ( "l2tpd" ),GlobalConfig->debug ); + L2tpdProcess->addArgument ( GlobalConfig->pathToL2tpd ); + } + L2tpdProcess->addArgument ( "-p" ); + L2tpdProcess->addArgument ( "/var/run/l2tpd" + GlobalConfig->currentProfile->getName() + ".pid" ); + L2tpdProcess->addArgument ( "-c" ); + L2tpdProcess->addArgument ( tmpPath + "l2tpd." + GlobalConfig->currentProfile->getName() + ".conf" ); + L2tpdProcess->addArgument ( "-s" ); + L2tpdProcess->addArgument ( tmpPath + "l2tp-secrets" + GlobalConfig->currentProfile->getName() ); + L2tpdProcess->addArgument ( "-D" ); + + if ( !L2tpdProcess->start ( env ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "l2tpd" ), GlobalConfig->error ); + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( "l2tpd" ) ); + setGuiStatus ( disconnected ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "%1 was already running. It was killed and restarted." ).arg ( "l2tpd" ), GlobalConfig->debug ); + } + + abort = false; + } + } + } + // control_finish: Connection established to 192.168.10.222, 1701. Local: 55406, Remote: 37911. + else if ( ProcessMsg_connect.find ( "Connection established", 0 , FALSE ) > -1 ) + { + NormalMsg=true; + GlobalConfig->appendLogEntry ( QString ( "[l2tpd] " + i18n ( "Low level connection to %1 established." ).arg ( GlobalConfig->currentProfile->getGateway() ) ) , GlobalConfig->success ); + abort = false; + } + else if ( ProcessMsg_connect.find ( "Call established", 0 , FALSE ) > -1 ) + { + NormalMsg=true; + GlobalConfig->appendLogEntry ( QString ( "[l2tpd] " + i18n ( "Low level connection to %1 established." ).arg ( GlobalConfig->currentProfile->getGateway() ) ) , GlobalConfig->info ); + abort = false; + if ( !GlobalConfig->pathToXl2tpd.isEmpty() && QFile ( GlobalConfig->pathToXl2tpd ).exists() ) + { + GlobalConfig->appendLogEntry ( QString ( "[l2tpd] " + i18n ( "Low level connection %1 established." ).arg ( GlobalConfig->currentProfile->getGateway() ) ) , GlobalConfig->info ); + + abort = false; + } + + disconnect ( &L2tpWaitForPppUpTimer, SIGNAL ( timeout() ), this, SLOT ( checkL2tpPppUp() ) ); + connect ( &L2tpWaitForPppUpTimer, SIGNAL ( timeout() ), this, SLOT ( checkL2tpPppUp() ) ); + L2tpWaitForPppUpTimer.start ( 1000, FALSE ); + + } + else if ( ProcessMsg_connect.find ( "Connecting to host", 0 , FALSE ) > -1 ) + { + NormalMsg=true; + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "%1 is connecting to host %2..." ).arg ( "l2tpd" ).arg ( GlobalConfig->currentProfile->getGateway() ),GlobalConfig->debug ); + } + else if ( ProcessMsg_connect.find ( "Listening on IP address", 0 , FALSE ) > -1 + || ProcessMsg_connect.find ( "Calling on tunnel", 0 , FALSE ) > -1 ) + { + NormalMsg=true; + abort = false; + } + else if ( GlobalConfig->status != GlobalConfig->connected && ProcessMsg_connect.find ( "check_control: control, cid =", 0 , FALSE ) > -1 ) + { + NormalMsg=true; + // cid is greather than 0 + if ( ProcessMsg_connect.section ( ',', 1, 1 ).section ( '=', 1, 1 ).stripWhiteSpace() != "0" ) // check_control: control, cid = 17467, Ns = 2, Nr = 4 + { + GlobalConfig->appendLogEntry ( QString ( "[l2tpd] " + i18n ( "L2TP tunnel to %1 established." ).arg ( GlobalConfig->currentProfile->getGateway() ) ) , GlobalConfig->success ); + + abort = false; + connectSuccess = true; + } + } + else if ( ProcessMsg_connect.find ( "Connecting to host", 0 , FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( QString ( "[l2tpd] " + i18n ( "L2TP connection to %1 established." ).arg ( GlobalConfig->currentProfile->getGateway() ) ) , GlobalConfig->success ); + abort = false; + if ( !GlobalConfig->pathToXl2tpd.isEmpty() && QFile ( GlobalConfig->pathToXl2tpd ).exists() ) + { + GlobalConfig->appendLogEntry ( QString ( "[l2tpd] " + i18n ( "L2TP tunnel to %1 established." ).arg ( GlobalConfig->currentProfile->getGateway() ) ) , GlobalConfig->success ); + + abort = false; + } + connectSuccess=true; + } + + if ( connectSuccess ) + { + sec = hour = min = 0; + + GlobalConfig->status = GlobalConfig->connected; + + disconnect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + connect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + durationTimer.start ( 1000, FALSE ); + setGuiStatus ( connected ); + + + setFirewallAfterConnect(); + if ( GlobalConfig->currentProfile->getExecuteCmdAfterConnect() ) + executeCommandAfterConnect(); + + sleep ( 2 ); + + if ( GlobalConfig->currentProfile->getUseAdditionalNetworkRoutes() && !GlobalConfig->currentProfile->getAdditionalNetworkRoutes().isEmpty() ) + addAdditionalNetworkRoutes(); + + if ( GlobalConfig->currentProfile->getUseConnectionStatusCheck() ) + { + startConnectionStatusCheck(); + } + + } + + + // normal + if ( NormalMsg ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( "[l2tpd] " + ProcessMsg_connect, GlobalConfig->debug ); + } + else if ( ErrorMsg ) + { + GlobalConfig->appendLogEntry ( "[l2tpd err] " + ProcessMsg_connect, GlobalConfig->error ); + } + if ( abort ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "l2tpd" ) , GlobalConfig->debug ); + disconnectClicked(); + GlobalConfig->status = GlobalConfig->disconnected; + setGuiStatus ( disconnected ); + + if ( GlobalConfig->currentProfile->getAuthMethod() == "chap" || GlobalConfig->currentProfile->getAuthMethod() == "mschap" || GlobalConfig->currentProfile->getAuthMethod() == "mschap-v2" ) + { + // remove kvpnc entries from chap-secerets + QFile ChapSecretsFile ( "/etc/ppp/chap-secrets" ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "pppd secrets file: %1" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + QTextStream stream ( &ChapSecretsFile ); + if ( ChapSecretsFile.open ( IO_ReadOnly ) ) + { + QString line = ""; + QString chapsecret_content = ""; + bool kvpnc_start_marker_found = false; + bool kvpnc_end_marker_found = false; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' + if ( line == "# --- generated by kvpnc. Do not edit it." ) + { + kvpnc_end_marker_found = true; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "End marker in %1 found" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + } + if ( line == "# +++ generated by kvpnc. Do not edit it." ) + { + kvpnc_start_marker_found = true; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Start marker in %1 found" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + } + + if ( kvpnc_start_marker_found == false ) + { + chapsecret_content += line; + chapsecret_content += '\n'; + } + } + ChapSecretsFile.close(); + if ( ChapSecretsFile.remove() ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 successfully removed" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + // ChapSecretsFile.setName("/etc/ppp/chap-secrets2"); + if ( ChapSecretsFile.open ( IO_WriteOnly ) ) + { + stream.setDevice ( &ChapSecretsFile ); + stream << chapsecret_content; + ChapSecretsFile.close(); + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 sucessfully rewritten" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 rewrite failed" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->error ); + } + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 remove failed" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->error ); + } + + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "File %1 could not opened!" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->error ); + } + } + if ( GlobalConfig->currentProfile->getAuthMethod() == "pap" ) + { + // remove kvpnc entries from pap-secerets + QFile papSecretsFile ( "/etc/ppp/pap-secrets" ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "pppd secrets file: %1" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + QTextStream stream ( &papSecretsFile ); + if ( papSecretsFile.open ( IO_ReadOnly ) ) + { + QString line = ""; + QString papsecret_content = ""; + bool kvpnc_start_marker_found = false; + bool kvpnc_end_marker_found = false; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' + if ( line == "# --- generated by kvpnc. Do not edit it." ) + { + kvpnc_end_marker_found = true; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "End marker in %1 found" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + } + if ( line == "# +++ generated by kvpnc. Do not edit it." ) + { + kvpnc_start_marker_found = true; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Start marker in %1 found" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + } + + if ( kvpnc_start_marker_found == false ) + { + papsecret_content += line; + papsecret_content += '\n'; + } + } + papSecretsFile.close(); + if ( papSecretsFile.remove() ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 successfully removed" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + // papSecretsFile.setName("/etc/ppp/pap-secrets2"); + if ( papSecretsFile.open ( IO_WriteOnly ) ) + { + stream.setDevice ( &papSecretsFile ); + stream << papsecret_content; + papSecretsFile.close(); + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 sucessfully rewritten" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 rewrite failed" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->error ); + } + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "File %1 remove failed" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->error ); + } + + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "File %1 could not opened!" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->error ); + } + } + return ; + } + } +// if (GlobalConfig->appPointer->hasPendingEvents ()) +// GlobalConfig->appPointer->processEvents(); + } +} + +void KVpnc::readFromStdout_openl2tp() +{ + while ( OpenL2tpProcess != 0 && OpenL2tpProcess->canReadLineStdout() ) + { + bool abort=false; + bool connectSuccess=false; + ProcessMsg_connect = OpenL2tpProcess->readLineStdout(); + + if ( GlobalConfig->enableDebugOpenl2tp ) + { + GlobalConfig->appendLogEntry ( "[openl2tp] " + ProcessMsg_connect, GlobalConfig->debug ); + } + else + { + if ( ProcessMsg_connect.find ( "FUNC:", 0 , FALSE ) < 0 && ProcessMsg_connect.find ( "FSM:", 0 , FALSE ) < 0 && ProcessMsg_connect.find ( "AVP:", 0 , FALSE ) < 0 && ProcessMsg_connect.find ( "PROTO:", 0 , FALSE ) < 0 && ProcessMsg_connect.find ( "XPRT:", 0 , FALSE ) < 0 && ProcessMsg_connect.find ( "DATA:", 0 , FALSE ) < 0 ) + GlobalConfig->appendLogEntry ( "[openl2tp] " + ProcessMsg_connect, GlobalConfig->debug ); + } + + if ( ProcessMsg_connect.find ( "address", 0 , FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Got IP address" ), GlobalConfig->debug ); + + if ( ProcessMsg_connect.find ( "local", 0 , FALSE ) > -1 ) + { + TunnelInterfaceIP = ProcessMsg_connect.section ( ' ',4,4 ); + if ( !TunnelInterfaceIP.isEmpty() ) + GlobalConfig->appendLogEntry ( i18n ( "Tunnel interface IP address: %1\n" ).arg ( TunnelInterfaceIP ), GlobalConfig->debug ); + + connectSuccess=true; + } + } + else if ( ProcessMsg_connect.find ( "event ICRP_ACCEPT in state WAITREPLY", 0 , FALSE ) > -1 ) + { + // short before low level connection up + } + else if ( ProcessMsg_connect.find ( "starting UNIX pppd", 0 , FALSE ) > -1 ) + { + // low level connection sure up + } + else if ( ProcessMsg_connect.find ( "state change: WAITCTLREPLY --> ESTABLISHED", 0 , FALSE ) > -1 ) + { + // low level connection up + } + else if ( ProcessMsg_connect.find ( "Using interface", 0 , FALSE ) > -1 ) + { + + L2tpPppDevice = ProcessMsg_connect.section ( ' ',2,2 ); + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Tunnel device: %1\n" ).arg ( L2tpPppDevice ), GlobalConfig->debug ); + } + else if ( ProcessMsg_connect.find ( "authentication succeeded:", 0 , FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Authentication succeeded." ), GlobalConfig->debug ); + abort = false; +// connectSuccess=true; + } + else if ( ProcessMsg_connect.find ( "Connection terminated.", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Connection has been terminated." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Connection has been terminated." ), GlobalConfig->info ); + abort = true; + } + + + + if ( connectSuccess ) + { + sec = hour = min = 0; + + GlobalConfig->status = GlobalConfig->connected; + + disconnect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + connect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + durationTimer.start ( 1000, FALSE ); + setGuiStatus ( connected ); + + + setFirewallAfterConnect(); + if ( GlobalConfig->currentProfile->getExecuteCmdAfterConnect() ) + executeCommandAfterConnect(); + + sleep ( 2 ); + + if ( GlobalConfig->currentProfile->getUseAdditionalNetworkRoutes() && !GlobalConfig->currentProfile->getAdditionalNetworkRoutes().isEmpty() ) + addAdditionalNetworkRoutes(); + + if ( GlobalConfig->currentProfile->getUseConnectionStatusCheck() ) + { + startConnectionStatusCheck(); + } + + } + + if ( abort ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "openl2tpd" ) , GlobalConfig->debug ); + disconnectClicked(); + GlobalConfig->status = GlobalConfig->disconnected; + setGuiStatus ( disconnected ); + + return ; + } + + } +} + +void KVpnc::readFromStderr_openl2tp() +{ + while ( OpenL2tpProcess != 0 && OpenL2tpProcess->canReadLineStderr() ) + { + bool abort=false; + ProcessMsg_connect = OpenL2tpProcess->readLineStderr(); + GlobalConfig->appendLogEntry ( "[openl2tp err] " + ProcessMsg_connect, GlobalConfig->error ); + + + if ( ProcessMsg_connect.find ( "parse error", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Error in generated configuration file for \"%1\", please contact KVpnc team." ).arg ( "openl2tpd" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Error in generated configuration file for \"%1\", please contact KVpnc team." ).arg ( "openl2tpd" ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( "File /var/run/openl2tpd.pid already exists", 0 , FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Lock file of %1 still exists. Please remove it if %2 is not running." ).arg ( "openl2tpd" ).arg ( "openl2tpd" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Lock file of %1 still exists." ).arg ( "openl2tpd" ) , GlobalConfig->error ); + abort = true; + } + + + if ( abort ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "l2tpd" ) , GlobalConfig->debug ); + disconnectClicked(); + GlobalConfig->status = GlobalConfig->disconnected; + setGuiStatus ( disconnected ); + + return ; + } + } +} + +void KVpnc::readFromStdout_startstopOpenl2tp() +{ + while ( StartStopOpenl2tpProcess != 0 && StartStopOpenl2tpProcess->canReadLineStdout() ) + { + bool abort=false; + bool connectSuccess=false; + ProcessMsg_connect = StartStopOpenl2tpProcess->readLineStdout(); + + if ( GlobalConfig->enableDebugOpenl2tp ) + { + GlobalConfig->appendLogEntry ( "[openl2tp] " + ProcessMsg_connect, GlobalConfig->debug ); + } + else + { + if ( ProcessMsg_connect.find ( "FUNC:", 0 , FALSE ) < 0 && ProcessMsg_connect.find ( "FSM:", 0 , FALSE ) < 0 && ProcessMsg_connect.find ( "AVP:", 0 , FALSE ) < 0 && ProcessMsg_connect.find ( "PROTO:", 0 , FALSE ) < 0 && ProcessMsg_connect.find ( "XPRT:", 0 , FALSE ) < 0 && ProcessMsg_connect.find ( "DATA:", 0 , FALSE ) < 0 ) + GlobalConfig->appendLogEntry ( "[openl2tp] " + ProcessMsg_connect, GlobalConfig->debug ); + } + + + if ( abort ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "openl2tpd" ) , GlobalConfig->debug ); + disconnectClicked(); + GlobalConfig->status = GlobalConfig->disconnected; + setGuiStatus ( disconnected ); + + return ; + } + + } +} + +void KVpnc::readFromStderr_startstopOpenl2tp() +{ + while ( StartStopOpenl2tpProcess != 0 && StartStopOpenl2tpProcess->canReadLineStderr() ) + { + bool abort=false; + ProcessMsg_connect = StartStopOpenl2tpProcess->readLineStderr(); + GlobalConfig->appendLogEntry ( "[openl2tp err] " + ProcessMsg_connect, GlobalConfig->error ); + + + if ( abort ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "openl2tp" ) , GlobalConfig->debug ); + disconnectClicked(); + GlobalConfig->status = GlobalConfig->disconnected; + setGuiStatus ( disconnected ); + + return ; + } + } +} + +void KVpnc::readFromStdout_vtun() +{ + while ( VtundProcess->canReadLineStdout() ) + { + bool NormalMsg = true; + bool ErrorMsg = false; + ProcessMsg_connect = VtundProcess->readLineStdout(); + // ProcessMsg_connect = QString( VtundProcess->readStdout() ); + //if ( !ProcessMsg_connect.isEmpty() ) + + + bool abort = false; + bool connectSuccess = false; + + + + /* + if ( ProcessMsg_connect.find ( "init_network: Unable to bind socket. Terminating", 0 , FALSE ) > -1 ) + { + + }*/ + + if ( ProcessMsg_connect.find ( "Connection refused(111)",0,FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Connection refused." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Connection refused." ),GlobalConfig->error ); + abort=true; + ErrorMsg=true; + } + else if ( ProcessMsg_connect.find ( " Exit ",0,FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( i18n ( "%1 has been exited." ),GlobalConfig->error ); + abort=true; + ErrorMsg=true; + } + + + if ( abort ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "vtund" ) , GlobalConfig->debug ); + //terminateConnection ( L2tpdProcess ); + disconnectClicked(); + GlobalConfig->status = GlobalConfig->disconnected; + setGuiStatus ( disconnected ); + + } + // success + if ( connectSuccess ) + { + + sec = hour = min = 0; + + GlobalConfig->status = GlobalConfig->connected; + + disconnect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + connect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + durationTimer.start ( 1000, FALSE ); + setGuiStatus ( connected ); + + + setFirewallAfterConnect(); + if ( GlobalConfig->currentProfile->getExecuteCmdAfterConnect() ) + executeCommandAfterConnect(); + + sleep ( 2 ); + + if ( GlobalConfig->currentProfile->getUseAdditionalNetworkRoutes() && !GlobalConfig->currentProfile->getAdditionalNetworkRoutes().isEmpty() ) + addAdditionalNetworkRoutes(); + +// //FIXME make it better +// PppdDevice = "ppp0"; +// NetworkInterface iface ( GlobalConfig, parent ); +// if ( iface.interfaceExist ( PppdDevice ) ) +// { +// TunnelInterfaceIP = iface.getInterfaceIP ( PppdDevice ); +// GlobalConfig->appendLogEntry ( i18n ( "Tunnel device: %1\n" ).arg ( PppdDevice ), GlobalConfig->debug ); +// if ( !TunnelInterfaceIP.isEmpty() ) +// GlobalConfig->appendLogEntry ( i18n ( "Tunnel interface IP address: %1\n" ).arg ( TunnelInterfaceIP ), GlobalConfig->debug ); +// } + + + if ( GlobalConfig->currentProfile->getUseConnectionStatusCheck() ) + { + startConnectionStatusCheck(); + } + } +// // normal + if ( NormalMsg ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( "[vtun] " + ProcessMsg_connect, GlobalConfig->debug ); + } + else +// if ( ErrorMsg ) + { + GlobalConfig->appendLogEntry ( "[vtun err] " + ProcessMsg_connect, GlobalConfig->error ); + } + } +} + +void KVpnc::readFromStderr_vtun() +{ + while ( VtundProcess->canReadLineStderr() ) + { + bool NormalMsg = true; + bool ErrorMsg = false; + ProcessMsg_connect = VtundProcess->readLineStderr(); + // // ProcessMsg_connect = QString( L2tpdProcess->readStderr() ); + // // if ( !ProcessMsg_connect.isEmpty() ) + // + bool abort = false; + bool connectSuccess = false; + + if ( ProcessMsg_connect.find ( "Session ",0,FALSE ) > -1 && ProcessMsg_connect.find ( "opened",0,FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Session opened." ),GlobalConfig->debug ); + } + if ( ProcessMsg_connect.find ( "compression ",0,FALSE ) > -1 && ProcessMsg_connect.find ( "initialized",0,FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Compression initialized." ),GlobalConfig->debug ); + } + if ( ProcessMsg_connect.find ( "UDP ",0,FALSE ) > -1 && ProcessMsg_connect.find ( "initialized",0,FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "UDP initialized." ),GlobalConfig->debug ); + } + if ( ProcessMsg_connect.find ( "encryption ",0,FALSE ) > -1 && ProcessMsg_connect.find ( "initialized",0,FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Encryption initialized." ),GlobalConfig->debug ); + + // FIXME only if encryption is activated (always!?) + connectSuccess=TRUE; + } + if ( ProcessMsg_connect.find ( "Connection refused(111)",0,FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Connection refused." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Connection refused." ),GlobalConfig->error ); + abort=true; + ErrorMsg=true; + } +// // if ( ProcessMsg_connect.find(" Exit ",0,FALSE) > -1 ) +// // { +// // GlobalConfig->appendLogEntry(i18n("%1 has been exited.").arg("vtund"),GlobalConfig->error); +// // abort=true; +// // ErrorMsg=true; +// // } + if ( ProcessMsg_connect.find ( "Connection denied by ",0,FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( i18n ( "Connection denied. Password wrong?" ),GlobalConfig->error ); + abort=true; + ErrorMsg=true; + } + if ( ProcessMsg_connect.find ( "Connection closed by other side",0,FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( i18n ( "Connection was closed by the remote host. Please check your settings." ),GlobalConfig->error ); + abort=true; + ErrorMsg=true; + } + if ( ProcessMsg_connect.find ( "syntax error",0,FALSE ) > -1 || ProcessMsg_connect.find ( "No hosts defined",0,FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Syntax error in config detected. Please report that to the KVpnc maintainer." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Syntax error in config detected. Please report that to the KVpnc maintainer." ),GlobalConfig->error ); + abort=true; + ErrorMsg=true; + } + + if ( ProcessMsg_connect.find ( "allocate pseudo tty",0,FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Can't allocate pseudo tty.\nPlease check that your kernel has LEGACY PTY=y or recompile patched vtun. You can get the patch for UNIX98 PTS here: %1" ).arg ( QString ( "http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=451931" ) ) ); + GlobalConfig->appendLogEntry ( i18n ( "Can't allocate pseudo tty." ),GlobalConfig->error ); + abort=true; + ErrorMsg=true; + } + +// else if ( GlobalConfig->status != GlobalConfig->connected && ProcessMsg_connect.find ( "check_control: control, cid =", 0 , FALSE ) > -1 ) +// { +// NormalMsg=true; +// // cid is greather than 0 +// if ( ProcessMsg_connect.section ( ',', 1, 1 ).section ( '=', 1, 1 ).stripWhiteSpace() != "0" ) // check_control: control, cid = 17467, Ns = 2, Nr = 4 +// { +// GlobalConfig->appendLogEntry ( QString ( "[l2tpd] " + i18n ( "L2TP tunnel to %1 established." ).arg ( GlobalConfig->currentProfile->getGateway() ) ) , GlobalConfig->success ); +// +// abort = false; +// connectSuccess = true; +// } +// } + + + // success + if ( connectSuccess ) + { + + GlobalConfig->appendLogEntry ( i18n ( "Connection established." ), GlobalConfig->success ); + + sec = hour = min = 0; + + GlobalConfig->status = GlobalConfig->connected; + + disconnect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + connect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + durationTimer.start ( 1000, FALSE ); + setGuiStatus ( connected ); + connectSuccess = false; + + setFirewallAfterConnect(); + if ( GlobalConfig->currentProfile->getExecuteCmdAfterConnect() ) + executeCommandAfterConnect(); + + if ( GlobalConfig->currentProfile->getUseAdditionalNetworkRoutes() && !GlobalConfig->currentProfile->getAdditionalNetworkRoutes().isEmpty() ) + { + addAdditionalNetworkRoutes(); + // GlobalConfig->appendLogEntry( i18n( "Add additional network routes..." ), GlobalConfig->debug ); + } + else + { + // GlobalConfig->appendLogEntry( i18n( "No additional routes to add." ), GlobalConfig->debug ); + } + if ( GlobalConfig->currentProfile->getUseConnectionStatusCheck() ) + { + startConnectionStatusCheck(); + } + } + +// // normal + if ( NormalMsg ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( "[vtun] " + ProcessMsg_connect, GlobalConfig->debug ); + } + else +// if ( ErrorMsg ) + { + GlobalConfig->appendLogEntry ( "[vtun err] " + ProcessMsg_connect, GlobalConfig->error ); + } + + if ( abort ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "vtund" ) , GlobalConfig->debug ); + disconnectClicked(); + GlobalConfig->status = GlobalConfig->disconnected; + setGuiStatus ( disconnected ); + return ; + } + GlobalConfig->appPointer->processEvents(); + } +} + +void KVpnc::readFromStdout_ssh ( KProcess *, char *buffer, int buflen ) +{ +// while ( SshProcess->canReadLineStdout() ) +// { +// ProcessMsg_connect = SshProcess->readLineStdout(); + // QString ProcessMsg_connect = QString( SshProcess->readStdout() ); + +// QString ProcessMsg_connect = QString::fromLatin1(buffer, buflen); + QString ProcessMsg_connect_raw = QString::fromLatin1 ( buffer, buflen ); + QStringList ProcessMsg_connect_raw_list = QStringList::split ( "debug1:",ProcessMsg_connect_raw ); + + for ( QStringList::Iterator it = ProcessMsg_connect_raw_list.begin(); it != ProcessMsg_connect_raw_list.end(); ++it ) + { + ProcessMsg_connect = *it; + + bool NormalMsg = true; + bool ErrorMsg = false; + bool abort = false; + bool connectSuccess=false; + + if ( ProcessMsg_connect.find ( "ssh_is_up", 0 , FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( i18n ( "SSH tunnel is now up" ) , GlobalConfig->info ); + connectSuccess=true; + } + + if ( ProcessMsg_connect.find ( "REMOTE HOST IDENTIFICATION HAS CHANGED!", 0 , FALSE ) > -1 ) + { + ErrorMsg=true; + KMessageBox::error ( this, i18n ( "Remote host identification has changed!" ) ) ; + GlobalConfig->appendLogEntry ( i18n ( "Remote host identification has changed!" ) , GlobalConfig->error ); + abort=false; + } + else if ( ProcessMsg_connect.find ( "Host key verification failed", 0 , FALSE ) > -1 ) + { + ErrorMsg=true; + KMessageBox::error ( this, i18n ( "Host key verification failed" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Host key verification failed" ) , GlobalConfig->error ); + abort=true; + } + else if ( ProcessMsg_connect.find ( "has changed and you have requested strict checking", 0 , FALSE ) > -1 ) + { + ErrorMsg=true; + KMessageBox::error ( this, i18n ( "Hostkey for %1 has changed and you have requested strict checking" ).arg ( GlobalConfig->TmpGatewayIP ) ); + GlobalConfig->appendLogEntry ( i18n ( "Hostkey for %1 has changed and you have requested strict checking" ).arg ( GlobalConfig->TmpGatewayIP ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( ": No route to host", 0 , FALSE ) > -1 ) + { + ErrorMsg=true; + KMessageBox::error ( this, i18n ( "No route to host %1" ).arg ( GlobalConfig->TmpGatewayIP ) ); + GlobalConfig->appendLogEntry ( i18n ( "No route to host %1" ).arg ( GlobalConfig->TmpGatewayIP ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( "Authentication succeeded", 0 , FALSE ) > -1 ) + { + ErrorMsg=false; +// KMessageBox::error ( this, i18n ( "Authentication succeeded" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Authentication succeeded" ) , GlobalConfig->info ); +// abort = true; + } + else if ( ProcessMsg_connect.find ( "Permission denied", 0 , FALSE ) > -1 ) + { + ErrorMsg = true; timer.stop(); + KMessageBox::error(this, i18n("Permission denied.")); + connectCounter = 0; + GlobalConfig->appendLogEntry(i18n("Permission denied") , GlobalConfig->error); + // disconnect ( &timer, SIGNAL ( timeout() ), this, SLOT ( slotConnectTimedOut() ) ); + abort = true; KMessageBox::error(this, i18n("Authentication has failed.")); + GlobalConfig->appendLogEntry(i18n("Authentication has failed.") , GlobalConfig->error); + //abort = true; + AuthRetry = true; + GlobalConfig->haveUserData = false; + connectClicked(); + } + else if ( ProcessMsg_connect.find ( "Remote: Failed to open the tunnel device.", 0 , FALSE ) > -1 ) + { + ErrorMsg=true; + KMessageBox::error ( this, i18n ( "Remote: Failed to open the tunnel device." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Remote: Failed to open the tunnel device." ), GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( "open failed: administratively prohibited: open failed", 0 , FALSE ) > -1 ) + { + ErrorMsg=true; + KMessageBox::error ( this, i18n ( "Action administratively prohibited" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Action administratively prohibited" ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( "Connection established.", 0 , FALSE ) > -1 ) + { +// KMessageBox::error ( this, i18n ( "Low level connection to host %1 established." ).arg ( GlobalConfig->TmpGatewayIP ) ); + GlobalConfig->appendLogEntry ( i18n ( "Low level connection to host %1 established." ).arg ( GlobalConfig->TmpGatewayIP ) , GlobalConfig->info ); + } + + else if ( ProcessMsg_connect.find ( "No more authentication methods to try.", 0 , FALSE ) > -1 ) + { + ErrorMsg=true; + KMessageBox::error ( this, i18n ( "No more authentication methods to try." ) ); + GlobalConfig->appendLogEntry ( i18n ( "No more authentication methods to try." ) , GlobalConfig->error ); + abort = true; + } + if ( abort ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "ssh" ) , GlobalConfig->debug ); + disconnectClicked(); + GlobalConfig->status = GlobalConfig->disconnected; + setGuiStatus ( disconnected ); + return ; + } + + // success + else if ( connectSuccess ) + { + sec = hour = min = 0; + + GlobalConfig->status = GlobalConfig->connected; + + disconnect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + connect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + durationTimer.start ( 1000, FALSE ); + setGuiStatus ( connected ); + connectSuccess = false; + + GlobalConfig->appendLogEntry ( i18n ( "Connection established." ), GlobalConfig->success ); + + // GlobalConfig->appendLogEntry( QString("connectstring: "+ProcessMsg_connect), GlobalConfig->debug ); + + SshDevice = ""; + if ( !PppdDevice.isEmpty() ) + SshDevice = PppdDevice; + else + { + if ( GlobalConfig->currentProfile->getTunnelDeviceType() == "tun" ) + SshDevice="tun0"; + else + SshDevice= "tap0"; + } + + // write ssh..up + QFile sshupfile ( tmpPath + "ssh." + GlobalConfig->currentProfile->getName() + ".up" ); + QTextStream sshupstream ( &sshupfile ); + if ( sshupfile.open ( IO_WriteOnly ) ) + { + sshupstream << "#!"<< GlobalConfig->InterpreterShell << "\n"; + sshupstream << "# generated by kvpnc. Do not edit it." << "\n"; + sshupstream << "# profile: " + GlobalConfig->currentProfile->getName() << "\n\n"; + + /* update dns? */ + if ( GlobalConfig->currentProfile->getUseDnsUpdate() ) + { + sshupstream << "cat /etc/resolv.conf > " << tmpPath + "resolv.conf." + GlobalConfig->currentProfile->getName() << "\n"; + sshupstream << "if [ -x /sbin/resolvconf ] ; then\n"; + sshupstream << " echo > /dev/null" << "\n"; + sshupstream << "else" << "\n"; + sshupstream << " echo \"# generated by kvpnc. Do not edit it.\" > /etc/resolv.conf" << "\n"; + sshupstream << "fi\n"; + } + else + { + /* dont update dns */ + } + + sshupstream << "\n"; + if ( GlobalConfig->currentProfile->getTunnelDeviceType() == "tun" ) + sshupstream << GlobalConfig->pathToIfconfig << " "+SshDevice+" " + GlobalConfig->currentProfile->getLocalVirtualIP() + " pointopoint " << GlobalConfig->currentProfile->getRemoteVirtualIP() << " up" <<"\n"; + if ( GlobalConfig->currentProfile->getTunnelDeviceType() == "tap" ) + sshupstream << GlobalConfig->pathToIfconfig << " "+SshDevice+" " + GlobalConfig->currentProfile->getLocalVirtualIP() << " up" <<"\n"; + + NetworkInterface iface ( GlobalConfig , parent ); + TunnelInterfaceIP = iface.getInterfaceIP ( SshDevice ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[ssh] " + i18n ( "Tunnel IP: %1" ).arg ( TunnelInterfaceIP ) , GlobalConfig->debug ); + + QString resolvtemp=""; + bool no_nameserver=true; + /* update dns? */ + if ( GlobalConfig->currentProfile->getUseDnsUpdate() ) + { + sshupstream << "if [ -x /sbin/resolvconf ] ; then\n"; + sshupstream << " dev=$1\n"; + sshupstream << " if [ -z $dev ] ; then\n"; + + // FIXME make devs dynamiclly + if ( GlobalConfig->currentProfile->getTunnelDeviceType() == "tun" ) + sshupstream << " dev=\"tun0\"\n"; + else + sshupstream << " dev=\"tap0\"\n"; + sshupstream << "fi\n"; + if ( !TmpDns1.isEmpty() || !TmpDns2.isEmpty() ) + { + no_nameserver=false; + sshupstream << "if [ -x /sbin/resolvconf ] ; then\n"; + if ( TmpDns2.isEmpty() ) + { + resolvtemp += "nameserver " + TmpDns1+ "\n"; + } + else + { + resolvtemp += "nameserver " + TmpDns1 + "\nnameserver " + TmpDns2+"\n"; + } + + sshupstream << "else" << "\n"; + sshupstream << " echo >> /etc/resolv.conf\n"; + sshupstream << " echo \"# generated by kvpnc. Do not edit it.\" > /etc/resolv.conf" << "\n"; + sshupstream << " echo \"# profile: " + GlobalConfig->currentProfile->getName() << "\" >> /etc/resolv.conf" << "\n"; + sshupstream << " echo \"nameserver " << TmpDns1 << "\" >> /etc/resolv.conf" << "\n"; + if ( !TmpDns2.isEmpty() ) + sshupstream << " echo \"nameserver " << TmpDns2 << "\" >> /etc/resolv.conf" << "\n"; + + } + + sshupstream << "fi" << "\n"; + + sshupstream << "# " << "\n"; + + if ( ( GlobalConfig->currentProfile->getUseDnsServer() && !GlobalConfig->currentProfile->getDnsServer().isEmpty() ) || ( GlobalConfig->currentProfile->getUseSearchDomainInResolvConf() && ! !GlobalConfig->currentProfile->getSearchDomainInResolvConf().isEmpty() ) || ( GlobalConfig->currentProfile->getUseDomainInResolvConf() && ! !GlobalConfig->currentProfile->getDomainInResolvConf().isEmpty() ) ) + { + sshupstream << "if [ -x /sbin/resolvconf ] ; then\n"; + sshupstream << " dev=$1\n"; + sshupstream << " if [ -z $dev ] ; then\n"; + if ( GlobalConfig->currentProfile->getTunnelDeviceType() == "tun" ) + sshupstream << " dev=\"tun0\"\n"; + else + sshupstream << " dev=\"tap0\"\n"; + sshupstream << " fi\n"; + + if ( GlobalConfig->currentProfile->getUseDnsServer() && !GlobalConfig->currentProfile->getDnsServer().isEmpty() ) + resolvtemp+= "nameserver "+GlobalConfig->currentProfile->getDnsServer() +"\n"; + if ( GlobalConfig->currentProfile->getUseSearchDomainInResolvConf() && !GlobalConfig->currentProfile->getSearchDomainInResolvConf().isEmpty() ) + resolvtemp+= "search "+GlobalConfig->currentProfile->getSearchDomainInResolvConf() +"\n"; + if ( GlobalConfig->currentProfile->getUseDomainInResolvConf() && !GlobalConfig->currentProfile->getDomainInResolvConf().isEmpty() ) + resolvtemp+= "domain "+GlobalConfig->currentProfile->getDomainInResolvConf() +"\n"; + sshupstream << "else\n"; + if ( GlobalConfig->currentProfile->getUseDnsServer() && !GlobalConfig->currentProfile->getDnsServer().isEmpty() ) + { + sshupstream << " echo \"nameserver " << GlobalConfig->currentProfile->getDnsServer() + "\" >> /etc/resolv.conf\n"; + no_nameserver=false; + } + if ( GlobalConfig->currentProfile->getUseSearchDomainInResolvConf() && !GlobalConfig->currentProfile->getSearchDomainInResolvConf().isEmpty() ) + sshupstream << "echo \"search " << GlobalConfig->currentProfile->getSearchDomainInResolvConf() + "\" >> /etc/resolv.conf\n"; + if ( GlobalConfig->currentProfile->getUseDomainInResolvConf() && !GlobalConfig->currentProfile->getDomainInResolvConf().isEmpty() ) + sshupstream << "echo \"domain " << GlobalConfig->currentProfile->getDomainInResolvConf() + "\" >> /etc/resolv.conf\n"; + sshupstream << "fi\n"; + } + + + sshupstream << "if [ -x /sbin/resolvconf ] ; then\n"; + sshupstream << " echo \""+resolvtemp+"\" > "+tmpPath + "resolv.conf." + GlobalConfig->currentProfile->getName() << "\n"; + if (no_nameserver == true) + { + sshupstream << " cat " + tmpPath + "/resolv.conf.before.kvpnc_" + GlobalConfig->currentProfile->getName() + " | grep nameserver >> " + tmpPath + "resolv.conf." + GlobalConfig->currentProfile->getName() + "\n"; + } + sshupstream << " cat "+tmpPath + "resolv.conf." + GlobalConfig->currentProfile->getName() + " | /sbin/resolvconf -a $dev\n"; + + /* crissi: -u seems not nessesary */ + //sshupstream << " cat "+tmpPath + tmpPath + "resolv.conf." + GlobalConfig->currentProfile->getName() +" | /sbin/resolvconf -u\n"; + + if (!GlobalConfig->holdGeneratedScripts) + sshupstream << " rm -f "+tmpPath + "resolv.conf." + GlobalConfig->currentProfile->getName()+"\n"; + + if ( no_nameserver==true ) + { + sshupstream << "else\n"; + sshupstream << " cat " << tmpPath + "/resolv.conf.before.kvpnc_" + GlobalConfig->currentProfile->getName() + " | grep nameserver >> /etc/resolv.conf\n"; + } + + sshupstream << "fi\n"; + // sshupstream << "chmod u-w /etc/resolv.conf\n"; + } + else + { + /* dont update dns */ + } + + sshupstream << GlobalConfig->pathToIp << " route show | grep default > " << OldDefaultroute << "\n"; + + if ( GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + { + sshupstream << GlobalConfig->pathToIp + " route replace default dev " + SshDevice + "\n"; + + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Setting extra route: %1 over %2 gw %3" ).arg ( GlobalConfig->currentProfile->getGateway() ).arg ( GlobalConfig->OldDefaultDev ).arg ( GlobalConfig->OldDefaultGw ), GlobalConfig->debug ); + + sshupstream << GlobalConfig->pathToIp + " route add " + GlobalConfig->currentProfile->getGateway() + "/32 via " << GlobalConfig->OldDefaultGw << " dev " << GlobalConfig->OldDefaultDev << "\n"; + + } + + GlobalConfig->NewDefaultGw = iface.getGatewayOfDefaultInterface(); + + if ( GlobalConfig->NewDefaultGw != "0.0.0.0" ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Setting extra route: %1 over %2 gw %3" ).arg ( "0.0.0.0" ).arg ( SshDevice ).arg ( GlobalConfig->NewDefaultGw ), GlobalConfig->debug ); + sshupstream << GlobalConfig->pathToIp + " route add 0.0.0.0 via " << GlobalConfig->NewDefaultGw << " dev " << SshDevice << "\n"; + } + sshupfile.close(); + } + + + QProcess *SshUpProcess = new QProcess ( this ); + SshUpProcess->addArgument ( GlobalConfig->InterpreterShell ); + SshUpProcess->addArgument ( tmpPath + "ssh." + GlobalConfig->currentProfile->getName() + ".up" ); + + if ( !SshUpProcess->start ( env ) ) + { + KMessageBox::sorry ( this, i18n ( "\"%1\" (%2) start failed!" ).arg ( "SshUpScript" ).arg ( tmpPath + "ssh." + GlobalConfig->currentProfile->getName() + ".up" ) ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" (%2) started." ).arg ( "SshUpScript" ).arg ( tmpPath + "ssh." + GlobalConfig->currentProfile->getName() + ".up" ) , GlobalConfig->debug ); + while ( SshUpProcess->isRunning() ) + { + parent->QApplication::processEvents(); + sleep ( 1 ); + } + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" (%2) finished." ).arg ( "SshUpScript" ).arg ( tmpPath + "ssh." + GlobalConfig->currentProfile->getName() + ".up" ) , GlobalConfig->debug ); + } + delete SshUpProcess; + SshUpProcess=0L; + + setFirewallAfterConnect(); + if ( GlobalConfig->currentProfile->getExecuteCmdAfterConnect() ) + executeCommandAfterConnect(); + + if ( GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + { + tmpPath = locateLocal ( "data", "kvpnc/" ); + QString SshReplaceDefaultRouteScript = tmpPath + "ssh_replace_defaultroute." + GlobalConfig->currentProfile->getName() + ".sh"; + + QFile file ( SshReplaceDefaultRouteScript ); + QTextStream stream ( &file ); + if ( file.open ( IO_WriteOnly ) ) + { + stream << "# generated by kvpnc. Do not edit it." << "\n"; + stream << "\n"; + file.close(); + ReplaceDefaultRouteProcess = new QProcess ( this ); + ReplaceDefaultRouteProcess->addArgument ( GlobalConfig->InterpreterShell ); + ReplaceDefaultRouteProcess->addArgument ( SshReplaceDefaultRouteScript ); + if ( !ReplaceDefaultRouteProcess->start ( env ) ) + { + KMessageBox::sorry ( this, i18n ( "\"%1\" %2 start failed!" ).arg ( i18n ( "ssh replace route process" ) ).arg ( tmpPath + "pppd_replace_defaultroute." + GlobalConfig->currentProfile->getName() + ".sh" ) ); + // disconnectClicked(); + // setGuiStatus(disconnected); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" (%2) started." ).arg ( i18n ( "ssh replace route process" ) ).arg ( tmpPath + "ssh_replace_defaultroute." + GlobalConfig->currentProfile->getName() + ".sh" ) , GlobalConfig->debug ); + + while ( ReplaceDefaultRouteProcess->isRunning() ) + { + sleep ( 1 ); + } + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" (%2) finished." ).arg ( i18n ( "ssh replace route process" ) ).arg ( tmpPath + "ssh_replace_defaultroute." + GlobalConfig->currentProfile->getName() + ".sh" ) , GlobalConfig->debug ); + } + delete ReplaceDefaultRouteProcess; + ReplaceDefaultRouteProcess=0L; + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "Could not write: \"%1\" (%2)!" ).arg ( i18n ( "ssh replace route script" ) ).arg ( SshReplaceDefaultRouteScript ), GlobalConfig->error ); + } + + + } + // PptpRouteProcess = new QProcess( this ); + // PptpRouteProcess->addArgument( GlobalConfig->pathToRoute ); + // PptpRouteProcess->addArgument( "add" ); + // PptpRouteProcess->addArgument( "-net" ); + // PptpRouteProcess->addArgument( GlobalConfig->currentProfile->getRemoteNetAddr() + "/" + GlobalConfig->currentProfile->getRemoteNetMask() ); + // PptpRouteProcess->addArgument( pppdev ); + + // if ( !PptpRouteProcess->start(env) ) + // { + // KMessageBox::sorry( this, i18n( "\"%1\" start failed!" ).arg( i18n( "pppd route process" ) ) ); + // disconnectClicked(); + // setGuiStatus(disconnected); + // } + // else + { + // GlobalConfig->appendLogEntry ( i18n( "\"%1\" started." ).arg( i18n( "pppd route process" ) ), GlobalConfig->info ); + +// while (PptpRouteProcess->isRunning()) +// { +// sleep(1); +// } +// delete PptpRouteProcess; +// PptpRouteProcess=0L; + + if ( GlobalConfig->currentProfile->getUseAdditionalNetworkRoutes() && !GlobalConfig->currentProfile->getAdditionalNetworkRoutes().isEmpty() ) + addAdditionalNetworkRoutes(); + + if ( GlobalConfig->currentProfile->getUseConnectionStatusCheck() ) + { + startConnectionStatusCheck(); + } + } + } + + if ( ErrorMsg ) + GlobalConfig->appendLogEntry ( "[ssh error] " + ProcessMsg_connect, GlobalConfig->error ); + else + GlobalConfig->appendLogEntry ( "[ssh] " + ProcessMsg_connect, GlobalConfig->info ); + + } +} + +void KVpnc::readFromStderr_ssh ( KProcess *, char *buffer, int buflen ) +{ +// while ( SshProcess->canReadLineStderr() ) +// { +// ProcessMsg_connect = SshProcess->readLineStderr(); + // QString ProcessMsg_connect = QString( SshProcess->readStderr() ); +// QString ProcessMsg_connect = QString::fromLatin1(buffer, buflen); + + QString ProcessMsg_connect_raw = QString::fromLatin1 ( buffer, buflen ); + QStringList ProcessMsg_connect_raw_list = QStringList::split ( "debug1:",ProcessMsg_connect_raw ); + + for ( QStringList::Iterator it = ProcessMsg_connect_raw_list.begin(); it != ProcessMsg_connect_raw_list.end(); ++it ) + { + ProcessMsg_connect = *it; + +// bool NormalMsg = true; + bool ErrorMsg = false; + bool abort = false; + + if ( ProcessMsg_connect.find ( "REMOTE HOST IDENTIFICATION HAS CHANGED!", 0 , FALSE ) > -1 ) + { + ErrorMsg=true; + KMessageBox::error ( this, i18n ( "Remote host identification has changed!" ) ) ; + GlobalConfig->appendLogEntry ( i18n ( "Remote host identification has changed!" ) , GlobalConfig->error ); + abort=false; + } + else if ( ProcessMsg_connect.find ( "Host key verification failed", 0 , FALSE ) > -1 ) + { + ErrorMsg=true; + KMessageBox::error ( this, i18n ( "Host key verification failed" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Host key verification failed" ) , GlobalConfig->error ); + abort=true; + } + else if ( ProcessMsg_connect.find ( "has changed and you have requested strict checking", 0 , FALSE ) > -1 ) + { + ErrorMsg=true; + KMessageBox::error ( this, i18n ( "Hostkey for %1 has changed and you have requested strict checking" ).arg ( GlobalConfig->TmpGatewayIP ) ); + GlobalConfig->appendLogEntry ( i18n ( "Hostkey for %1 has changed and you have requested strict checking" ).arg ( GlobalConfig->TmpGatewayIP ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( ": No route to host", 0 , FALSE ) > -1 ) + { + ErrorMsg=true; + KMessageBox::error ( this, i18n ( "No route to host %1" ).arg ( GlobalConfig->TmpGatewayIP ) ); + GlobalConfig->appendLogEntry ( i18n ( "No route to host %1" ).arg ( GlobalConfig->TmpGatewayIP ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( "Authentication succeeded", 0 , FALSE ) > -1 ) + { + ErrorMsg=false; +// KMessageBox::error ( this, i18n ( "Authentication succeeded" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Authentication succeeded" ) , GlobalConfig->info ); +// abort = true; + } + else if ( ProcessMsg_connect.find ( "Remote: Failed to open the tunnel device.", 0 , FALSE ) > -1 ) + { + ErrorMsg=true; + KMessageBox::error ( this, i18n ( "Remote: Failed to open the tunnel device." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Remote: Failed to open the tunnel device." ), GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( "open failed: administratively prohibited: open failed", 0 , FALSE ) > -1 ) + { + ErrorMsg=true; + KMessageBox::error ( this, i18n ( "Action administratively prohibited" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Action administratively prohibited" ) , GlobalConfig->error ); + abort = true; + } + else if ( ProcessMsg_connect.find ( "Connection established.", 0 , FALSE ) > -1 ) + { +// KMessageBox::error ( this, i18n ( "Low level connection to host %1 established." ).arg ( GlobalConfig->TmpGatewayIP ) ); + GlobalConfig->appendLogEntry ( i18n ( "Low level connection to host %1 established." ).arg ( GlobalConfig->TmpGatewayIP ) , GlobalConfig->info ); + } + else if ( ProcessMsg_connect.find ( "No more authentication methods to try.", 0 , FALSE ) > -1 ) + { + ErrorMsg=true; + KMessageBox::error ( this, i18n ( "No more authentication methods to try." ) ); + GlobalConfig->appendLogEntry ( i18n ( "No more authentication methods to try." ) , GlobalConfig->error ); + abort = true; + } + if ( ErrorMsg ) + GlobalConfig->appendLogEntry ( "[ssh error] " + ProcessMsg_connect, GlobalConfig->error ); + else + GlobalConfig->appendLogEntry ( "[ssh] " + ProcessMsg_connect, GlobalConfig->info ); + if ( abort ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "There is a reason for stop connecting, terminating \"%1\" process." ).arg ( "ssh" ) , GlobalConfig->debug ); + disconnectClicked(); + GlobalConfig->status = GlobalConfig->disconnected; + setGuiStatus ( disconnected ); + return ; + } + } +} + +void KVpnc::readFromStdout_ping() +{ + //while ( PingProcess->canReadLineStdout() ) { + //ProcessMsg_connect = PingProcess->readLineStdout(); + ProcessMsg_connect = QString ( PingProcess->readStdout() ); + + //mw->DebugOutput->append( "raw out (pingtest): " + ProcessMsg_connect ); + + if ( ProcessMsg_connect.find ( "time=", 0, FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( "[ping] " + ProcessMsg_connect, GlobalConfig->success ); + KNotifyClient::event ( topLevelWidget() ->winId(), "ping success", i18n ( "Ping was successful." ) ); + } + else if ( ProcessMsg_connect.find ( "100 % packet loss", 0, FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( "[ping err] " + ProcessMsg_connect, GlobalConfig->error ); + KNotifyClient::event ( topLevelWidget() ->winId(), "ping failed", i18n ( "Ping has failed." ) ); + } + else + { + if ( ProcessMsg_connect.find ( "failed to bind", 0, FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Binding interface failed!" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Binding interface failed!" ) , GlobalConfig->error ); + } + else if ( ProcessMsg_connect.find ( "Destination Host Unreachable", 0, FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Destination host is unreachable!" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Destination host is unreachable!" ) , GlobalConfig->error ); + } + + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( "[ping]: " + ProcessMsg_connect, GlobalConfig->debug ); + } + // } +} + +void KVpnc::readFromStderr_ping() +{ + // while ( PingProcess->canReadLineStderr() ) { + // ProcessMsg_connect = PingProcess->readLineStderr(); + ProcessMsg_connect = QString ( PingProcess->readStderr() ); + + //mw->DebugOutput->append( "raw err (pingtest): " + ProcessMsg_connect ); + if ( ProcessMsg_connect.find ( "time=", 0, FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( "[ping] " + ProcessMsg_connect, GlobalConfig->success ); + } + else if ( ProcessMsg_connect.find ( "100 % packet loss", 0, FALSE ) > -1 ) + { + GlobalConfig->appendLogEntry ( "[ping err] " + ProcessMsg_connect, GlobalConfig->error ); + } + else + { + if ( ProcessMsg_connect.find ( "failed to bind", 0, FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Binding interface failed!" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Binding interface failed!" ) , GlobalConfig->error ); + } + if ( ProcessMsg_connect.find ( "Destination Host Unreachable", 0, FALSE ) > -1 ) + { + KMessageBox::error ( this, i18n ( "Destination host is unreachable!" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Destination host is unreachable!" ) , GlobalConfig->error ); + } + } + //} +} + +void KVpnc::readFromStdout_route() +{ + //while ( RouteProcess->canReadLineStdout() ) { + //ProcessMsg_connect = RouteProcess->readLineStdout(); + ProcessMsg_connect = QString ( RouteProcess->readStdout() ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[route] " + ProcessMsg_connect, GlobalConfig->debug ); + + // } +} + +void KVpnc::readFromStderr_route() +{ + // while ( RouteProcess->canReadLineStderr() ) { + // ProcessMsg_connect = RouteProcess->readLineStderr(); + ProcessMsg_connect = QString ( RouteProcess->readStderr() ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[route err] " + ProcessMsg_connect, GlobalConfig->error ); + //} +} + +void KVpnc::readFromStdout_disconnect() +{ + while ( DisconnectProcess->canReadLineStdout() ) + { + ProcessMsg_connect = DisconnectProcess->readLineStdout(); + //ProcessMsg_connect = QString( DisconnectProcess->readStdout() ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[disconnect] " + ProcessMsg_connect, GlobalConfig->debug ); + + } +} + +void KVpnc::readFromStderr_disconnect() +{ + while ( DisconnectProcess->canReadLineStderr() ) + { + ProcessMsg_connect = DisconnectProcess->readLineStderr(); + //ProcessMsg_connect = QString( DisconnectProcess->readStderr() ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[disconnect err] " + ProcessMsg_connect, GlobalConfig->error ); + } +} + +void KVpnc::readFromStdout_setVirtualIP() +{ + QString msg = QString ( SetVirtualIPProcess->readStdout() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( msg, GlobalConfig->debug ); +} + +void KVpnc::readFromStderr_setVirtualIP() +{ + QString msg = QString ( SetVirtualIPProcess->readStderr() ); + GlobalConfig->appendLogEntry ( msg, GlobalConfig->error ); + setVirtualIPSuccess = false; +} + +void KVpnc::readFromStdout_connectionStatusCheck() +{ + QString msg = QString ( ConnectionStatusCheckProcess->readStdout() ); + + if ( msg.find ( "PING ok.", 0 , FALSE ) > -1 ) + { + /* Connection alive */ + if ( GlobalConfig->KvpncDebugLevel > 0 ) + { + if ( GlobalConfig->currentProfile->getDoPingIP() ) + { + GlobalConfig->appendLogEntry ( i18n ( "Ping to %1 within %2 checks every %3s was ok." ).arg ( GlobalConfig->currentProfile->getPingHostIP() ).arg ( GlobalConfig->currentProfile->getConnectionStatusCheckSuccessCount() ).arg ( GlobalConfig->currentProfile->getConnectionStatusInterval() ), GlobalConfig->debug ); + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "Ping to %1 within %2 checks every %3s was ok." ).arg ( GlobalConfig->currentProfile->getGateway() ).arg ( GlobalConfig->currentProfile->getConnectionStatusCheckSuccessCount() ).arg ( GlobalConfig->currentProfile->getConnectionStatusInterval() ), GlobalConfig->debug ); + } + } + } + if ( msg.find ( "PING failed!", 0 , FALSE ) > -1 ) + { + /* Connection dead?! */ + if ( GlobalConfig->KvpncDebugLevel > 0 ) + { + if ( GlobalConfig->currentProfile->getDoPingIP() ) + { + GlobalConfig->appendLogEntry ( i18n ( "Ping to %1 within %2 checks every %3s has been failed!" ).arg ( GlobalConfig->currentProfile->getPingHostIP() ).arg ( GlobalConfig->currentProfile->getConnectionStatusCheckSuccessCount() ).arg ( GlobalConfig->currentProfile->getConnectionStatusInterval() ), GlobalConfig->error ); + KNotifyClient::event ( topLevelWidget() ->winId(), "connection lost", i18n ( "Ping to %1 within %2 checks every %3s has been failed!" ).arg ( GlobalConfig->currentProfile->getPingHostIP() ).arg ( GlobalConfig->currentProfile->getConnectionStatusCheckSuccessCount() ).arg ( GlobalConfig->currentProfile->getConnectionStatusInterval() ) ); + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "Ping to %1 within %2 checks every %3s has been failed!" ).arg ( GlobalConfig->currentProfile->getGateway() ).arg ( GlobalConfig->currentProfile->getConnectionStatusCheckSuccessCount() ).arg ( GlobalConfig->currentProfile->getConnectionStatusInterval() ), GlobalConfig->error ); + KNotifyClient::event ( topLevelWidget() ->winId(), "connection lost", i18n ( "Ping to %1 within %2 checks every %3s has been failed!" ).arg ( GlobalConfig->currentProfile->getGateway() ).arg ( GlobalConfig->currentProfile->getConnectionStatusCheckSuccessCount() ).arg ( GlobalConfig->currentProfile->getConnectionStatusInterval() ) ); + } + } + disconnect ( ConnectionStatusCheckProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_connectionStatusCheck() ) ); + disconnect ( ConnectionStatusCheckProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_connectionStatusCheck() ) ); + ConnectionStatusCheckProcess->kill(); + // kill connection + disconnectClicked(); + + if ( GlobalConfig->currentProfile->getDoReconnectAfterConnectionLost() ) + { + if ( GlobalConfig->currentProfile->getUseReconnectDelay() ) + { + GlobalConfig->appendLogEntry ( i18n ( "Waiting %1s for reconnect..." ).arg ( GlobalConfig->currentProfile->getReconnectDelay() ), GlobalConfig->info ); + for ( int time = 0; time <= GlobalConfig->currentProfile->getReconnectDelay() * 1000;time += 200 ) + { + usleep ( 200 ); + GlobalConfig->appPointer->processEvents(); + } + } + // if (GlobalConfig->KvpncDebugLevel > 0) + GlobalConfig->appendLogEntry ( i18n ( "Reconnect after connection lost enabled, reconnecting..." ), GlobalConfig->info ); + connectClicked(); + } + } +} + +void KVpnc::readFromStderr_connectionStatusCheck() +{ + QString msg = QString ( ConnectionStatusCheckProcess->readStderr() ); + + // if ( msg.find( "PING ok.", 0 , FALSE ) > -1 ) + // { + // /* Connection alive */ + // if (GlobalConfig->KvpncDebugLevel > 0) + // GlobalConfig->appendLogEntry ( i18n("Ping to %1 within %2 checks every %3s was ok.").arg(GlobalConfig->currentProfile->getGateway()).arg(GlobalConfig->currentProfile->getConnectionStatusCheckSuccessCount()).arg(GlobalConfig->currentProfile->getConnectionStatusInterval()), GlobalConfig->debug ); + // + // } + // if ( msg.find( "PING failed!", 0 , FALSE ) > -1 ) + // { + // /* Connection dead?! */ + // if (GlobalConfig->KvpncDebugLevel > 0) + // GlobalConfig->appendLogEntry ( i18n("Ping to %1 within %2 checks every %3s was ok.").arg(GlobalConfig->currentProfile->getGateway()).arg(GlobalConfig->currentProfile->getConnectionStatusCheckSuccessCount()).arg( GlobalConfig->currentProfile->getConnectionStatusInterval() ), GlobalConfig->error ); + // KNotifyClient::event( topLevelWidget()->winId(), "connection lost",i18n("Ping to %1 within %2 checks every %3s was ok.").arg(GlobalConfig->currentProfile->getGateway()).arg(GlobalConfig->currentProfile->getConnectionStatusCheckSuccessCount()).arg(GlobalConfig->currentProfile->getConnectionStatusInterval()) ); + // // kill connection + // disconnectClicked(); + // } +} + +void KVpnc::readFromStdout_executeCommandBeforeConnect() +{ + while ( CmdBeforeConnectProcess->canReadLineStdout() ) + { + ProcessMsg_connect = CmdBeforeConnectProcess->readLineStdout(); + //ProcessMsg_connect = QString( CmdBeforeConnectProcess->readStdout() ); + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( "[CmdBeforeConnect] " + ProcessMsg_connect, GlobalConfig->debug ); + } +} + +void KVpnc::readFromStderr_executeCommandBeforeConnect() +{ + while ( CmdBeforeConnectProcess->canReadLineStderr() ) + { + ProcessMsg_connect = CmdBeforeConnectProcess->readLineStderr(); + //ProcessMsg_connect = QString( CmdBeforeConnectProcess->readStderr() ); + + GlobalConfig->appendLogEntry ( "[CmdBeforeConnect err] " + ProcessMsg_connect, GlobalConfig->error ); + } +} + +void KVpnc::readFromStdout_executeCommandAfterConnect() +{ + while ( CmdAfterConnectProcess->canReadLineStdout() ) + { + ProcessMsg_connect = CmdAfterConnectProcess->readLineStdout(); + //ProcessMsg_connect = QString( CmdAfterConnectProcess->readStdout() ); + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( "[CmdAfterConnect] " + ProcessMsg_connect, GlobalConfig->debug ); + } +} + +void KVpnc::readFromStderr_executeCommandAfterConnect() +{ + while ( CmdAfterConnectProcess->canReadLineStderr() ) + { + ProcessMsg_connect = CmdAfterConnectProcess->readLineStderr(); + //ProcessMsg_connect = QString( CmdAfterConnectProcess->readStderr() ); + + GlobalConfig->appendLogEntry ( "[CmdAfterConnect err] " + ProcessMsg_connect, GlobalConfig->error ); + } +} + +void KVpnc::readFromStdout_executeCommandBeforeDisconnect() +{ + while ( CmdBeforeDisconnectProcess->canReadLineStdout() ) + { + ProcessMsg_connect = CmdBeforeDisconnectProcess->readLineStdout(); + //ProcessMsg_connect = QString( CmdBeforeDisconnectProcess->readStdout() ); + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( "[CmdBeforeDisconnect] " + ProcessMsg_connect, GlobalConfig->debug ); + } +} + +void KVpnc::readFromStderr_executeCommandBeforeDisconnect() +{ + while ( CmdBeforeDisconnectProcess->canReadLineStderr() ) + { + ProcessMsg_connect = CmdBeforeDisconnectProcess->readLineStderr(); + //ProcessMsg_connect = QString( CmdBeforeDisconnectProcess->readStderr() ); + + GlobalConfig->appendLogEntry ( "[CmdBeforeDisconnect err] " + ProcessMsg_connect, GlobalConfig->error ); + } +} + +void KVpnc::readFromStdout_executeCommandAfterDisconnect() +{ + while ( CmdAfterDisconnectProcess->canReadLineStdout() ) + { + ProcessMsg_connect = CmdAfterDisconnectProcess->readLineStdout(); + //ProcessMsg_connect = QString( CmdAfterDisconnectProcess->readStdout() ); + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( "[CmdAfterDisconnect] " + ProcessMsg_connect, GlobalConfig->debug ); + } +} + +void KVpnc::readFromStderr_executeCommandAfterDisconnect() +{ + while ( CmdAfterDisconnectProcess->canReadLineStderr() ) + { + ProcessMsg_connect = CmdAfterDisconnectProcess->readLineStderr(); + //ProcessMsg_connect = QString( CmdAfterDisconnectProcess->readStderr() ); + + GlobalConfig->appendLogEntry ( "[CmdAfterDisconnect err] " + ProcessMsg_connect, GlobalConfig->error ); + } +} + +void KVpnc::readCiscoVpncTestProcessOutput() +{ + QString msg = ""; + while ( TestCiscoVpncProcess->canReadLineStdout() ) + { + msg = QString ( TestCiscoVpncProcess->readLineStdout() ); + + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "msg: %1" ).arg ( msg ), GlobalConfig->debug ); + + if ( msg == "" ) + return ; + if ( msg.find ( "The VPN module is not loaded.", 0 , FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Virtual interface of cisco client is not present" ), GlobalConfig->debug ); + ciscoVpncRunning = false; + return; + } + else if ( msg.find ( "cisco_ipsec", 0 , FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Virtual interface of cisco client is present" ), GlobalConfig->debug ); + ciscoVpncRunning = true; + return; + } + } +} + +void KVpnc::terminateConnection ( QProcess *proc ) +{ + if ( proc->isRunning() ) + { +// proc->tryTerminate(); +// proc->tryTerminate(); +// proc->tryTerminate(); + + // QTimer::singleShot( 5000, proc, SLOT( kill() ) ); + + } + timer.stop(); + durationTimer.stop(); + GlobalConfig->status = GlobalConfig->disconnected; + connectCounter = 0; + setGuiStatus ( disconnected ); + +} + +void KVpnc::connectionEnded() +{ + durationTimer.stop(); + GlobalConfig->status = GlobalConfig->disconnected; + + if ( prevConnectionState == 1 ) //connecting + GlobalConfig->appendLogEntry ( i18n ( "Successful connect try canceled." ) , GlobalConfig->success ); + else + GlobalConfig->appendLogEntry ( i18n ( "Successful disconnected." ) , GlobalConfig->success ); + + + // clean up scripts + if ( !GlobalConfig->holdGeneratedScripts ) + { + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::cisco ) + { + + } + + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ciscoorig ) + { + QFile file ( QString ( "/etc/opt/cisco-vpnclient/Profiles/" ) +QString ( "kvpnc_" ) +QString ( GlobalConfig->currentProfile->getName() +".pcf" ) ); + file.remove(); + } + + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon ) + { + QFile file ( tmpPath + "setkey." + GlobalConfig->currentProfile->getName() + ".conf" ); + file.remove(); + file.setName ( tmpPath + "/setkey." + GlobalConfig->currentProfile->getName() + ".sh" ); + file.remove(); + file.setName ( tmpPath + "racoon." + GlobalConfig->currentProfile->getName() + ".conf" ); + file.remove(); + file.setName ( tmpPath + "iptables." + GlobalConfig->currentProfile->getName() + ".add_racoon.sh" ); + file.remove(); + file.setName ( tmpPath + "iptables." + GlobalConfig->currentProfile->getName() + ".remove_racoon.sh" ); + file.remove(); + file.setName ( tmpPath + "setkey." + GlobalConfig->currentProfile->getName() + ".remove_setkey.sh" ); + file.remove(); + + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::psk ) + { + file.setName ( tmpPath + "psk." + GlobalConfig->currentProfile->getName() + ".key" ); + file.remove(); + } + file.setName ( tmpPath + "racoon." + GlobalConfig->currentProfile->getName() + ".log" ); + file.remove(); + } // racoon + + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan ) + { + QFile file ( tmpPath + "iptables." + GlobalConfig->currentProfile->getName() + ".add_ipsec_freeswan.sh" ); + file.remove(); + file.setName ( tmpPath + "iptables." + GlobalConfig->currentProfile->getName() + ".remove_ipsec_freeswan.sh" ); + file.remove(); + + } // freeswan + + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::pptp ) + { + + } + + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::openvpn ) + { + + } + + } + + if ( prevConnectionState != 1 ) // connected + { + QString durationString ( i18n ( "%1:%2:%3" ).arg ( QString().sprintf ( "%02u", hour ) ).arg ( QString().sprintf ( "%02u", min ) , QString().sprintf ( "%02u", sec ) ) ); + GlobalConfig->appendLogEntry ( i18n ( "Connection duration was %1 hours, %2 minutes, %3 seconds" ).arg ( QString().sprintf ( "%02u", hour ), QString().sprintf ( "%02u", min ) , QString().sprintf ( "%02u", sec ) ), GlobalConfig->info ); + } + connectCounter = 0; + GlobalConfig->TmpPassword = ""; + GlobalConfig->TmpGroupPassword = ""; +} + +void KVpnc::slotConnectTimedOut() +{ + this->connectCounter++; + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::cisco ||GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ciscoorig ) + { + if ( connectCounter > GlobalConfig->connectSleepRetry && timer.isActive() ) + { + timer.stop(); + // it dont get it connected so we kill it :) + + GlobalConfig->appendLogEntry ( i18n ( "Timeout while connecting to %1. %2 connect process will be killed.!" ).arg ( GlobalConfig->currentProfile->getGateway() ).arg ( "vpnc" ), GlobalConfig->error ); + + if ( VpncProcess != 0 && VpncProcess->isRunning() ) + VpncProcess->kill(); + if ( CiscoVpncProcess != 0 && CiscoVpncProcess->isRunning() ) + CiscoVpncProcess->kill(); + + GlobalConfig->status = GlobalConfig->disconnected; + mw->buttonConnect->setEnabled ( true ); + mw->buttonDisconnect->setEnabled ( false ); + this->ConnectAction->setEnabled ( true ); + this->DisconnectAction->setEnabled ( false ); + //parent->statusBar() ->insertItem( i18n( "Connected" ), 2, 0, true ); + KVpncDock->setStatus ( disconnected ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Connection failed (timeout)." ), GlobalConfig->debug ); + disconnectClicked(); + slotStatusMsg ( i18n ( "Timeout while connecting to %1. %2 connect process will be killed.!" ).arg ( GlobalConfig->currentProfile->getGateway() ).arg ( "vpnc" ), ID_FLASH_MSG ); + slotStatusMsg ( i18n ( "Disconnected" ), ID_CONNECTION_MSG ); + QToolTip::remove( KVpncDock ); + QToolTip::add( KVpncDock, i18n ( "Disconnected" ) ); + connectCounter = 0; + setGuiStatus ( disconnected ); + KMessageBox::error ( this, i18n ( "Timeout while connecting to %1 (%2) after %3s. Please check if the VPN server is reachable and the settings (UDP/TCP, local port, UDP encapsulation port) are correct. Maybe the timeout must be increased too." ).arg ( GlobalConfig->currentProfile->getGateway() ).arg ( GlobalConfig->currentProfile->getName() ).arg ( GlobalConfig->tryConnectTimeout ) ); + } + else if ( GlobalConfig->currentProfile->getDoReconnectAfterConnectionLost() ) + { + GlobalConfig->appendLogEntry ( i18n ( "Waiting %1 seconds for connect..." ).arg ( GlobalConfig->connectSleepDelay ), GlobalConfig->info ); + slotStatusMsg ( i18n ( "Waiting for connect..." ), ID_FLASH_MSG ); + } + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan || GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { + timer.stop(); + GlobalConfig->appendLogEntry ( i18n ( "Timeout while connecting to %1. %2 connect process will be killed.!" ).arg ( GlobalConfig->currentProfile->getGateway() ).arg ( "ipsec" ), GlobalConfig->error ); + + disconnectClicked(); + + } +} + +void KVpnc::newSessionClicked() +{ + // call new profile dialog... + NewProfileDialog newdlg ( parent, this, i18n ( "New Profile" ), GlobalConfig ); + newdlg.exec(); + if ( newdlg.newProfileCreated ) + { + VpnAccountData * it; + bool nameOk = false; + bool ok; + QString newName=newdlg.getName(); + QString Oldname = newdlg.getName(); + while ( nameOk == false ) + { + for ( it = GlobalConfig->AccountList->first(); it; it = GlobalConfig->AccountList->next() ) + { + if ( ( it != GlobalConfig->currentProfile ) && ( it->getName() == newName ) ) + { + //account->setName( QString( account->getName() + "_2" ) ); + // KMessageBox::information ( this, i18n( "Profile name exists!\n It will be renamed to \"%1\"." ).arg( account->getName() ), i18n( "Name exist, renamed" ) ); + KMessageBox::error ( this, i18n ( "Profile name exists!" ), i18n ( "Name Exists" ) ); + + newName = KInputDialog::getText ( i18n ( "New Name" ), i18n ( "New name for profile:" ), QString ( Oldname + "_2" ), &ok ); + if ( ok == false ) + { + KMessageBox::information ( 0, i18n ( "Rename at new created profile was canceled." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Rename at new created profile was canceled." ), GlobalConfig->info ); + slotStatusMsg ( i18n ( "Rename at new created profile was canceled." ), ID_FLASH_MSG ); + return ; + } + } + } + if ( newName.isEmpty() ) + nameOk=false; + else + nameOk = true; + } + + if (nameOk) + { + profileAddedOrDeleted(); + mw->SessionCombo->setCurrentText (newName ); + + mw->SessionCombo->setEnabled ( TRUE ); + DeleteSessionAction->setEnabled ( TRUE ); + SaveSessionAction->setEnabled ( TRUE ); + ImportSessionAction->setEnabled ( TRUE ); + ConnectAction->setEnabled ( TRUE ); + mw->buttonConnect->setEnabled ( TRUE ); + + sessionToggled ( newdlg.getName() ); + + slotStatusMsg ( i18n ( "Profile \"%1\" added." ).arg ( mw->SessionCombo->currentText() ), ID_FLASH_MSG ); + GlobalConfig->appendLogEntry ( i18n ( "Profile \"%1\" added." ).arg ( mw->SessionCombo->currentText() ) , GlobalConfig->info ); + GlobalConfig->saveOptions(); + saveGuiOptions(); + + QuickConnectMenu->clear(); + for ( uint i = 0; i < GlobalConfig->AccountList->count();i++ ) + { + QuickConnectMenu->insertItem ( GlobalConfig->AccountList->at ( i ) ->getName() ); + } + + VpnAccountData * it; + for ( it = GlobalConfig->AccountList->first(); it; it = GlobalConfig->AccountList->next() ) + { + kdDebug() << "item: " << it->getName() << endl; + QuickConnectMenu->insertItem ( it->getName() ); + mw->SessionCombo->insertItem ( it->getName() ); + } + GlobalConfig->currentProfile = GlobalConfig->AccountList->first(); + mw->SessionCombo->setEnabled ( TRUE ); + mw->buttonConnect->setEnabled ( TRUE ); + this->sessionToggled ( GlobalConfig->currentProfile->getName() ); + + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "Rename at new created profile was canceled." ), GlobalConfig->info ); + slotStatusMsg ( i18n ( "Creating new profile canceled." ), ID_FLASH_MSG ); + GlobalConfig->appendLogEntry ( i18n ( "Creating new profile canceled." ), GlobalConfig->info ); + } + } + else + { + slotStatusMsg ( i18n ( "Creating new profile canceled." ), ID_FLASH_MSG ); + GlobalConfig->appendLogEntry ( i18n ( "Creating new profile canceled." ), GlobalConfig->info ); + } + +} + +void KVpnc::saveSessionClicked() +{ + GlobalConfig->appPointer->setOverrideCursor ( QCursor ( Qt::WaitCursor ) ); + GlobalConfig->appendLogEntry ( i18n ( "Saving profiles and global options..." ),GlobalConfig->info ); + this->slotStatusMsg ( i18n ( "Saving profiles and global options..." ), ID_STATUS_MSG ); + if ( !GlobalConfig->AccountList->isEmpty() ) + { + GlobalConfig->saveOptions(); + GlobalConfig->appendLogEntry ( i18n ( "Profiles saved." ),GlobalConfig->info ); + this->slotStatusMsg ( i18n ( "Profiles saved." ), ID_FLASH_MSG ); + } + saveGuiOptions(); + this->slotStatusMsg ( i18n ( "Global options saved." ), ID_FLASH_MSG ); + GlobalConfig->appendLogEntry ( i18n ( "Global options saved." ),GlobalConfig->info ); + this->slotStatusMsg ( i18n ( "Ready." ), ID_STATUS_MSG ); + GlobalConfig->appPointer->restoreOverrideCursor(); +} + +void KVpnc::deleteSessionClicked() +{ + if ( GlobalConfig->currentProfile == 0 ) + return ; + + QString Name = GlobalConfig->currentProfile->getName(); + + ToolInfo *IpsecToolInfo = Utils ( GlobalConfig ).getToolInfo ( "ipsec" ) ; + + QString TypeString = i18n ( "unknown" ); + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::cisco ) + TypeString = i18n ( "Cisco" ); + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ciscoorig ) + TypeString = i18n ( "Cisco (propritary)" ); + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::pptp ) + TypeString = i18n ( "PPTP" ); + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan ) + { + if ( IpsecToolInfo->Version.contains ( "Openswan", false ) ) + IpsecType = TypeString = i18n ( "Openswan" ); + else if ( IpsecToolInfo->Version.contains ( "strongSwan", false ) ) + IpsecType = TypeString = i18n ( "strongSwan" ); + else + IpsecType = TypeString = i18n ( "FreeS/WAN" ); + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon ) + TypeString = "racoon"; + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::openvpn ) + TypeString = "OpenVPN"; + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { + TypeString = "L2TP (racoon)"; + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { + if ( IpsecToolInfo->Version.contains ( "Openswan", false ) ) + IpsecType = TypeString = "L2TP (Openswan)"; + else if ( IpsecToolInfo->Version.contains ( "strongSwan", false ) ) + IpsecType = TypeString = "L2TP (strongSwan)"; + else + IpsecType = TypeString = "L2TP (FreeS/WAN)"; + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::vtun ) + TypeString = "Vtun"; + + + if ( !Name.isEmpty() ) + { + + int result = KMessageBox::questionYesNo ( this, i18n ( "Really delete profile \"%1\" (type: %2, Server: %3)?" ).arg ( GlobalConfig->currentProfile->getName() ).arg ( TypeString ).arg ( GlobalConfig->currentProfile->getGateway() ), i18n ( "Delete?" ), KStdGuiItem::del(), KStdGuiItem::cancel() ); + if ( result == 3 ) // yes + { + VpnAccountData * it; + QuickConnectMenu->clear(); + mw->SessionCombo->clear(); + GlobalConfig->removeEntry ( GlobalConfig->currentProfile->getName() ); + + if ( GlobalConfig->AccountList->isEmpty() ) + { + GlobalConfig->currentProfile = 0L; + mw->SessionCombo->setEnabled ( FALSE ); + ConnectAction->setEnabled ( FALSE ); + mw->buttonConnect->setEnabled ( FALSE ); + DeleteSessionAction->setEnabled ( FALSE ); + GlobalConfig->lastProfile = ""; + } + else + { + for ( it = GlobalConfig->AccountList->first(); it; it = GlobalConfig->AccountList->next() ) + { + kdDebug() << "item: " << it->getName() << endl; + QuickConnectMenu->insertItem ( it->getName() ); + mw->SessionCombo->insertItem ( it->getName() ); + } + GlobalConfig->currentProfile = GlobalConfig->AccountList->first(); + GlobalConfig->lastProfile = GlobalConfig->AccountList->first()->getName(); + mw->SessionCombo->setEnabled ( TRUE ); + mw->buttonConnect->setEnabled ( TRUE ); + this->sessionToggled ( GlobalConfig->currentProfile->getName() ); + } + + slotStatusMsg ( i18n ( "Profile \"%1\" deleted." ).arg ( Name ), ID_FLASH_MSG ); + GlobalConfig->appendLogEntry ( i18n ( "Profile \"%1\" deleted." ).arg ( Name ) , GlobalConfig->info ); + GlobalConfig->saveOptions(); + saveGuiOptions(); + + } + } + +} + +void KVpnc::renameSessionClicked () +{ + + VpnAccountData * it; + bool nameOk = false; + bool ok = true; + QString newName=""; + QString Oldname = GlobalConfig->currentProfile->getName(); + newName = KInputDialog::getText ( i18n ( "New Name" ), i18n ( "New name for profile:" ), QString ( GlobalConfig->currentProfile->getName() ), &ok ); + while ( nameOk == false ) + { + for ( it = GlobalConfig->AccountList->first(); it; it = GlobalConfig->AccountList->next() ) + { + if ( ( it != GlobalConfig->currentProfile ) && ( it->getName() == GlobalConfig->currentProfile->getName() ) ) + { + //account->setName( QString( account->getName() + "_2" ) ); + // KMessageBox::information ( this, i18n( "Profile name exists!\n It will be renamed to \"%1\"." ).arg( account->getName() ), i18n( "Name exist, renamed" ) ); + KMessageBox::error ( this, i18n ( "Profile name exists!" ), i18n ( "Name Exists" ) ); + + newName = KInputDialog::getText ( i18n ( "New Name" ), i18n ( "New name for profile:" ), QString ( GlobalConfig->currentProfile->getName() + "_2" ), &ok ); + if ( ok == false ) + { + KMessageBox::information ( 0, i18n ( "Rename was canceled." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Rename was canceled." ), GlobalConfig->info ); + slotStatusMsg ( i18n ( "Rename was canceled." ), ID_FLASH_MSG ); + return ; + } + } + nameOk = true; + } + nameOk = true; + } + if ( newName.isEmpty() ) + { + nameOk=false; + } + + if ( nameOk ) + { + for ( it = GlobalConfig->AccountList->first(); it; it = GlobalConfig->AccountList->next() ) + { + if ( it == GlobalConfig->currentProfile ) + { + it = GlobalConfig->AccountList->first(); + GlobalConfig->currentProfile->setName ( newName ); + nameOk = true; + + mw->SessionCombo->clear(); + QuickConnectMenu->clear(); + + for ( uint i = 0; i < GlobalConfig->AccountList->count();i++ ) + { + QuickConnectMenu->insertItem ( GlobalConfig->AccountList->at ( i ) ->getName() ); + mw->SessionCombo->insertItem ( GlobalConfig->AccountList->at ( i ) ->getName() ); + } + mw->SessionCombo->setCurrentText ( GlobalConfig->currentProfile->getName() ); + GlobalConfig->removeEntry ( Oldname ); + + if ( !mw->SessionCombo->isEnabled() ) + mw->SessionCombo->setEnabled ( TRUE ); + + this->ConnectAction->setEnabled ( true ); + sessionToggled ( GlobalConfig->currentProfile->getName() ); + + KMessageBox::information ( 0, i18n ( "Rename of \"%1\" to \"%2\" was successful." ).arg ( Oldname ).arg ( GlobalConfig->currentProfile->getName() ) ); + GlobalConfig->appendLogEntry ( i18n ( "Rename of \"%1\" to \"%2\" was successful." ).arg ( Oldname ).arg ( GlobalConfig->currentProfile->getName() ), GlobalConfig->info ); + slotStatusMsg ( i18n ( "Rename of \"%1\" to \"%2\" was successful." ).arg ( Oldname ).arg ( GlobalConfig->currentProfile->getName() ), ID_FLASH_MSG ); + + GlobalConfig->saveOptions(); + //std::cout << "save done" << std::endl; + return; + } + } + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "Rename was canceled." ), GlobalConfig->info ); + slotStatusMsg ( i18n ( "Rename was canceled." ), ID_FLASH_MSG ); + } +} + +void KVpnc::sessionToggled ( const QString& Name ) +{ + // mw->DebugOutput->append( "sessionToggled" ); + if ( Name.isEmpty() || GlobalConfig->AccountList->isEmpty() ) + { + this->DeleteSessionAction->setEnabled ( FALSE ); + // this->advancedSessionAction->setEnabled ( FALSE ); + this->SaveSessionAction->setEnabled ( FALSE ); + return; + } + else + { + this->DeleteSessionAction->setEnabled ( TRUE ); + // this->advancedSessionAction->setEnabled ( TRUE ); + this->SaveSessionAction->setEnabled ( TRUE ); + VpnAccountData * it; + GlobalConfig->currentProfile = GlobalConfig->AccountList->first(); + for ( it = GlobalConfig->AccountList->first(); it; it = GlobalConfig->AccountList->next() ) + { + QString Name = mw->SessionCombo->currentText(); + if ( !Name.isEmpty() ) + { + if ( it->getName() == Name ) + { + // profile found + GlobalConfig->currentProfile = it; + QString ProfileInfo = ""; + QString TypeString = ""; + QString Gateway = it->getGateway(); + QString Username = it->getUserName(); + //if ( GlobalConfig->KvpncDebugLevel > 2 ) + // GlobalConfig->appendLogEntry (i18n("Username: \"%1").arg(Username), KVpncConfig::debug); + if (it->getDontSaveUsername() || (Username == "")) + Username = i18n("<ask at connect>"); + QString IpsecId = ""; + QString RemotePort=0; + QString IkeOptions = ""; + QString EspOptions = ""; + QString TunnelDeviceType=it->getTunnelDeviceType(); + + + this->ExportOpenvpnProfileAction->setEnabled ( FALSE ); + + QString type = ""; // visible name + QString bin = ""; // executable name + + ProfileInfo += ""; + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "connectionType raw: %1" ).arg ( QString().setNum ( GlobalConfig->currentProfile->getConnectionType() ) ), KVpncConfig::debug ); + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::cisco ) + { + type = "vpnc"; + bin = "vpnc"; + TypeString = i18n ( "Cisco (free)" ); + ProfileInfo += ""; + ProfileInfo += ""; + IpsecId = it->getID(); + ProfileInfo += ""; + ProfileInfo += ""; + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ciscoorig ) + { + type = "ciscovpnc"; + bin = "vpnclient"; + TypeString = i18n ( "Cisco (proprietary)" ); + ProfileInfo += ""; + ProfileInfo += ""; + IpsecId = it->getID(); + ProfileInfo += ""; + ProfileInfo += ""; + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan ) + { + type = "ipsec"; + bin = "ipsec"; + TypeString = i18n ( "IPsec (Openswan/strongSwan)" ); + ProfileInfo += ""; + ProfileInfo += ""; + IpsecId = it->getSpecialLocalID(); + ProfileInfo += ""; + IkeOptions = it->getIpsecIke(); + ProfileInfo += ""; + EspOptions = it->getIpsecEsp(); + ProfileInfo += ""; + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon ) + { + type = "racoon"; + bin = "racoon"; + TypeString = i18n ( "IPsec (ipsec-tools)" ); + ProfileInfo += ""; + IpsecId = it->getSpecialLocalID(); + ProfileInfo += ""; + IkeOptions = it->getAuthenticationAlgorithm(); + ProfileInfo += ""; + EspOptions = it->getEncryptionAlgorithm(); + ProfileInfo += ""; + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::pptp ) + { + type = "pptp"; + bin = "pppd pptp"; + TypeString = i18n ( "PPTP" ); + ProfileInfo += ""; + ProfileInfo += ""; + QString PptpOptions = ""; + PptpOptions += ""; + ProfileInfo += ""; + ProfileInfo += ""; + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::openvpn ) + { + type = "openvpn"; + bin = "openvpn"; + TypeString = i18n ( "OpenVPN" ); + ProfileInfo += ""; + ProfileInfo += ""; + int RemotePort = 1194; + if (it->getUseRemotePort()) + RemotePort = it->getRemotePort(); + ProfileInfo += ""; + ProfileInfo += ""; + ProfileInfo += ""; + + this->ExportOpenvpnProfileAction->setEnabled ( TRUE ); + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { + type = "l2tpd (racoon)"; + if ( GlobalConfig->currentProfile->getL2tpDaemon() == VpnAccountData::l2tpd ) + { + bin = "racoon, l2tpd | xl2tpd"; + TypeString = i18n ( "L2TP (ipsec-tools + (x)l2tpd)" ); + } + if ( GlobalConfig->currentProfile->getL2tpDaemon() == VpnAccountData::openl2tp ) + { + bin = "racoon, openl2tpd"; + TypeString = i18n ( "L2TP (ipsec-tools + openl2tpd)" ); + } + ProfileInfo += ""; + IpsecId = it->getSpecialLocalID(); + ProfileInfo += ""; + IkeOptions = it->getAuthenticationAlgorithm(); + ProfileInfo += ""; + EspOptions = it->getEncryptionAlgorithm(); + ProfileInfo += ""; + ProfileInfo += ""; + ProfileInfo += ""; + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { + type = "l2tpd (ipsec)"; + if ( GlobalConfig->currentProfile->getL2tpDaemon() == VpnAccountData::l2tpd ) + { + bin = "ipsec, l2tpd | xl2tpd"; + TypeString = i18n ( "L2TP (Openswan/strongSwan + (x)l2tpd)" ); + } + if ( GlobalConfig->currentProfile->getL2tpDaemon() == VpnAccountData::openl2tp ) + { + bin = "ipsec, openl2tpd"; + TypeString = i18n ( "L2TP (Openswan/strongSwan + openl2tpd)" ); + } + ProfileInfo += ""; + ProfileInfo += ""; + IkeOptions = it->getIpsecIke(); + ProfileInfo += ""; + EspOptions = it->getIpsecEsp(); + ProfileInfo += ""; + ProfileInfo += ""; + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::vtun ) + { + type = "vtun"; + bin = "vtund"; + TypeString = i18n ( "Vtun" ); + ProfileInfo += ""; + ProfileInfo += ""; + ProfileInfo += ""; + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ssh ) + { + type = "ssh"; + bin = "ssh, ksshaskpass | gnome-ssh-askpass"; + TypeString = i18n ( "SSH" ); + ProfileInfo += ""; + ProfileInfo += ""; + ProfileInfo += ""; + ProfileInfo += ""; + } + else + { + type = "other"; + bin = ""; + } + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Selected connection type: %1." ).arg ( type ), GlobalConfig->debug ); + + int Authtype = it->getAuthType(); + QString AuthTypeText=""; + QString AuthTypePretty = ""; + if ( Authtype == VpnAccountData::cert ) + { + AuthTypeText="cert"; + AuthTypePretty = i18n("Certificate"); + } + else if ( Authtype == VpnAccountData::psk ) + { + AuthTypeText="psk"; + AuthTypePretty = i18n("Pre shared key"); + } + else if ( Authtype == VpnAccountData::hybrid ) + { + AuthTypeText="hybrid"; + AuthTypePretty = i18n("Hybrid"); + } + else + { + AuthTypeText="unknown auth"; + AuthTypePretty = i18n("Unknown"); + } + + if ( it->getConnectionType() == VpnAccountData::pptp ) + { + AuthTypePretty = i18n("PPTP"); + if ( GlobalConfig->currentProfile->getAuthMethod() == "chap") + AuthTypePretty += " ("+i18n("CHAP")+")"; + if ( GlobalConfig->currentProfile->getAuthMethod() == "mschap") + AuthTypePretty += " ("+i18n("MSCHAP")+")"; + if ( GlobalConfig->currentProfile->getAuthMethod() == "mschap-v2") + AuthTypePretty += " ("+i18n("MSCHAP v2")+")"; + if ( GlobalConfig->currentProfile->getAuthMethod() == "pap" ) + AuthTypePretty += " ("+i18n("PAP")+")"; + } + if ( it->getConnectionType() == VpnAccountData::l2tpd_racoon || it->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { + if ( GlobalConfig->currentProfile->getAuthMethod() == "chap") + AuthTypePretty += " ("+i18n("L2TP:")+" "+i18n("CHAP")+")"; + if ( GlobalConfig->currentProfile->getAuthMethod() == "mschap") + AuthTypePretty += " ("+i18n("L2TP:")+" "+i18n("MSCHAP")+")"; + if ( GlobalConfig->currentProfile->getAuthMethod() == "mschap-v2") + AuthTypePretty += " ("+i18n("L2TP:")+" "+i18n("MSCHAP v2")+")"; + if ( GlobalConfig->currentProfile->getAuthMethod() == "pap" ) + AuthTypePretty += " ("+i18n("L2TP:")+" "+i18n("PAP")+")"; + } + if ( it->getConnectionType() == VpnAccountData::ssh ) + { + AuthTypePretty = i18n("SSH"); + if (it->getAuthWithUsernameAndPassword()) + AuthTypePretty += i18n(" (using password)"); + else + if (it->getPskIsInFile()) + AuthTypePretty += i18n(" (using key: %1)").arg(it->getPreSharedKeyFile()); + else + AuthTypePretty += i18n(" (using key: %1)").arg(it->getPreSharedKey()); + } + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Selected auth type: %1." ).arg ( AuthTypePretty ), GlobalConfig->debug ); + ProfileInfo += ""; + + +// ToolInfo *it; + // std::cout << "Tool (bin): " << bin << std::endl; + QString TypeRequirementStatus=""; + if ( !GlobalConfig->ToolList->isEmpty() ) + { + + bool UseSmartcardOk=true; + if ( GlobalConfig->currentProfile->getUseSmartcard() ) + { + ToolInfo *Pkcs11ToolInfo = Utils ( GlobalConfig ).getToolInfo ( "pkcs11-tool" ); + if ( Pkcs11ToolInfo->found ) + UseSmartcardOk=true; + else + UseSmartcardOk=false; + } + + if ( type != "pptp" && type != "l2tpd (racoon)" && type != "l2tpd (ipsec)" && type != "ssh" ) + { + if ( Utils ( GlobalConfig ).getToolInfo ( bin ) != 0 && Utils ( GlobalConfig ).getToolInfo ( bin )->found ) + { + if ( !GlobalConfig->currentProfile->getUseSmartcard() ) + { + // program is installed + this->ConnectAction->setEnabled ( TRUE ); + mw->buttonConnect->setEnabled ( TRUE ); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "The required daemon (%1) is available, connect will be enabled." ).arg ( bin ), KVpncConfig::info ); + TypeRequirementStatus = i18n ( "Daemon (%1) available").arg(bin); + } + else + { + if ( UseSmartcardOk == false ) + { + this->ConnectAction->setEnabled ( FALSE ); + mw->buttonConnect->setEnabled ( FALSE ); + GlobalConfig->appendLogEntry ( i18n ( "The required helper program (%1) isn't available, connect will be disabled." ).arg ( "pkcs11-tool" ), KVpncConfig::error ); + TypeRequirementStatus = i18n ( "Daemon (%1) not available").arg ( "pkcs11-tool" ); + } + else + { + this->ConnectAction->setEnabled ( TRUE ); + mw->buttonConnect->setEnabled ( TRUE ); + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "The required daemon (%1) and helper program (%2) is available, connect will be enabled." ).arg ( bin ).arg ( "pkcs11-tool" ), KVpncConfig::info ); + TypeRequirementStatus = i18n ( "Daemon (%1) and helper program (%2) not available").arg ( "pkcs11-tool" ).arg("pkcs11-tool"); + } + } + } + else + { + this->ConnectAction->setEnabled ( FALSE ); + mw->buttonConnect->setEnabled ( FALSE ); + GlobalConfig->appendLogEntry ( i18n ( "The required daemon (%1) isn't available, connect will be disabled." ).arg ( bin ), KVpncConfig::error ); + TypeRequirementStatus = i18n ( "Daemon (%1) not available").arg(bin); + } + } + else + { + if ( type == "l2tpd (racoon)" ) + { + bool racoon_and_l2tpd_available = false; + bool racoon_and_xl2tpd_available = false; + bool racoon_and_openl2tp_available=false; + if ( Utils ( GlobalConfig ).getToolInfo ( "racoon" )->found ) + { + if ( Utils ( GlobalConfig ).getToolInfo ( "l2tpd" )->found ) + racoon_and_l2tpd_available = true; + if ( Utils ( GlobalConfig ).getToolInfo ( "xl2tpd" )->found ) + racoon_and_xl2tpd_available = true; + if ( Utils ( GlobalConfig ).getToolInfo ( "openl2tpd" )->found ) + racoon_and_openl2tp_available = true; + } + if ( GlobalConfig->currentProfile->getL2tpDaemon() == VpnAccountData::l2tpd ) + { + if ( racoon_and_l2tpd_available ) + { + // programs are installed + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "The required daemons (%1 and %2) are available, connect will be enabled." ).arg ( "racoon" ).arg ( "l2tpd" ), KVpncConfig::info ); + TypeRequirementStatus = i18n ( "Daemons (%1 and %2) available").arg ( "racoon" ).arg ( "l2tpd" ); + + this->ConnectAction->setEnabled ( TRUE ); + mw->buttonConnect->setEnabled ( TRUE ); + } + else if ( racoon_and_xl2tpd_available ) + { + // programs are installed + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "The required daemons (%1 and %2) are available, connect will be enabled." ).arg ( "racoon" ).arg ( "xl2tpd" ), KVpncConfig::info ); + + TypeRequirementStatus = i18n ( "Daemons (%1 and %2) available").arg ( "racoon" ).arg ( "xl2tpd" ); + + this->ConnectAction->setEnabled ( TRUE ); + mw->buttonConnect->setEnabled ( TRUE ); + } + else if ( racoon_and_l2tpd_available==false && racoon_and_xl2tpd_available==false ) + { + GlobalConfig->appendLogEntry ( i18n ( "The required daemons (%1 and %2) are not available, connect will be disabled." ).arg ( "racoon" ).arg ( "l2tpd/xl2tpd" ), KVpncConfig::error ); + TypeRequirementStatus = i18n ( "Daemons (%1 and %2) not available").arg ( "racoon" ).arg ( "xl2tpd" ); + } + } + if ( GlobalConfig->currentProfile->getL2tpDaemon() == VpnAccountData::openl2tp ) + { + if ( racoon_and_openl2tp_available ) + { + // programs are installed + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "The required daemons (%1 and %2) are available, connect will be enabled." ).arg ( "racoon" ).arg ( "openl2tp" ), KVpncConfig::info ); + + TypeRequirementStatus = i18n ( "Daemons (%1 and %2) available").arg ( "racoon" ).arg ( "openl2tp" ); + + this->ConnectAction->setEnabled ( TRUE ); + mw->buttonConnect->setEnabled ( TRUE ); + } + } + } + if ( type == "l2tpd (ipsec)" ) + { + bool ipsec_and_l2tpd_available = false; + bool ipsec_and_xl2tpd_available = false; + bool ipsec_and_openl2tp_available=false; + if ( Utils ( GlobalConfig ).getToolInfo ( "ipsec" )->found ) + { + if ( Utils ( GlobalConfig ).getToolInfo ( "l2tpd" )->found ) + ipsec_and_l2tpd_available = true; + if ( Utils ( GlobalConfig ).getToolInfo ( "xl2tpd" )->found ) + ipsec_and_xl2tpd_available = true; + if ( Utils ( GlobalConfig ).getToolInfo ( "openl2tpd" )->found ) + ipsec_and_openl2tp_available = true; + } + + QString deamon=""; + if ( ipsec_and_l2tpd_available ) + deamon="l2tpd"; + if ( ipsec_and_xl2tpd_available ) + deamon="xl2tpd"; + if ( ipsec_and_openl2tp_available ) + deamon="openl2tp"; + if ( ipsec_and_l2tpd_available || ipsec_and_xl2tpd_available || ipsec_and_openl2tp_available ) + { + if ( !GlobalConfig->currentProfile->getUseSmartcard() ) + { + + if ( GlobalConfig->currentProfile->getL2tpDaemon() == VpnAccountData::l2tpd ) + { + if ( ipsec_and_l2tpd_available ) + { + // programs are installed + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "The required daemons (%1 and %2) are available, connect will be enabled." ).arg ( "ipsec" ).arg ( "l2tpd" ), KVpncConfig::info ); + + TypeRequirementStatus = i18n ( "Daemons (%1 and %2) available").arg ( "ipsec" ).arg ( "l2tpd" ); + + this->ConnectAction->setEnabled ( TRUE ); + mw->buttonConnect->setEnabled ( TRUE ); + } + else if ( ipsec_and_xl2tpd_available ) + { + // programs are installed + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "The required daemons (%1 and %2) are available, connect will be enabled." ).arg ( "ipsec" ).arg ( "xl2tpd" ), KVpncConfig::info ); + + TypeRequirementStatus = i18n ( "Daemons (%1 and %2) available").arg ( "ipsec" ).arg ( "xl2tpd" ); + + this->ConnectAction->setEnabled ( TRUE ); + mw->buttonConnect->setEnabled ( TRUE ); + } + else if ( ipsec_and_l2tpd_available==false && ipsec_and_xl2tpd_available==false ) + { + GlobalConfig->appendLogEntry ( i18n ( "The required daemons (%1 and %2) are not available, connect will be disabled." ).arg ( "ipsec" ).arg ( "l2tpd/xl2tpd" ), KVpncConfig::error ); + TypeRequirementStatus = i18n ( "Daemons (%1 and %2) not available").arg ( "ipsec" ).arg ( "l2tpd/xl2tpd" ); + } + } + if ( GlobalConfig->currentProfile->getL2tpDaemon() == VpnAccountData::openl2tp ) + { + if ( ipsec_and_openl2tp_available ) + { + // programs are installed + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "The required daemons (%1 and %2) are available, connect will be enabled." ).arg ( "ipsec" ).arg ( "openl2tp" ), KVpncConfig::info ); + + TypeRequirementStatus = i18n ( "Daemons (%1 and %2) available").arg ( "ipsec" ).arg ( "openl2tp" ); + + this->ConnectAction->setEnabled ( TRUE ); + mw->buttonConnect->setEnabled ( TRUE ); + } + else if ( ipsec_and_openl2tp_available==false ) + { + GlobalConfig->appendLogEntry ( i18n ( "The required daemons (%1 and %2) are not available, connect will be disabled." ).arg ( "ipsec" ).arg ( "openl2tp" ), KVpncConfig::error ); + TypeRequirementStatus = i18n ( "Daemons (%1 and %2) available").arg ( "ipsec" ).arg ( "openl2tp" ); + } + } + } + else + { + if ( GlobalConfig->currentProfile->getUseSmartcard() ) + { + if ( UseSmartcardOk == false ) + { + this->ConnectAction->setEnabled ( FALSE ); + mw->buttonConnect->setEnabled ( FALSE ); + GlobalConfig->appendLogEntry ( i18n ( "The required helper program (%1) isn't available, connect will be disabled." ).arg ( "pkcs11-tool" ), KVpncConfig::error ); + TypeRequirementStatus = i18n ( "Daemon (%1) not available").arg ( "pkcs11-tool" ); + } + else + { + this->ConnectAction->setEnabled ( TRUE ); + mw->buttonConnect->setEnabled ( TRUE ); + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "The required daemons (%1 and %2) and helper program (%3) is available, connect will be enabled." ).arg ( "ipsec" ).arg ( QString(deamon) ).arg ( "pkcs11-tool" ), KVpncConfig::info ); + TypeRequirementStatus = i18n ( "Daemons (%1 and %2) available").arg ( "ipsec" ).arg(deamon).arg ( "pkcs11-tool" ); + } + } + } + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "The required daemons (%1 and %2) are not available, connect will be disabled." ).arg ( "ipsec" ).arg ( "l2tpd/xl2tpd" ), KVpncConfig::error ); + TypeRequirementStatus = i18n ( "Daemons (%1 and %2) not available").arg ( "ipsec" ).arg ( "l2tpd/xl2pd" ); + } + } + if ( type == "pptp" ) + { + bool pppd_and_pptp_available = false; + if ( Utils ( GlobalConfig ).getToolInfo ( "pppd" )->found ) + { + if ( Utils ( GlobalConfig ).getToolInfo ( "pptp" )->found ) + pppd_and_pptp_available = true; + } + if ( pppd_and_pptp_available ) + { + // programs are installed + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "The required daemons (%1 and %2) are available, connect will be enabled." ).arg ( "pppd" ).arg ( "pptp" ), KVpncConfig::info ); + TypeRequirementStatus = i18n ( "Daemons (%1 and %2) available").arg ( "pppd" ).arg ( "pptp" ); + + this->ConnectAction->setEnabled ( TRUE ); + mw->buttonConnect->setEnabled ( TRUE ); + + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "The required daemons (%1 and %2) are not available, connect will be disabled." ).arg ( "pppd" ).arg ( "pptp" ), KVpncConfig::error ); + TypeRequirementStatus = i18n ( "Daemons (%1 and %2) not available").arg ( "pppd" ).arg ( "pptp" ); + } + } + if ( type == "ssh" ) + { + bool ssh_and_kaskpass_available = false; + bool ssh_and_gnomeaskpass_available = false; + if ( Utils ( GlobalConfig ).getToolInfo ( "ssh" )->found ) + { + if ( Utils ( GlobalConfig ).getToolInfo ( "ksshaskpass" )->found ) + ssh_and_kaskpass_available = true; + if ( Utils ( GlobalConfig ).getToolInfo ( "gnome-ssh-askpass" )->found ) + ssh_and_gnomeaskpass_available = true; + } + if ( ssh_and_kaskpass_available ) + { + // programs are installed + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "The required programs (%1 and %2) are available, connect will be enabled." ).arg ( "ssh" ).arg ( "ksshaskpass" ), KVpncConfig::info ); + + TypeRequirementStatus = i18n ( "Daemons (%1 and %2) available").arg ( "ssh" ).arg ( "ksshaskpass" ); + + this->ConnectAction->setEnabled ( TRUE ); + mw->buttonConnect->setEnabled ( TRUE ); + + } + else if ( ssh_and_gnomeaskpass_available ) + { + // programs are installed + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "The required programs (%1 and %2) are available, connect will be enabled." ).arg ( "ssh" ).arg ( "gnome-ssh-askpass" ), KVpncConfig::info ); + + TypeRequirementStatus = i18n ( "Daemons (%1 and %2) available").arg ( "ssh" ).arg ( "gnome-ssh-askpass" ); + + this->ConnectAction->setEnabled ( TRUE ); + mw->buttonConnect->setEnabled ( TRUE ); + + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "The required programs (%1 and %2) are not available, connect will be disabled." ).arg ( "ssh" ).arg ( i18n ( "%1 or %2" ).arg ( "ksshaskpass" ).arg ( "gnome-ssh-askpass" ) ), KVpncConfig::error ); + TypeRequirementStatus = i18n ( "Daemons (%1 and %2) not available").arg ( "ssh" ).arg ( i18n ( "%1 or %2" ).arg ( "ksshaskpass" ).arg ( "gnome-ssh-askpass" ) ); + } + } + + } + } + ProfileInfo += ""; + ProfileInfo += "
"+i18n("Type:")+""+TypeString+"
"+i18n("Gateway (VPN server):")+""+Gateway+"
"+i18n("IPsec ID:")+""+IpsecId+"
"+i18n("Username:")+""+Username+"
"+i18n("Type:")+""+TypeString+"
"+i18n("Gateway (VPN server):")+""+Gateway+"
"+i18n("IPsec ID:")+""+IpsecId+"
"+i18n("Username:")+""+Username+"
"+i18n("Type:")+""+TypeString+"
"+i18n("Gateway (VPN server):")+""+Gateway+"
"+i18n("IPsec ID:")+""+IpsecId+"
"+i18n("IKE options:")+""+IkeOptions+"
"+i18n("ESP options:")+""+EspOptions+"
"+i18n("Type:")+""+TypeString+"
"+i18n("IPsec ID:")+""+IpsecId+"
"+i18n("Authentication algorithm:")+""+IkeOptions+"
"+i18n("Encryption algorithm:")+""+EspOptions+"
"+i18n("Type:")+""+TypeString+"
"+i18n("Gateway (VPN server):")+""+Gateway+"
"; + if (it->getRequireMppe()) + PptpOptions += ""; + else + PptpOptions += ""; + if (it->getRefuse128BitEncryption()) + PptpOptions += ""; + else + PptpOptions += ""; + if (it->getRefuse40BitEncryption()) + PptpOptions += ""; + else + PptpOptions += ""; + if (it->getDisableMPPEComp()) + PptpOptions += ""; + else + PptpOptions += ""; + if (it->getUseNoBsdComp()) + PptpOptions += ""; + else + PptpOptions += ""; + if (it->getUseNoDeflate()) + PptpOptions += ""; + else + PptpOptions += ""; + if (it->getDisableHeaderCompression()) + PptpOptions += ""; + else + PptpOptions += ""; + if (it->getDisableAdressControlCompression()) + PptpOptions += ""; + else + PptpOptions += ""; + if (it->getDisableProtocolFieldCompression()) + PptpOptions += ""; + else + PptpOptions += ""; + if (it->getDisableMagicNumberNegotiation()) + PptpOptions += ""; + else + PptpOptions += ""; + if (it->getDisableCcp()) + PptpOptions += ""; + else + PptpOptions += ""; + if (it->getDisableIpx()) + PptpOptions += ""; + else + PptpOptions += ""; + if (it->getAllowStatefulMode()) + PptpOptions += ""; + else + PptpOptions += ""; + QString NtDomainName = "-"; + if ( it->getUseNtDomainName() ) + NtDomainName = it->getNtDomainName(); + PptpOptions += ""; + /* + ProfilePptpOptionsWidget->DnsServerCheckbox->setChecked( it->getUseDnsServer() ); + ProfilePptpOptionsWidget->DnsServerLineedit->setText( it->getDnsServer() ); + ProfilePptpOptionsWidget->UseNoIpDefaultCheckbox->setChecked( it->getUseNoIpDefault() ); + ProfilePptpOptionsWidget->RequireEapCheckbox->setChecked(it->getRequireEap()); + + */ + PptpOptions += "
"+i18n("Require MPPE:")+""+ i18n("yes")+"
"+i18n("Require MPPE:")+""+ i18n("no")+"
"+i18n("Refuse 128 bit encryption:")+""+ i18n("yes")+"
"+i18n("Refuse 128 bit encryption:")+""+ i18n("no")+"
"+i18n("Refuse 40 bit encryption:")+""+ i18n("yes")+"
"+i18n("Refuse 40 bit encryption:")+""+ i18n("no")+"
"+i18n("Disable MPPE compression:")+""+ i18n("yes")+"
"+i18n("Disable MPPE compression:")+""+ i18n("no")+"
"+i18n("Disable BSD compression:")+""+ i18n("yes")+"
"+i18n("Disable BSD compression:")+""+ i18n("no")+"
"+i18n("Disable deflate compression:")+""+ i18n("yes")+"
"+i18n("Disable deflate compression:")+""+ i18n("no")+"
"+i18n("Disable header compression:")+""+ i18n("yes")+"
"+i18n("Disable header compression:")+""+ i18n("no")+"
"+i18n("Disable address control compression:")+""+ i18n("yes")+"
"+i18n("Disable address control compression:")+""+ i18n("no")+"
"+i18n("Disable protocol field compression:")+""+ i18n("yes")+"
"+i18n("Disable protocol field compression:")+""+ i18n("no")+"
"+i18n("Disable magic number negotiation:")+""+ i18n("yes")+"
"+i18n("Disable magic number negotiation")+""+ i18n("no")+"
"+i18n("Disable Compression Control Protocol negotiation:")+""+ i18n("yes")+"
"+i18n("Disable Compression Control Protocol negotiation:")+""+ i18n("no")+"
"+i18n("Disable IPX protocol:")+""+ i18n("yes")+"
"+i18n("Disable IPX protocol:")+""+ i18n("no")+"
"+i18n("Allow stateful mode:")+""+ i18n("yes")+"
"+i18n("Allow stateful mode:")+""+ i18n("no")+"
"+i18n("NT domain name:")+""+ NtDomainName+"
"+i18n("Username:")+""+Username+"
"+i18n("PPTP options:")+""+PptpOptions+"
"+i18n("Type:")+""+TypeString+"
"+i18n("Gateway (VPN server):")+""+Gateway+"
"+i18n("Remote port:")+""+QString().setNum(RemotePort)+"
"+i18n("Username:")+""+Username+"
"+i18n("Tunnel device type:")+""+TunnelDeviceType+"
"+i18n("Type:")+""+TypeString+"
"+i18n("IPsec ID:")+""+IpsecId+"
"+i18n("Authentication algorithm:")+""+IkeOptions+"
"+i18n("Encryption algorithm:")+""+EspOptions+"
"+i18n("Gateway (VPN server):")+""+Gateway+"
"+i18n("Username:")+""+Username+"
"+i18n("Type:")+""+TypeString+"
"+i18n("Gateway (VPN server):")+""+Gateway+"
"+i18n("IKE options:")+""+IkeOptions+"
"+i18n("ESP options:")+""+EspOptions+"
"+i18n("Username:")+""+Username+"
"+i18n("Gateway (VPN server):")+""+Gateway+"
"+i18n("Username:")+""+Username+"
"+i18n("Tunnel device type:")+""+TunnelDeviceType+"
"+i18n("Type:")+""+TypeString+"
"+i18n("Gateway (VPN server):")+""+Gateway+"
"+i18n("Username:")+""+Username+"
"+i18n("Tunnel device type:")+""+TunnelDeviceType+"
"+i18n("Authentication:")+""+AuthTypePretty+"
"+i18n("Required tools:")+""+TypeRequirementStatus+"
"; + QToolTip::add( mw->SessionCombo, ProfileInfo ); + break; + } + } + } + } +} + +void KVpnc::slotDurationEvent() +{ + + sec += 1; + if ( sec > 59 ) + { + sec = 0; + min += 1; + + } + if ( min > 59 ) + { + sec = 0; + min = 0; + hour += 1; + } + + + if ( !isHidden() ) + { + QString StatusMsg = ""; + QString durationString(i18n("%1:%2:%3" ).arg( QString().sprintf("%02u", hour)).arg( QString().sprintf("%02u", min)).arg( QString().sprintf("%02u", sec))); + QString Username = ""; + + if (!GlobalConfig->TmpUsername.isEmpty()) + Username = GlobalConfig->TmpUsername; + else + Username = GlobalConfig->currentProfile->getUserName(); + + if (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::cisco) + { + StatusMsg = i18n("Connected: %2@%1, [%3], %4").arg(Username).arg(GlobalConfig->currentProfile->getGateway()).arg(PrettyTypeString).arg(durationString); + } + else if (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ciscoorig) + { + StatusMsg = i18n("Connected: %2@%1, [%3], %4").arg(Username).arg(GlobalConfig->currentProfile->getGateway()).arg(PrettyTypeString).arg(durationString); + } + else if (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::pptp) + { + StatusMsg = i18n("Connected: %2@%1 [%3], %4").arg( GlobalConfig->currentProfile->getGateway()).arg( Username).arg( PrettyTypeString).arg(durationString); + } + else if (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan || + (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::openvpn && GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() == true) || + GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon || + GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon || + GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan + ) + { + if (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan && !(GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan && GlobalConfig->currentProfile->getAuthWithUsernameAndPassword())) + { + StatusMsg = i18n("Connected: %1 [%2], %3").arg( GlobalConfig->currentProfile->getGateway()).arg(PrettyTypeString).arg(durationString); + } + else if (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon) + { + StatusMsg = i18n("Connected: %1 [%2], %3").arg(GlobalConfig->currentProfile->getGateway()).arg(PrettyTypeString).arg(durationString); + } + else if (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon) + { + StatusMsg = i18n("Connected: %2@%1 [%3], %4").arg(GlobalConfig->currentProfile->getGateway()).arg(Username).arg(PrettyTypeString).arg(durationString); + } + else if (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan || (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan && GlobalConfig->currentProfile->getAuthWithUsernameAndPassword())) + { + StatusMsg = i18n("Connected: %2@%1 [%3], %4").arg(GlobalConfig->currentProfile->getGateway()).arg(Username).arg(PrettyTypeString).arg(durationString); + } + else if (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::openvpn) + { + StatusMsg = i18n("Connected: %2@%1 [%3], %4").arg(GlobalConfig->currentProfile->getGateway()).arg(Username).arg(PrettyTypeString).arg(durationString); + } + + } + else if (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::openvpn) + { + StatusMsg = i18n("Connected: %1, [%2], %3").arg(GlobalConfig->currentProfile->getGateway()).arg(PrettyTypeString).arg(durationString); + } + else if (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::vtun) + { + StatusMsg = i18n("Connected: %1, [%2], %3").arg(QString(GlobalConfig->currentProfile->getGateway())).arg(QString(PrettyTypeString)).arg(durationString); + } + else if (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ssh) + { + StatusMsg = i18n("Connected: %1@%2 [%3], %4").arg(QString(Username)).arg(GlobalConfig->currentProfile->getGateway()).arg(PrettyTypeString).arg(durationString); + } + + + slotStatusMsg(StatusMsg, ID_CONNECTION_MSG); + } + +// if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::cisco ) +// { +// int connecttime_seconds = sec + min * 60 + hour * 60 * 60; +// int PeerTimeout = GlobalConfig->currentProfile->getPeerTimeout(); +// if ( PeerTimeout > 0 && connecttime_seconds > PeerTimeout ) +// { +// GlobalConfig->appendLogEntry ( i18n ( "Peer timeout value (%1 s) reached. Reconnecing..." ).arg ( PeerTimeout ), GlobalConfig->info ); +// disconnectClicked(); +// sleep ( 2 ); +// connectClicked(); +// } +// } +} + +void KVpnc::showDockTooltip() +{ + QString IP; + if (GlobalConfig->showInterfaceIPinTooltip) + { + if (TunnelInterfaceIP.isEmpty()) + { + if (GlobalConfig->currentProfile && GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::openvpn) + { + NetworkInterface iface(GlobalConfig, parent); + TunnelInterfaceIP = iface.getInterfaceIP(OpenvpnDevice); + } + if (GlobalConfig->currentProfile && GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ssh) + { + NetworkInterface iface(GlobalConfig, parent); + + // FIXME make it dynamiclly + if (GlobalConfig->currentProfile->getTunnelDeviceType() == "tun") + TunnelInterfaceIP = iface.getInterfaceIP("tun0"); + else + TunnelInterfaceIP = iface.getInterfaceIP("tap0"); + } + // else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) { + // NetworkInterface iface( GlobalConfig, parent ); + // + // //FIXME + // TunnelInterfaceIP = iface.getInterfaceIP( "ppp0" ); + // } + } + + IP = TunnelInterfaceIP; + if (IP.isEmpty()) + IP = i18n("none"); + } + QString durationString =""; + QString ToolTipMsg = ""; + + QString Username = ""; + QString ConnectionStatus=""; + + if (GlobalConfig->status == GlobalConfig->connected || GlobalConfig->status == GlobalConfig->connecting) + { + if (GlobalConfig->status == GlobalConfig->connected) + { + ConnectionStatus = i18n("connected"); + durationString = i18n("%1:%2:%3").arg( QString().sprintf("%02u", hour)).arg(QString().sprintf("%02u", min)).arg(QString().sprintf("%02u", sec)); + } + else + { + ConnectionStatus = i18n("connecting"); + } + + if (!GlobalConfig->TmpUsername.isEmpty()) + Username = GlobalConfig->TmpUsername; + else + Username = GlobalConfig->currentProfile->getUserName(); + + ToolTipMsg += ""; + ToolTipMsg += ""; + ToolTipMsg += ""; + + if (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::cisco || GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ciscoorig) + ToolTipMsg += ""; + + + if (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::cisco || GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ciscoorig || GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::pptp || + GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon || GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan || + (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::openvpn && GlobalConfig->currentProfile->getAuthWithUsernameAndPassword())) + { + ToolTipMsg += ""; + } + if ((GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::cisco || GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ciscoorig || GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::pptp || + GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon || + GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan || + GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::openvpn || + GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ssh) && GlobalConfig->showInterfaceIPinTooltip == true) + ToolTipMsg += ""; + + if ( GlobalConfig->currentProfile->getUseLeftSourceIp() && (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon || GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan) && GlobalConfig->showInterfaceIPinTooltip == true) + { + ToolTipMsg += ""; + } + + + if (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::openvpn && GlobalConfig->currentProfile->getUseHttpProxy()) + { + ToolTipMsg += ""; + if (GlobalConfig->currentProfile->getUseHttpProxyAuth()) + { + ToolTipMsg += ""; + ToolTipMsg += ""; + } + } + + if (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::cisco || GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::openvpn || + GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ssh) + { + ToolTipMsg += ""; + } + + if (GlobalConfig->showConnectionTimeInTooltip) + ToolTipMsg += ""; + } + else if (GlobalConfig->status == GlobalConfig->disconnected) + { + ConnectionStatus = i18n("disconnected"); + ToolTipMsg += ""; + } + ToolTipMsg += "
"+i18n("Status:")+""+ConnectionStatus+"
"+i18n("Server:")+""+QString(GlobalConfig->currentProfile->getGateway())+"
"+i18n("Type:")+""+QString(PrettyTypeString)+"
"+i18n("IPSec ID:")+""+GlobalConfig->currentProfile->getID()+"
"+i18n("user:")+""+QString(Username)+"
"+i18n("tunnel IP:")+""+QString(IP)+"
"+i18n ("Virtual IP:")+""+GlobalConfig->currentProfile->getLeftSourceIp()+"
"+i18n("HTTP proxy:")+""+GlobalConfig->currentProfile->getHttpProxy()+":"+QString().setNum(GlobalConfig->currentProfile->getHttpProxyPort())+"
"+i18n("HTTP proxy type:")+""+GlobalConfig->currentProfile->getHttpProxyAuthType().upper()+"
"+i18n("HTTP proxy user:")+""+GlobalConfig->currentProfile->getHttpProxyUser()+"
"+i18n("Tunnel device type:")+""+QString(GlobalConfig->currentProfile->getTunnelDeviceType())+"
"+i18n("Duration:")+""+durationString+"
"+i18n("State:")+""+ ConnectionStatus+"
"; + QToolTip::remove ( KVpncDock); + QToolTip::add ( KVpncDock, ToolTipMsg ); +} + +void KVpnc::setGuiStatus ( int status ) +{ + QString durationString = ""; + QString DaemonString = ""; + QString ToolTipMsg = ""; + QString ConnectMsg = ""; + QString LogMsg = ""; + QString ConnectionStatus = i18n("unknown"); + QString Username = ""; + if (status == GlobalConfig->connected) + { + setIcon ( connectedIcon ); + + durationString = i18n ( "%1:%2:%3" ).arg ( QString().sprintf ( "%02u", hour ) ).arg ( QString().sprintf ( "%02u", min ) ).arg ( QString().sprintf ( "%02u", sec ) ) ; + QString ConnectMsg = ""; + QString LogMsg = ""; + QString ToolTipMsg = ""; + QString DeamonString = ""; + ConnectionStatus = i18n("connected"); + + if ( !GlobalConfig->TmpUsername.isEmpty() ) + Username=GlobalConfig->TmpUsername; + else + Username = GlobalConfig->currentProfile->getUserName(); + + mw->SessionCombo->setEnabled ( false ); + ImportCertAction->setEnabled ( false ); + DeleteSessionAction->setEnabled ( false ); + RenameSessionAction->setEnabled ( false ); + ImportSessionAction->setEnabled ( false ); + NewProfileWizardAction->setEnabled ( false ); + + KVpncDock->setStatus ( connected ); + GlobalConfig->status = GlobalConfig->connected; + statusColorLabel->setPixmap ( *connectedStatusPixmap ); + mw->buttonConnect->setEnabled ( false ); + mw->buttonDisconnect->setEnabled ( true ); + mw->SessionCombo->setEnabled ( false ); + ConnectAction->setEnabled ( false ); + DisconnectAction->setEnabled ( true ); + PreferencesAction->setEnabled ( false ); + ProfileManagerAction->setEnabled ( false ); + NewProfileWizardAction->setEnabled ( false ); + PrefAction ->setEnabled ( false ); + + ToolTipMsg = ConnectMsg; + QToolTip::add + ( KVpncDock, ToolTipMsg ); + + slotStatusMsg ( i18n ( "Successful connected." ), ID_FLASH_MSG ); + slotStatusMsg ( ConnectMsg , ID_CONNECTION_MSG ); + GlobalConfig->appendLogEntry ( ConnectMsg , GlobalConfig->success ); + + //sleep(2); + if ( GlobalConfig->minimizeAfterConnect ) + hide(); + + + QuickConnectMenu = new QPopupMenu ( KVpncDock->menu() ); + + + //setItemEnabled ( int id, bool enable ) + + } + else if ( status == GlobalConfig->connecting ) + { + //setIcon( connectingIcon ); + mw->buttonConnect->setEnabled ( false ); + mw->buttonDisconnect->setEnabled ( false ); + mw->SessionCombo->setEnabled ( false ); + ImportCertAction->setEnabled ( false ); + RenameSessionAction->setEnabled ( false ); + DeleteSessionAction->setEnabled ( false ); + ImportSessionAction->setEnabled ( false ); + + KVpncDock->setStatus ( connecting ); + GlobalConfig->status = GlobalConfig->connecting; + mw->SessionCombo->setEnabled ( false ); + PreferencesAction->setEnabled ( false ); + ProfileManagerAction->setEnabled ( false ); + NewProfileWizardAction->setEnabled ( false ); + PrefAction ->setEnabled ( false ); + + ConnectionStatus = i18n("connecting"); + + statusColorLabel->setPixmap ( *connectingStatusPixmap ); + + slotStatusMsg ( i18n ( "Connecting..." ), ID_CONNECTION_MSG ); + slotStatusMsg ( i18n ( "Connecting..." ), ID_FLASH_MSG ); + + connectClicked(); + + } + else if ( status == GlobalConfig->disconnected ) + { + setIcon ( disconnectedIcon ); + mw->buttonConnect->setEnabled ( true ); + mw->buttonDisconnect->setEnabled ( false ); + DisconnectAction->setEnabled ( false ); + ConnectAction->setEnabled ( true ); + mw->SessionCombo->setEnabled ( false ); + ImportCertAction->setEnabled ( true ); + RenameSessionAction->setEnabled ( true ); + DeleteSessionAction->setEnabled ( true ); + ImportSessionAction->setEnabled ( true ); + KVpncDock->setStatus ( disconnected ); + mw->SessionCombo->setEnabled ( true ); + PreferencesAction->setEnabled ( true ); + ProfileManagerAction->setEnabled ( true ); + NewProfileWizardAction->setEnabled ( true ); + PrefAction ->setEnabled ( true ); + + QToolTip::remove( KVpncDock ); + QToolTip::add( KVpncDock, i18n ( "Disconnected" ) ); + + statusColorLabel->setPixmap ( *disconnectedStatusPixmap ); + + slotStatusMsg ( i18n ( "Disconnected" ), ID_CONNECTION_MSG ); + slotStatusMsg ( i18n ( "Disconnected." ), ID_FLASH_MSG ); + + if ( prevConnectionState == GlobalConfig->connected ) + KNotifyClient::event ( topLevelWidget() ->winId(), "connection finished", i18n ( "Connection \"%1\" finished" ).arg ( GlobalConfig->currentProfile->getName() ) ); + else if ( prevConnectionState == GlobalConfig->connecting ) + KNotifyClient::event ( topLevelWidget() ->winId(), "connect try canceled", i18n ( "Connect try to \"%1\" canceled" ).arg ( GlobalConfig->currentProfile->getName() ) ); + } + if (status == GlobalConfig->connecting || status == GlobalConfig->connected) + { + if (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::cisco || GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ciscoorig) + { + if (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::cisco) + { + PrettyTypeString = i18n("Cisco (free)"); + DaemonString = "vpnc"; + } + else + { + PrettyTypeString = i18n("Cisco (proprietary)"); + DaemonString = "vpnclient"; + } + if (GlobalConfig->currentProfile->getAuthType() == VpnAccountData::psk) + { + ToolTipMsg = i18n("\nstatus: %6\nserver: %1\nuser: %2\nIPSec ID: %3\nduration: %4\nprofile: %5").arg(GlobalConfig->currentProfile->getGateway()).arg(GlobalConfig->currentProfile->getUserName()).arg(GlobalConfig->currentProfile->getID()).arg(durationString).arg(GlobalConfig->currentProfile->getName() + " [" + PrettyTypeString + "]").arg(ConnectionStatus); + + ConnectMsg = i18n("%5: %2@%1, %3 [%4]").arg(GlobalConfig->currentProfile->getGateway()).arg(Username).arg(durationString).arg(PrettyTypeString).arg(ConnectionStatus); + + LogMsg = i18n("Successful connected to server: \"%1\", user: \"%2\", IPSec ID: \"%3\" at %4").arg(GlobalConfig->currentProfile->getGateway()).arg(GlobalConfig->currentProfile->getUserName()).arg(GlobalConfig->currentProfile->getID()).arg(QDateTime::currentDateTime().toString(Qt::TextDate) + " [" + PrettyTypeString + "]"); + } + if (GlobalConfig->currentProfile->getAuthType() == VpnAccountData::cert) + { + ToolTipMsg = i18n("\nstatus: %6\nserver: %1\nuser: %2\nIPSec ID: %3\nduration: %4\nprofile: %5").arg(GlobalConfig->currentProfile->getGateway()).arg(Username).arg(durationString).arg(GlobalConfig->currentProfile->getName() + " [" + PrettyTypeString + "]").arg(ConnectionStatus); + + ConnectMsg = i18n("%5: %2@%1, %3 [%4]").arg(GlobalConfig->currentProfile->getGateway()).arg(Username).arg(durationString).arg(PrettyTypeString).arg(ConnectionStatus); + + LogMsg = i18n("Successful connected to server: \"%1\", user: \"%2\" at %3").arg(GlobalConfig->currentProfile->getGateway()).arg(Username).arg(QDateTime::currentDateTime().toString(Qt::TextDate) + " [" + PrettyTypeString + "]"); + } + } + else if (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::pptp) + { + PrettyTypeString = i18n("PPTP"); + DaemonString = "pppd, pptp"; + ToolTipMsg = i18n("status: %5\nserver: %1\nuser: %2\nduration: %3\nprofile %4").arg(GlobalConfig->currentProfile->getGateway()).arg(Username).arg(durationString , GlobalConfig->currentProfile->getName() + " [" + PrettyTypeString + "]").arg(ConnectionStatus); + + ConnectMsg = i18n("Connected: %2@%1, %3").arg(GlobalConfig->currentProfile->getGateway()).arg(Username).arg(durationString); + + QString TypeString2 = " [" + i18n("%1" , PrettyTypeString) + QString("]"); + LogMsg = i18n("Successful connected to server \"%1\"\nuser: \"%2\" at %3").arg(GlobalConfig->currentProfile->getGateway()).arg(Username).arg(QString(QDateTime::currentDateTime().toString(Qt::TextDate)) + TypeString2); + } + else if (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon || GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon || GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan || GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan) + { + if (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon) + { + PrettyTypeString = i18n("racoon"); + DaemonString = "racoon"; + ConnectMsg = i18n("Policy was successfully activated, daemon (%1) is running and tunnel is up.").arg(DaemonString); + } + else if (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan) + { + PrettyTypeString = IpsecType; // openswan, strongswan, ... + DaemonString = "ipsec"; + ConnectMsg = i18n("Policy was successful activated and daemon (%1) is running.").arg(DaemonString); + } + else if (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon) + { + PrettyTypeString = i18n("L2TP (racoon)"); + DaemonString = "racoon, " + GlobalConfig->currentProfile->getL2tpDaemon(); + + ToolTipMsg = i18n("status: %5\nserver: %1\nuser: %2\nduration: %3\nprofile %4").arg(QString(GlobalConfig->currentProfile->getGateway())).arg(Username).arg(durationString).arg(QString(GlobalConfig->currentProfile->getName()) + " [" + PrettyTypeString + "]").arg(ConnectionStatus); + + ConnectMsg = i18n("%5: %2@%1, %3 [%4]").arg(GlobalConfig->currentProfile->getGateway()).arg(Username).arg(durationString).arg(PrettyTypeString).arg(ConnectionStatus); + } + else if (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan) + { + PrettyTypeString = IpsecType; + if (!GlobalConfig->pathToXl2tpd.isEmpty() && QFile(GlobalConfig->pathToXl2tpd).exists()) + DaemonString = "ipsec, " + GlobalConfig->currentProfile->getL2tpDaemon(); + ToolTipMsg = i18n("status: %5\nserver: %1\nuser: %2\nduration: %3\nprofile %4").arg(QString(GlobalConfig->currentProfile->getGateway())).arg(Username).arg(durationString , QString(GlobalConfig->currentProfile->getName()) + " [" + PrettyTypeString + "]").arg(ConnectionStatus); + + ConnectMsg = i18n("%4: %2@%1, %3").arg(QString(GlobalConfig->currentProfile->getGateway())).arg( Username).arg(durationString).arg(ConnectionStatus); + } + else if (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan && GlobalConfig->currentProfile->getAuthWithUsernameAndPassword()) + { + PrettyTypeString = IpsecType; + DaemonString = "ipsec"; + ToolTipMsg = i18n("status: %5\nserver: %1\nuser: %2\nduration: %3\nprofile %4").arg(QString(GlobalConfig->currentProfile->getGateway())).arg(Username).arg(durationString , QString(GlobalConfig->currentProfile->getName()) + " [" + PrettyTypeString + "]").arg(ConnectionStatus); + + ConnectMsg = i18n("Connected: %2@%1, %3").arg(GlobalConfig->currentProfile->getGateway()).arg(Username).arg(durationString); + } + + LogMsg = i18n("Policy successful activated and daemon (%1) running for server \"%2\" (%3) at date %4, profile \"%5\".").arg(DaemonString).arg(GlobalConfig->currentProfile->getGateway()).arg(GlobalConfig->TmpGatewayIP).arg(QDateTime::currentDateTime().toString(Qt::TextDate)).arg(GlobalConfig->currentProfile->getName() + " [" + PrettyTypeString + "]"); + + } + else if (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::openvpn) + { + PrettyTypeString = i18n("OpenVPN"); + DaemonString = "openvpn"; + ToolTipMsg = i18n("status: %3 \nserver: %1\nduration: %2").arg(GlobalConfig->currentProfile->getGateway()).arg(durationString).arg(ConnectionStatus); + + ConnectMsg = i18n("Connected: %1, %2, profile \"%3\"").arg(GlobalConfig->currentProfile->getGateway()).arg(durationString).arg(GlobalConfig->currentProfile->getName() + " [" + PrettyTypeString + "]"); + + LogMsg = i18n("Successful connected to server \"%1\" at %2, profile \"%3\".").arg(GlobalConfig->currentProfile->getGateway()).arg(QDateTime::currentDateTime().toString(Qt::TextDate)).arg(GlobalConfig->currentProfile->getName() + " [" + PrettyTypeString + "]"); + } + else if (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::vtun) + { + PrettyTypeString = i18n("Vtun"); + DaemonString = "vtun"; + ToolTipMsg = i18n("status: %3\nserver: %1\nduration: %2").arg(QString(GlobalConfig->currentProfile->getGateway())).arg(durationString).arg(ConnectionStatus); + + ConnectMsg = i18n("Connected: %1, %2, profile \"%3\"").arg(QString(GlobalConfig->currentProfile->getGateway())).arg(durationString).arg(QString(GlobalConfig->currentProfile->getName() + " [" + PrettyTypeString + "]")); + + LogMsg = i18n("Successful connected to server \"%1\" at %2, profile \"%3\".").arg(QString(GlobalConfig->currentProfile->getGateway())).arg(QDateTime::currentDateTime().toString(Qt::TextDate)).arg(QString(GlobalConfig->currentProfile->getName()) + " [" + PrettyTypeString + "]"); + } + else if (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ssh) + { + PrettyTypeString = i18n("SSH"); + DaemonString = "ssh"; + ToolTipMsg = i18n("status: %3\nserver: %1\nduration: %2").arg(QString(GlobalConfig->currentProfile->getGateway())).arg(durationString).arg(ConnectionStatus); + + ConnectMsg = i18n("%4: %1, %2, profile \"%3\"").arg(QString(GlobalConfig->currentProfile->getGateway())).arg(durationString ).arg(QString(GlobalConfig->currentProfile->getName() + " [" + PrettyTypeString + "]")); + + LogMsg = i18n("Successful connected to server \"%1\" at %2, profile \"%3\".").arg(GlobalConfig->currentProfile->getGateway()).arg(QDateTime::currentDateTime().toString(Qt::TextDate)).arg(GlobalConfig->currentProfile->getName() + " [" + PrettyTypeString + "]"); + } + if (status == GlobalConfig->connected) + KNotifyClient::event ( topLevelWidget() ->winId(), "connection established", ConnectMsg ); + } + +} + +void KVpnc::importKvpncSettingsClicked() +{ + QString filename = KFileDialog::getOpenFileName ( QString ( "." ), QString ( "*.xml *.kvpnc" ), 0,i18n ( "KVpnc settings import" ) ); + + if ( !filename.isEmpty() ) + { + bool openProfileManager=false; + QString RetName=""; + bool ret = GlobalConfig->importKvpncConfig ( filename,RetName,openProfileManager ); + if ( ret == true ) + { + mw->SessionCombo->clear(); + QuickConnectMenu->clear(); + + for ( uint i = 0; i < GlobalConfig->AccountList->count();i++ ) + { + QuickConnectMenu->insertItem ( GlobalConfig->AccountList->at ( i ) ->getName() ); + mw->SessionCombo->insertItem ( GlobalConfig->AccountList->at ( i ) ->getName() ); + } + if ( !mw->SessionCombo->isEnabled() ) + mw->SessionCombo->setEnabled ( TRUE ); + + this->ConnectAction->setEnabled ( true ); + mw->SessionCombo->setCurrentText ( RetName ); + sessionToggled ( RetName ); + +// KMessageBox::information ( 0, i18n ( "Import of \"%1\" was successful." ).arg ( filename ) ); +// GlobalConfig->appendLogEntry ( i18n ( "Import of \"%1\" was successful." ).arg ( filename ), GlobalConfig->info ); +// slotStatusMsg ( i18n ( "Import of \"%1\" was successful." ).arg ( filename ), ID_FLASH_MSG ); + if ( openProfileManager==true ) + showProfileManagerClicked(); + } + + } +} + +void KVpnc::exportKvpncSettingsClicked() +{ + QString filename = KFileDialog::getOpenFileName ( QString ( "." ), QString ( "*.xml *.kvpnc" ), 0,i18n ( "KVpnc settings export" ) ); + + if ( !filename.isEmpty() ) + { + GlobalConfig->exportKvpncConfig ( filename ); +// KMessageBox::information( 0, i18n( "Export was successful." ), i18n( "Export success" ) ); + } +} + +void KVpnc::importProfileClicked ( QString file ) +{ + + ImportProfileDialog dlg ( GlobalConfig, this, i18n ( "Import profile" ), file ); + dlg.exec(); + dlg.resize ( 800, dlg.height() ); + + bool importOK = dlg.importOk; + bool ok = false; + bool openProfileManager=dlg.main->OpenProfileManagerCheckBox->isChecked(); + if ( importOK ) + { + VpnAccountData * account = dlg.acc; + + VpnAccountData * it; + bool nameOk = false; + while ( nameOk == false ) + { + for ( it = GlobalConfig->AccountList->first(); it; it = GlobalConfig->AccountList->next() ) + { + if ( it->getName() == account->getName() ) + { + //account->setName( QString( account->getName() + "_2" ) ); + // KMessageBox::information ( this, i18n( "Profile name exists!\n It will be renamed to \"%1\"." ).arg( account->getName() ), i18n( "Name exist, renamed" ) ); + KMessageBox::error ( 0, i18n ( "Profile name exists!" ), i18n ( "Name Exists" ) ); + nameOk = false; + QString newName = KInputDialog::getText ( i18n ( "New Name" ), i18n ( "New name for profile:" ), QString ( account->getName() + "_2" ), &ok ); + if (newName.isEmpty()) + { + KMessageBox::information ( 0, i18n ( "Import was canceled." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Import was canceled." ), GlobalConfig->info ); + return; + } + if (newName != it->getName() ) + { + account->setName ( newName ); + nameOk = true; + } + } + else + { + nameOk = true; + } + } + } + + if ( nameOk == true ) + { + GlobalConfig->AccountList->append ( account ); + mw->SessionCombo->clear(); + QuickConnectMenu->clear(); + + for ( uint i = 0; i < GlobalConfig->AccountList->count();i++ ) + { + QuickConnectMenu->insertItem ( GlobalConfig->AccountList->at ( i ) ->getName() ); + mw->SessionCombo->insertItem ( GlobalConfig->AccountList->at ( i ) ->getName() ); + } + mw->SessionCombo->setCurrentText ( account->getName() ); + + if ( !mw->SessionCombo->isEnabled() ) + mw->SessionCombo->setEnabled ( TRUE ); + + this->ConnectAction->setEnabled ( true ); + sessionToggled ( account->getName() ); + + KMessageBox::information ( 0, i18n ( "Import of \"%1\" was successful." ).arg ( account->getName() ) ); + GlobalConfig->appendLogEntry ( i18n ( "Import of \"%1\" (%2) was successful." ).arg ( account->getName() ).arg ( "PCF" ), GlobalConfig->info ); + slotStatusMsg ( i18n ( "Import of \"%1\" (%2) was successful." ).arg ( account->getName() ).arg ( "PCF" ), ID_FLASH_MSG ); + + GlobalConfig->saveOptions(); + // std::cout << "save done" << std::endl; + + QString bin = "vpnc"; + ToolInfo *tool; + //std::cout << "Tool (bin): " << bin << std::endl; + if ( !GlobalConfig->ToolList->isEmpty() ) + { + for ( tool = GlobalConfig->ToolList->first(); tool; tool = GlobalConfig->ToolList->next() ) + { + if ( bin == tool->Name ) + { + if ( tool->PathToExec.section ( '/', -1 ) != bin ) + { + // program is NOT installed + KMessageBox::information ( this, i18n ( "The required tool (%1) is not installed, please install it before you are connecting and restart kvpnc." ).arg ( bin ), i18n ( "Tool Missing" ) ); + } + break; + } + } + } + if ( openProfileManager==true ) + showProfileManagerClicked(); + // std::cout << "show profilemanager" << std::endl; + } + else + { + KMessageBox::information ( 0, i18n ( "Import was canceled." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Import was canceled." ), GlobalConfig->info ); + slotStatusMsg ( i18n ( "Import was canceled." ), ID_FLASH_MSG ); + } + } +} + +void KVpnc::importProfileClicked() +{ + importProfileClicked ( "" ); +} + +void KVpnc::importOpenvpnProfileClicked() +{ + importOpenvpnProfileClicked ( "" ); +} + +void KVpnc::importOpenvpnProfileClicked ( QString file ) +{ + + ImportOpenvpnProfileDialog dlg ( GlobalConfig, this, i18n ( "Import OpenVPN profile" ), file ); + dlg.exec(); + dlg.resize ( 800, dlg.height() ); + bool importOK = dlg.importOk; + bool openProfileManager=dlg.main->OpenProfileManagerCheckBox->isChecked(); + if ( importOK ) + { + VpnAccountData * account = dlg.acc; + + VpnAccountData * it; + bool nameOk = false; + bool ok = true; + while ( nameOk == false ) + { + for ( it = GlobalConfig->AccountList->first(); it; it = GlobalConfig->AccountList->next() ) + { + if ( it->getName() == account->getName() ) + { + //account->setName( QString( account->getName() + "_2" ) ); + // KMessageBox::information ( this, i18n( "Profile name exists!\n It will be renamed to \"%1\"." ).arg( account->getName() ), i18n( "Name exist, renamed" ) ); + KMessageBox::error ( this, i18n ( "Profile name exists!" ), i18n ( "Name Exists" ) ); + + QString newName = KInputDialog::getText ( i18n ( "New Name" ), i18n ( "New name for profile:" ), QString ( account->getName() + "_2" ), &ok ); + if ( ok == false ) + { + KMessageBox::information ( 0, i18n ( "Import was canceled." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Import was canceled." ), GlobalConfig->info ); + slotStatusMsg ( i18n ( "Import was canceled." ), ID_FLASH_MSG ); + return ; + } + else + { + it = GlobalConfig->AccountList->first(); + account->setName ( newName ); + nameOk = true; + } + } + nameOk = true; + } + nameOk = true; + } + + GlobalConfig->AccountList->append ( account ); + mw->SessionCombo->clear(); + QuickConnectMenu->clear(); + + for ( uint i = 0; i < GlobalConfig->AccountList->count();i++ ) + { + QuickConnectMenu->insertItem ( GlobalConfig->AccountList->at ( i ) ->getName() ); + mw->SessionCombo->insertItem ( GlobalConfig->AccountList->at ( i ) ->getName() ); + } + mw->SessionCombo->setCurrentText ( account->getName() ); + + if ( !mw->SessionCombo->isEnabled() ) + mw->SessionCombo->setEnabled ( TRUE ); + + this->ConnectAction->setEnabled ( true ); + sessionToggled ( account->getName() ); + + KMessageBox::information ( 0, i18n ( "Import of \"%1\" was successful." ).arg ( account->getName() ) ); + GlobalConfig->appendLogEntry ( i18n ( "Import of \"%1\" (%2) was successful." ).arg ( account->getName() ).arg ( "OpenVPN" ), GlobalConfig->info ); + slotStatusMsg ( i18n ( "Import of \"%1\" (%2) was successful." ).arg ( account->getName() ).arg ( "OpenVPN" ), ID_FLASH_MSG ); + + GlobalConfig->saveOptions(); + // std::cout << "save done" << std::endl; + + QString bin = "openvpn"; + ToolInfo *tool; + //std::cout << "Tool (bin): " << bin << std::endl; + if ( !GlobalConfig->ToolList->isEmpty() ) + { + for ( tool = GlobalConfig->ToolList->first(); tool; tool = GlobalConfig->ToolList->next() ) + { + if ( bin == tool->Name ) + { + if ( tool->PathToExec.section ( '/', -1 ) != bin ) + { + // program is NOT installed + KMessageBox::information ( this, i18n ( "The required tool (%1) is not installed, please install it before you are connecting and restart kvpnc." ).arg ( bin ), i18n ( "Tool Missing" ) ); + } + break; + } + } + } + + if ( openProfileManager ) + showProfileManagerClicked(); + // std::cout << "show profilemanager" << std::endl; + + } + +} + +void KVpnc::importIpsecProfileClicked () +{ + QString filename = KFileDialog::getOpenFileName ( QString ( "." ), QString ( "*.ipsec *.conf" ), 0,i18n ( "IPSec settings import" ) ); + + if ( !filename.isEmpty() ) + { + bool openProfileManager=false; + QString RetName=""; + bool ret = GlobalConfig->importIpsecConfig ( filename,RetName,openProfileManager ); + if ( ret == true ) + { + mw->SessionCombo->clear(); + QuickConnectMenu->clear(); + + for ( uint i = 0; i < GlobalConfig->AccountList->count();i++ ) + { + QuickConnectMenu->insertItem ( GlobalConfig->AccountList->at ( i ) ->getName() ); + mw->SessionCombo->insertItem ( GlobalConfig->AccountList->at ( i ) ->getName() ); + } + if ( !mw->SessionCombo->isEnabled() ) + mw->SessionCombo->setEnabled ( TRUE ); + + this->ConnectAction->setEnabled ( true ); + + mw->SessionCombo->setCurrentText ( RetName ); + sessionToggled ( RetName ); + +// KMessageBox::information ( 0, i18n ( "Import of \"%1\" was successful." ).arg ( filename ) ); +// GlobalConfig->appendLogEntry ( i18n ( "Import of \"%1\" was successful." ).arg ( filename ), GlobalConfig->info ); +// slotStatusMsg ( i18n ( "Import of \"%1\" was successful." ).arg ( filename ), ID_FLASH_MSG ); + + } + if ( openProfileManager==true ) + showProfileManagerClicked(); + + } + +} + +void KVpnc::importFritzboxProfileClicked () +{ + QString filename = KFileDialog::getOpenFileName ( QString ( "." ), QString ( "vpnuser*.cfg" ), 0,i18n ( "Fritzbox VPN settings import" ) ); + + if ( !filename.isEmpty() ) + { + bool openProfileManager=false; + QString RetName=""; + bool ret = GlobalConfig->importFritzboxConfig ( filename,RetName,openProfileManager ); + if ( ret == true ) + { + mw->SessionCombo->clear(); + QuickConnectMenu->clear(); + + for ( uint i = 0; i < GlobalConfig->AccountList->count();i++ ) + { + QuickConnectMenu->insertItem ( GlobalConfig->AccountList->at ( i ) ->getName() ); + mw->SessionCombo->insertItem ( GlobalConfig->AccountList->at ( i ) ->getName() ); + } + if ( !mw->SessionCombo->isEnabled() ) + mw->SessionCombo->setEnabled ( TRUE ); + + this->ConnectAction->setEnabled ( true ); + + mw->SessionCombo->setCurrentText ( RetName ); + sessionToggled ( RetName ); + +// KMessageBox::information ( 0, i18n ( "Import of \"%1\" was successful." ).arg ( filename ) ); +// GlobalConfig->appendLogEntry ( i18n ( "Import of \"%1\" was successful." ).arg ( filename ), GlobalConfig->info ); +// slotStatusMsg ( i18n ( "Import of \"%1\" was successful." ).arg ( filename ), ID_FLASH_MSG ); + + } + if ( openProfileManager==true ) + showProfileManagerClicked(); + + } + +} + +void KVpnc::slotCancelClicked() +{ + cancelClicked = true; +} + +void KVpnc::addRouteRacoon() +{ + + // if ( RacoonHelperProcess->normalExit () ) + { + // disconnect( RacoonHelperProcess, SIGNAL( processExited () ), this, SLOT( addRouteRacoon() ) ); + // disconnect( RacoonHelperProcess, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdout_racoon_helper() ) ); + // disconnect( RacoonHelperProcess, SIGNAL( readyReadStderr() ), this, SLOT( readFromStderr_racoon_helper() ) ); + + + tmpPath = locateLocal ( "data", "kvpnc/" ); + QString RacoonRouteSetScript = tmpPath + "/set_route." + GlobalConfig->currentProfile->getName() + ".sh"; + NetworkInterface iface ( GlobalConfig, parent ); + QString defaultinterface = iface.getDefaultInterface(); + QString dev = "lo"; + + QString RemoteNetAddr = GlobalConfig->currentProfile->getRemoteNetAddr(); + QString RemoteNetMask = GlobalConfig->currentProfile->getRemoteNetMask(); + QString RemoteNet = RemoteNetAddr + "/" + RemoteNetMask; + + tmpInterface = iface.getDefaultInterface(); + + if ( GlobalConfig->currentProfile->getUseVirtualIP() ) + dev = QString ( dev + ":100" ); + else + dev = tmpInterface; + + QFile RacoonSetRouteScript ( RacoonRouteSetScript ); + QTextStream stream ( &RacoonSetRouteScript ); + if ( RacoonSetRouteScript.open ( IO_WriteOnly ) ) + { + if ( GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + { + stream << GlobalConfig->pathToIp << " route show | grep 'default via' > " + tmpPath + "/defaultroute_before." + GlobalConfig->currentProfile->getName() << "\n"; + stream << GlobalConfig->pathToRoute << " del default" << "\n"; + + stream << GlobalConfig->pathToRoute << " add default gw " << GlobalConfig->currentProfile->getGateway() << " " << iface.getDefaultInterface() << "\n"; + } + + // FIXME racoon_l2tpd too? + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon && GlobalConfig->currentProfile->getUseRemoteNetwork()) + { + if (GlobalConfig->currentProfile->getUseLeftSourceIp() ) + { + // virtual ip + } + else + { + stream << GlobalConfig->pathToRoute << " add -net " << RemoteNet << " " << dev << "\n"; + } + } + RacoonSetRouteScript.close(); + + RouteProcess = new QProcess ( this ); + RouteProcess->addArgument ( GlobalConfig->InterpreterShell ); + RouteProcess->addArgument ( RacoonRouteSetScript ); + + connect ( RouteProcess, SIGNAL ( readyReadStdout () ), this, SLOT ( readFromStdout_route() ) ); + connect ( RouteProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_route() ) ); + + if ( !RouteProcess->start ( env ) ) + { + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( "route (racoon)" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "route (racoon)" ) , GlobalConfig->error ); + disconnectClicked(); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + { + if ( GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + GlobalConfig->appendLogEntry ( i18n ( "route (%1): route add default gw " ).arg ( "racoon" ) + GlobalConfig->currentProfile->getGateway() + " " + tmpInterface, GlobalConfig->debug ); + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon && !GlobalConfig->currentProfile->getUseLeftSourceIp() && GlobalConfig->currentProfile->getUseRemoteNetwork()) + GlobalConfig->appendLogEntry ( i18n ( "route (%1): route add -net " ).arg ( "racoon" ) + RemoteNet + " " + tmpInterface, GlobalConfig->debug ); + } + while ( RouteProcess->isRunning() ) + { + sleep ( 1 ); + } + } + delete RouteProcess; + RouteProcess=0L; + } + } +} + +void KVpnc::delRouteRacoon() +{ + + // if ( DisconnectProcess != 0 ) + { + disconnect ( DisconnectProcess, SIGNAL ( processExited () ), this, SLOT ( delRouteRacoon() ) ); + + tmpPath = locateLocal ( "data", "kvpnc/" ); + QString RacoonRouteSetScript = tmpPath + "/remove_route." + GlobalConfig->currentProfile->getName() + ".sh"; + NetworkInterface iface ( GlobalConfig, parent ); + QString dev = "lo"; + + QString RemoteNetAddr = GlobalConfig->currentProfile->getRemoteNetAddr(); + QString RemoteNetMask = GlobalConfig->currentProfile->getRemoteNetMask(); + QString RemoteNet = RemoteNetAddr + "/" + RemoteNetMask; + + tmpInterface = iface.getDefaultInterface(); + + if ( GlobalConfig->currentProfile->getUseVirtualIP() ) + dev = QString ( dev + ":100" ); + else + dev = tmpInterface; + + QFile RacoonSetRouteScript ( RacoonRouteSetScript ); + QTextStream stream ( &RacoonSetRouteScript ); + if ( RacoonSetRouteScript.open ( IO_WriteOnly ) ) + { + if ( GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + { + stream << GlobalConfig->pathToRoute << " del default" << "\n"; + stream << GlobalConfig->pathToIp << " route add `cat " + tmpPath + "/defaultroute_before." + GlobalConfig->currentProfile->getName() << "`" << "\n"; + } + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon && GlobalConfig->currentProfile->getUseRemoteNetwork() ) + { + if (GlobalConfig->currentProfile->getUseLeftSourceIp() ) + { + // virtual ip + } + else + { + stream << GlobalConfig->pathToRoute << " del -net " << RemoteNet << " " << dev << "\n"; + } + } + RacoonSetRouteScript.close(); + + RouteProcess = new QProcess ( this ); + RouteProcess->addArgument ( GlobalConfig->InterpreterShell ); + RouteProcess->addArgument ( RacoonRouteSetScript ); + + connect ( RouteProcess, SIGNAL ( readyReadStdout () ), this, SLOT ( readFromStdout_route() ) ); + connect ( RouteProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_route() ) ); + // connect( DisconnectProcess, SIGNAL( processExited () ), this, SLOT( removeIptablesRacoon() ) ); + + if ( !RouteProcess->start ( env ) ) + { + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( "del route (racoon)" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "del route (racoon)" ) , GlobalConfig->error ); + + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + { + if ( GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + GlobalConfig->appendLogEntry ( i18n ( "route (%1): route del default gw " ).arg ( "racoon" ) + GlobalConfig->currentProfile->getGateway() + " " + tmpInterface, GlobalConfig->debug ); + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon && !GlobalConfig->currentProfile->getUseLeftSourceIp() && GlobalConfig->currentProfile->getUseRemoteNetwork()) + GlobalConfig->appendLogEntry ( i18n ( "route (%1): route del -net " ).arg ( "racoon" ) + RemoteNet + " " + tmpInterface, GlobalConfig->debug ); + } + while ( RouteProcess->isRunning() ) + { + sleep ( 1 ); + } + } + delete RouteProcess; + RouteProcess=0L; + } + } +} + +void KVpnc::doIptablesRacoon() +{ + // if ( ConnectProcess->normalExit () ) + { + // if ( ConnectProcess ) + // disconnect( ConnectProcess, SIGNAL( processExited () ), this, SLOT( doIptablesRacoon() ) ); + /* + iptables -I INPUT -p 50 -i $IFACE -s $VPNGW_IP -j ACCEPT + */ + putenv ( ( char* ) ( "LC_ALL=C" ) ); + IptablesProcess = new QProcess ( this ); + IptablesProcess->addArgument ( GlobalConfig->InterpreterShell ); + IptablesProcess->addArgument ( tmpPath + "iptables." + GlobalConfig->currentProfile->getName() + ".add_racoon.sh" ); + + // connect( IptablesProcess, SIGNAL( processExited () ), this, SLOT( doRacoon() ) ); + + if ( !IptablesProcess->start ( env ) ) + { + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( "iptables." + GlobalConfig->currentProfile->getName() + ".add_racoon.sh" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "iptables." + GlobalConfig->currentProfile->getName() + ".add_racoon.sh" ) , GlobalConfig->error ); + disconnectClicked(); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( "iptables." + GlobalConfig->currentProfile->getName() + ".add_racoon.sh" ) , GlobalConfig->debug ); + while ( IptablesProcess->isRunning() ) + { + sleep ( 1 ); + } + } + delete IptablesProcess; + IptablesProcess=0L; + } +} + +void KVpnc::doPingKickupTunnel() +{ + + if ( GlobalConfig->KvpncDebugLevel > 4 ) + GlobalConfig->appendLogEntry ( i18n ( "Sending ping for kicking up the tunnel..." ), GlobalConfig->debug ); + /* first: kick up the tunnel */ + putenv ( ( char* ) ( "LC_ALL=C" ) ); + QProcess PingProcess; + QString PathToPing = ""; + ToolInfo *Tool; + for ( Tool = GlobalConfig->ToolList->first();Tool;Tool = GlobalConfig->ToolList->next() ) + { + if ( Tool->Name == "ping" ) + { + PathToPing = Tool->PathToExec; + break; + } + } + PingProcess.addArgument ( PathToPing ); + PingProcess.addArgument ( "-c"); + PingProcess.addArgument ( "1" ); + PingProcess.addArgument ( "-w" ); + PingProcess.addArgument ( "2" ); + if (GlobalConfig->currentProfile->getUseRemoteNetwork()) + PingProcess.addArgument ( GlobalConfig->currentProfile->getRemoteNetAddr() ); + else + PingProcess.addArgument ( GlobalConfig->currentProfile->getGateway() ); + + if ( !PingProcess.start ( env ) ) + { + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( "ping " + GlobalConfig->currentProfile->getPingHostIP() ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "ping " + GlobalConfig->currentProfile->getPingHostIP() ), GlobalConfig->error ); + } +} + +void KVpnc::doRacoon() +{ + disconnect ( RacoonHelperProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_racoon_helper() ) ); + disconnect ( RacoonHelperProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_racoon_helper() ) ); + disconnect ( RacoonHelperProcess, SIGNAL ( processExited () ), this, SLOT ( doRacoon() ) ); + + + + if ( RacoonHelperProcess->normalExit () ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[racoon]: " + i18n ( "%1 finished." ).arg ( "setkey" ), GlobalConfig->debug ); + + /* + /usr/sbin/racoon -f -l + */ + QFile f ( tmpPath + "racoon." + GlobalConfig->currentProfile->getName() + ".log" ); + if ( f.exists() ) + f.remove(); + QTextStream s ( &f ); + if ( f.open ( IO_WriteOnly ) ) + { + s << "\n"; + } + f.close(); + s.unsetDevice(); + putenv ( ( char* ) ( "LC_ALL=C" ) ); + RacoonProcess = 0; + RacoonProcess = new QProcess ( this ); + RacoonProcess->addArgument ( GlobalConfig->pathToRacoon ); + RacoonProcess->addArgument ( "-F" ); // foreground we want :) +// RacoonProcess->addArgument ( "-v" ); +// RacoonProcess->addArgument ( "-dd" ); + RacoonProcess->addArgument ( "-f" ); + RacoonProcess->addArgument ( tmpPath + "racoon." + GlobalConfig->currentProfile->getName() + ".conf" ); + RacoonProcess->addArgument ( "-l" ); // logfile (we get content with tail process) + RacoonProcess->addArgument ( tmpPath + "racoon." + GlobalConfig->currentProfile->getName() + ".log" ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "racoon: " + GlobalConfig->pathToRacoon + " -f " + tmpPath + "/racoon." + GlobalConfig->currentProfile->getName() + ".conf", GlobalConfig->debug ); + +// RacoonProcess->setCommunication ( QProcess::Stdin | QProcess::Stdout | QProcess::Stderr | QProcess::DupStderr ); +// RacoonProcess->closeStdin(); + connect ( RacoonProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_racoon() ) ); + connect ( RacoonProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_racoon() ) ); + + + if ( !RacoonProcess->start ( env ) ) + { + disconnect ( RacoonProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_racoon() ) ); + disconnect ( RacoonProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_racoon() ) ); + delete RacoonProcess; + RacoonProcess=0L; + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( "racoon" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "racoon" ) , GlobalConfig->error ); + disconnectClicked(); + } + else + { + racoon_tunnel_state = 0; + + if ( GlobalConfig->RacoonDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "%1 started. " ).arg ( "racoon" ), GlobalConfig->info ); + + doTailRacoonLog(); + sleep ( 3 ); + + racoonStarted(); + + // sec = hour = min = 0; + + // GlobalConfig->status = GlobalConfig->disconnected; + // timer.stop(); + // connect( &durationTimer, SIGNAL( timeout() ), this, SLOT( slotDurationEvent() ) ); + // durationTimer.start( 1000, FALSE ); + } + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[racoon]: " + i18n ( "%1 finished with error." ).arg ( "setkey" ), GlobalConfig->debug ); + + } + delete RacoonHelperProcess; + RacoonHelperProcess=0L; +} + +void KVpnc::stopRacoon() +{ + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Stopping %1." ).arg ( "racoon" ), GlobalConfig->debug ); + + putenv ( ( char* ) ( "LC_ALL=C" ) ); + RacoonctlProcess = new QProcess ( this ); + QString PathToRacoonctl = ""; + ToolInfo* Tool = Utils ( GlobalConfig ).getToolInfo ( "racoonctl" ); + PathToRacoonctl = Tool->PathToExec; + + RacoonctlProcess->addArgument ( PathToRacoonctl ); + RacoonctlProcess->addArgument ( "vpn-disconnect" ); + + RacoonctlProcess->addArgument ( GlobalConfig->TmpGatewayIP ); + + connect ( RacoonctlProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_racoonctl() ) ); + connect ( RacoonctlProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_racoonctl() ) ); + connect ( RacoonctlProcess, SIGNAL ( processExited () ), this, SLOT ( racoonctlExited() ) ); + + + if ( !RacoonctlProcess->start ( env ) ) + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( QString ( "racoonctl vpn-disconnect "+GlobalConfig->TmpGatewayIP ) ) ); + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "%1 started. " ).arg ( QString ( "racoonctl vpn-disconnect "+GlobalConfig->TmpGatewayIP ) ), GlobalConfig->info ); + + while ( RacoonctlProcess->isRunning() ) + { + usleep ( 500 ); + // parent->QApplication::processEvents(); + } + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" finished." ).arg ( QString ( "racoonctl vpn-disconnect "+GlobalConfig->TmpGatewayIP ) ), GlobalConfig->debug ); + } + disconnect ( RacoonctlProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_racoonctl() ) ); + disconnect ( RacoonctlProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_racoonctl() ) ); + disconnect ( RacoonctlProcess, SIGNAL ( processExited () ), this, SLOT ( racoonctlExited() ) ); + delete RacoonctlProcess; + RacoonctlProcess=0L; +} + +void KVpnc::doTailRacoonLog() +{ + putenv ( ( char* ) ( "LC_ALL=C" ) ); + RacoonTailProcess = new QProcess ( this ); + RacoonTailProcess->addArgument ( GlobalConfig->pathToTail ); + RacoonTailProcess->addArgument ( "-n" ); + RacoonTailProcess->addArgument ( "1000" ); + RacoonTailProcess->addArgument ( "-f" ); + RacoonTailProcess->addArgument ( tmpPath + "racoon." + GlobalConfig->currentProfile->getName() + ".log" ); + + connect ( RacoonTailProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_tail_racoon() ) ); + connect ( RacoonTailProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_tail_racoon() ) ); + + if ( !RacoonTailProcess->start ( env ) ) + { + disconnect ( RacoonTailProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_tail_racoon() ) ); + disconnect ( RacoonTailProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_tail_racoon() ) ); + delete RacoonTailProcess; + RacoonTailProcess=0L; + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( GlobalConfig->pathToTail+" -f " + tmpPath + "racoon." + GlobalConfig->currentProfile->getName() + ".log" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( GlobalConfig->pathToTail+" -f " + tmpPath + "racoon." + GlobalConfig->currentProfile->getName() + ".log" ) , GlobalConfig->error ); + disconnectClicked(); + } + else + { + // status=connected; + // setGuiStatus(connected); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( GlobalConfig->pathToTail+" -f " + tmpPath + "racoon." + GlobalConfig->currentProfile->getName() + ".log" ), GlobalConfig->debug ); + + + } +} + +void KVpnc::removeIptablesRacoon() +{ + // if ( DisconnectProcess != 0 ) + { + // if ( DisconnectProcess ) + // disconnect( DisconnectProcess, SIGNAL( processExited () ), this, SLOT( removeIptablesRacoon() ) ); + + putenv ( ( char* ) ( "LC_ALL=C" ) ); + DisconnectProcess = new QProcess ( this ); + DisconnectProcess->addArgument ( GlobalConfig->InterpreterShell ); + DisconnectProcess->addArgument ( tmpPath + "iptables." + GlobalConfig->currentProfile->getName() + ".remove_racoon.sh" ); + if ( !DisconnectProcess->start ( env ) ) + { + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( "iptables." + GlobalConfig->currentProfile->getName() + ".remove_racoon.sh" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "iptables." + GlobalConfig->currentProfile->getName() + ".remove_racoon.sh" ), GlobalConfig->error ); + disconnectClicked(); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( "iptables." + GlobalConfig->currentProfile->getName() + ".remove_racoon.sh" ), GlobalConfig->debug ); + while ( DisconnectProcess->isRunning() ) + { + usleep ( 500 ); + // parent->QApplication::processEvents(); + } + } + delete DisconnectProcess; + DisconnectProcess=0L; + } +} + +void KVpnc::removeSetkey() +{ + if ( DisconnectProcess ) + disconnect ( DisconnectProcess, SIGNAL ( processExited () ), this, SLOT ( removeSetkey() ) ); + + putenv ( ( char* ) ( "LC_ALL=C" ) ); + RemoveSetkeyProcess = new QProcess ( this ); + RemoveSetkeyProcess->addArgument ( GlobalConfig->InterpreterShell ); + RemoveSetkeyProcess->addArgument ( tmpPath + "setkey." + GlobalConfig->currentProfile->getName() + ".remove_setkey.sh" ); + + // connect( RemoveSetkeyProcess, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdout_remove_setkey() ) ); + // connect( RemoveSetkeyProcess, SIGNAL( readyReadStderr() ), this, SLOT( readFromStderr_remove_setkey() ) ); + // connect( RemoveSetkeyProcess, SIGNAL( processExited () ), this, SLOT( delRouteRacoon() ) ); + + if ( !RemoveSetkeyProcess->start ( env ) ) + { + // KMessageBox::error( this, i18n( "\"%1\" start failed!" ).arg( "setkey (remove)" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "setkey (remove)" ) , GlobalConfig->error ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( "setkey (remove)" ), GlobalConfig->debug ); + while ( RemoveSetkeyProcess->isRunning() ) + { + usleep ( 500 ); + // parent->QApplication::processEvents(); + } + } + delete RemoveSetkeyProcess; + RemoveSetkeyProcess=0L; + + // connectionEnded(); +} + +void KVpnc::doIptablesFreeswan() +{ + // if ( ConnectProcess->normalExit () ) + { + // disconnect( ConnectProcess, SIGNAL( processExited () ), this, SLOT( doIptablesFreeswan() ) ); + /* + iptables -I INPUT -p 50 -i $IFACE -s $VPNGW_IP -j ACCEPT + */ + putenv ( ( char* ) ( "LC_ALL=C" ) ); + IptablesProcess = new QProcess ( this ); + IptablesProcess->addArgument ( GlobalConfig->InterpreterShell ); + IptablesProcess->addArgument ( tmpPath + "iptables." + GlobalConfig->currentProfile->getName() + ".add_ipsec_freeswan.sh" ); + + if ( !IptablesProcess->start ( env ) ) + { + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( "iptables." + GlobalConfig->currentProfile->getName() + ".add_ipsec_freeswan.sh" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "iptables." + GlobalConfig->currentProfile->getName() + ".add_ipsec_freeswan.sh" ) , GlobalConfig->error ); + disconnectClicked(); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( "iptables.%1.add_ipsec_freeswan.sh" ).arg ( GlobalConfig->currentProfile->getName() ), GlobalConfig->debug ); + + while ( IptablesProcess->isRunning() ) + { + usleep ( 500 ); + // parent->QApplication::processEvents(); + } + + setFirewallAfterConnect(); + if ( GlobalConfig->currentProfile->getExecuteCmdAfterConnect() ) + executeCommandAfterConnect(); + } + delete IptablesProcess; + IptablesProcess=0L; + } +} + +void KVpnc::addRouteIpsec() +{ + tmpPath = locateLocal ( "data", "kvpnc/" ); + QString IpsecRouteSetScript = tmpPath + "/set_route." + GlobalConfig->currentProfile->getName() + ".sh"; + NetworkInterface iface ( GlobalConfig, parent ); + QString defaultinterface = iface.getDefaultInterface(); + QString dev = "lo"; + + QString RemoteNetAddr = GlobalConfig->currentProfile->getRemoteNetAddr(); + QString RemoteNetMask = GlobalConfig->currentProfile->getRemoteNetMask(); + QString RemoteNet = RemoteNetAddr + "/" + RemoteNetMask; + + if ( iface.interfaceExist ( "ipsec0" ) ) + tmpInterface = "ipsec0"; + else + tmpInterface = iface.getDefaultInterface(); + + if ( GlobalConfig->currentProfile->getUseVirtualIP() ) + dev = QString ( dev + ":100" ); + else + dev = tmpInterface; + + QFile IpsecSetRouteScript ( IpsecRouteSetScript ); + QTextStream stream ( &IpsecSetRouteScript ); + if ( IpsecSetRouteScript.open ( IO_WriteOnly ) ) + { + if ( GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + { + stream << GlobalConfig->pathToIp << " route show | grep 'default via' > " + tmpPath + "default-route." + GlobalConfig->currentProfile->getName() << "\n"; + stream << GlobalConfig->pathToRoute << " del default" << "\n"; + + stream << GlobalConfig->pathToRoute << " add default gw " << GlobalConfig->currentProfile->getGateway() << " " << iface.getDefaultInterface() << "\n"; + } + // stream << GlobalConfig->pathToRoute << " add -net " << RemoteNet << " " << dev << "\n"; // set by opnswan + IpsecSetRouteScript.close(); + + RouteProcess = new QProcess ( this ); + RouteProcess->addArgument ( GlobalConfig->InterpreterShell ); + RouteProcess->addArgument ( IpsecRouteSetScript ); + + connect ( RouteProcess, SIGNAL ( readyReadStdout () ), this, SLOT ( readFromStdout_route() ) ); + connect ( RouteProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_route() ) ); + + if ( !RouteProcess->start ( env ) ) + { + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( "route (%1)" ).arg ( IpsecType ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "route (%1)" ).arg ( IpsecType ) , GlobalConfig->error ); + // disconnectClicked(); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + { + if ( GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + GlobalConfig->appendLogEntry ( i18n ( "route (%1): route add default gw " ).arg ( "ipsec" ) + GlobalConfig->currentProfile->getGateway() + " " + tmpInterface, GlobalConfig->debug ); + // GlobalConfig->appendLogEntry ( i18n( "route (%1): route add -net " ).arg("ipsec") + RemoteNet << " " + tmpInterface, GlobalConfig->debug ); + while ( RouteProcess->isRunning() ) + { + usleep ( 500 ); + // parent->QApplication::processEvents(); + } + } + } + disconnect ( RouteProcess, SIGNAL ( readyReadStdout () ), this, SLOT ( readFromStdout_route() ) ); + disconnect ( RouteProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_route() ) ); + delete RouteProcess; + RouteProcess=0L; + } +} + +void KVpnc::delRouteIpsec() +{ + tmpPath = locateLocal ( "data", "kvpnc/" ); + QString IpsecRouteSetScript = tmpPath + "/remove_route." + GlobalConfig->currentProfile->getName() + ".sh"; + NetworkInterface iface ( GlobalConfig, parent ); + QString dev = "lo"; + + QString RemoteNetAddr = GlobalConfig->currentProfile->getRemoteNetAddr(); + QString RemoteNetMask = GlobalConfig->currentProfile->getRemoteNetMask(); + QString RemoteNet = RemoteNetAddr + "/" + RemoteNetMask; + + if ( iface.interfaceExist ( "ipsec0" ) ) + tmpInterface = "ipsec0"; + else + tmpInterface = iface.getDefaultInterface(); + + if ( GlobalConfig->currentProfile->getUseVirtualIP() ) + dev = QString ( dev + ":100" ); + else + dev = tmpInterface; + + QFile IpsecSetRouteScript ( IpsecRouteSetScript ); + QTextStream stream ( &IpsecSetRouteScript ); + if ( IpsecSetRouteScript.open ( IO_WriteOnly ) ) + { + stream << "#!"<< GlobalConfig->InterpreterShell << "\n"; + if ( GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + { + stream << GlobalConfig->pathToRoute << " del default" << "\n"; + + stream << GlobalConfig->pathToIp << " route add `cat " +tmpPath + "default-route." + GlobalConfig->currentProfile->getName() << "`" << "\n"; + } + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan ) + stream << GlobalConfig->pathToRoute << " del -net " << RemoteNet << " " << dev << "\n"; + IpsecSetRouteScript.close(); + + RouteProcess = new QProcess ( this ); + RouteProcess->addArgument ( GlobalConfig->InterpreterShell ); + RouteProcess->addArgument ( IpsecRouteSetScript ); + + connect ( RouteProcess, SIGNAL ( readyReadStdout () ), this, SLOT ( readFromStdout_route() ) ); + connect ( RouteProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_route() ) ); + + if ( !RouteProcess->start ( env ) ) + { + // KMessageBox::error( this, i18n( "\"%1\" start failed!" ).arg( "del route ("+IpsecType+")" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "del route (" + IpsecType + ")" ) , GlobalConfig->error ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "route (ipsec): route del started." ), GlobalConfig->debug ); + + while ( RouteProcess->isRunning() ) + { + usleep ( 500 ); + // parent->QApplication::processEvents(); + } + } + disconnect ( RouteProcess, SIGNAL ( readyReadStdout () ), this, SLOT ( readFromStdout_route() ) ); + disconnect ( RouteProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_route() ) ); + delete RouteProcess; + RouteProcess=0L; + } +} + +void KVpnc::removeIptablesFreeswan() +{ + // if ( DisconnectProcess->normalExit () ) + { + // disconnect( DisconnectProcess, SIGNAL( processExited () ), this, SLOT( removeIptablesFreeswan() ) ); + + putenv ( ( char* ) ( "LC_ALL=C" ) ); + DisconnectProcess = new QProcess ( this ); + DisconnectProcess->addArgument ( GlobalConfig->InterpreterShell ); + DisconnectProcess->addArgument ( tmpPath + "iptables." + GlobalConfig->currentProfile->getName() + ".remove_ipsec_freeswan.sh" ); + if ( !DisconnectProcess->start ( env ) ) + { + // KMessageBox::error( this, i18n( "\"%1\" start failed!" ).arg( "iptables." + GlobalConfig->currentProfile->getName() + ".remove_ipsec_freeswan.sh" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "iptables." + GlobalConfig->currentProfile->getName() + ".remove_ipsec_freeswan.sh" ), GlobalConfig->error ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( "iptables." + GlobalConfig->currentProfile->getName() + ".remove_ipsec_freeswan.sh" ), GlobalConfig->debug ); + while ( DisconnectProcess->isRunning() ) + { + usleep ( 500 ); + // parent->QApplication::processEvents(); + } + } + delete DisconnectProcess; + DisconnectProcess=0L; + } +} + +void KVpnc::doPingTest() +{ + /* + ping -c3 -I + */ + QString LocalIP; + QString Interface; + NetworkInterface iface ( GlobalConfig, parent ); + //LocalIP = iface.getInterfaceIP( iface.getDefaultInterface() ); + if ( GlobalConfig->currentProfile->getNetworkDevice().isEmpty() ) + Interface = iface.getInterfaceIP ( iface.getDefaultInterface() ); + else + Interface = GlobalConfig->currentProfile->getNetworkDevice(); + QString PingHostIP = GlobalConfig->currentProfile->getPingHostIP(); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Host for ping: %1" ).arg ( PingHostIP ), GlobalConfig->debug ); + + /* first: kick up the tunnel */ + putenv ( ( char* ) ( "LC_ALL=C" ) ); + PingProcess = new QProcess ( this ); + + QString PathToPing = ""; + ToolInfo *Tool; + for ( Tool = GlobalConfig->ToolList->first();Tool;Tool = GlobalConfig->ToolList->next() ) + { + if ( Tool->Name == "ping" ) + { + PathToPing = Tool->PathToExec; + break; + } + } + PingProcess->addArgument ( PathToPing ); + PingProcess->addArgument ( "-c1" ); + PingProcess->addArgument ( PingHostIP ); + + if ( !PingProcess->start ( env ) ) + { + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( "ping " + GlobalConfig->currentProfile->getPingHostIP() ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "ping " + GlobalConfig->currentProfile->getPingHostIP() ), GlobalConfig->error ); + } + else + { + //sleep( 3 ); + PingProcess->kill(); + /* second: real ping */ + PingProcess->clearArguments(); + PingProcess->addArgument ( PathToPing ); + PingProcess->addArgument ( "-c5" ); + PingProcess->addArgument ( "-v" ); + //PingProcess->addArgument( "-I" ); + //PingProcess->addArgument( Interface ); + PingProcess->addArgument ( PingHostIP ); + + connect ( PingProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_ping() ) ); + connect ( PingProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ping() ) ); + connect ( PingProcess, SIGNAL ( processExited() ), this, SLOT ( pingTestExited() ) ); + + pingtest = true; + + if ( !PingProcess->start ( env ) ) + { + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( "ping " + GlobalConfig->currentProfile->getPingHostIP() ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "ping " + GlobalConfig->currentProfile->getPingHostIP() ) , GlobalConfig->error ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( "ping" ), GlobalConfig->debug ); + //sleep(5); +// PingProcess->kill(); +// PingProcess->start(env); + while ( PingProcess->isRunning() ) + { + sleep ( 1 ); + } + disconnect ( PingProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_ping() ) ); + disconnect ( PingProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ping() ) ); + disconnect ( PingProcess, SIGNAL ( processExited() ), this, SLOT ( pingTestExited() ) ); + + } + } + delete PingProcess; + PingProcess=0L; +} + +void KVpnc::pingTestExited() +{ + disconnect ( PingProcess, SIGNAL ( processExited () ), this, SLOT ( pingTestExited() ) ); + // disconnect( PingProcess, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdout_ping() ) ); + // disconnect( PingProcess, SIGNAL( readyReadStderr() ), this, SLOT( readFromStderr_ping() ) ); + // pingtest = false; +} + +void KVpnc::vpncStarted() +{ + disconnect ( VpncProcess, SIGNAL ( processExited () ), this, SLOT ( vpncStarted() ) ); + + /* doing some after tunnel is up */ + + // VpncProcess->clearArguments(); + // VpncProcess->addArgument( GlobalConfig->InterpreterShell ); + // VpncProcess->addArgument( VpncConnectScript ); + // + // connect( VpncProcess, SIGNAL( readyReadStdout() ), this, SLOT( readOutputFrom_vpnc() ) ); + // + // if ( !VpncProcess->start(env) ) { + // KMessageBox::sorry( this, i18n( "\"%1\" start failed!" ).arg( "vpnc-connect" ) ); + // } else { + // GlobalConfig->appendLogEntry ( i18n( "\"%1\" started." ).arg("vpnc-connect"),GlobalConfig->info ); + // + // // connect( &timer, SIGNAL( timeout() ), this, SLOT( slotConnectTimedOut() ) ); + // // timer.start( tryConnectTimeout * 1000, FALSE ); + // // + // // mw->buttonConnect->setEnabled( false ); + // + // } +} + +void KVpnc::racoonStarted() +{ + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Policy was successful activated and daemon (%1) is running, starting up tunnel..." ).arg ( "racoon" ), GlobalConfig->debug ); + + bool AdminSockExist=false; + int tryCounter=0; + while ( !AdminSockExist && tryCounter < 20 ) + { + AdminSockExist=QFile ( "/var/run/racoon/racoon.sock" ).exists(); + tryCounter++; + if ( tryCounter ==20 ) + break; + else + { + tryCounter=0; + if ( GlobalConfig->KvpncDebugLevel > 8 ) + { + GlobalConfig->appendLogEntry ( i18n ( "Waiting admin sock of %1..." ).arg ( "racoon" ), GlobalConfig->debug ); + } + } + usleep ( 500 ); + GlobalConfig->appPointer->processEvents(); + } + + if ( tryCounter==20 ) + { + GlobalConfig->appendLogEntry ( i18n ( "Waiting admin sock of %1 needs too long. Stop." ).arg ( "racoon" ), GlobalConfig->debug ); + disconnectClicked(); + return; + } + + putenv ( ( char* ) ( "LC_ALL=C" ) ); + RacoonctlProcess = new QProcess ( this ); + QString PathToRacoonctl = ""; + ToolInfo* Tool = Utils ( GlobalConfig ).getToolInfo ( "racoonctl" ); + PathToRacoonctl = Tool->PathToExec; + + RacoonctlProcess->addArgument ( PathToRacoonctl ); + RacoonctlProcess->addArgument ( "vc" ); + + if ( GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) + { + RacoonctlProcess->addArgument ( "-u" ); + RacoonctlProcess->addArgument ( GlobalConfig->TmpUsername ); + } + + RacoonctlProcess->addArgument ( GlobalConfig->TmpGatewayIP ); + + connect ( RacoonctlProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_racoonctl() ) ); + connect ( RacoonctlProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_racoonctl() ) ); + connect ( RacoonctlProcess, SIGNAL ( processExited () ), this, SLOT ( racoonctlExited() ) ); + + + if ( !RacoonctlProcess->start ( env ) ) + if ( GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( QString ( "racoonctl vpn-connect -u "+GlobalConfig->TmpUsername+" "+GlobalConfig->TmpGatewayIP ) ) ); + else + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( QString ( "racoonctl vpn-connect "+GlobalConfig->TmpGatewayIP ) ) ); + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + { + if ( GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( QString ( "racoonctl vpn-connect -u "+GlobalConfig->TmpUsername+" "+GlobalConfig->TmpGatewayIP ) ), GlobalConfig->debug ); + else + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( QString ( "racoonctl vpn-connect "+GlobalConfig->TmpGatewayIP ) ), GlobalConfig->debug ); + } + + if ( GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) + { +// for (int waitforconnect=0;waitforconnect< 25;waitforconnect++) +// usleep(500); + +// sleep(10); + if ( GlobalConfig->VpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[racoonctl] " + i18n ( "User password requested, send it...\n" ), GlobalConfig->debug ); + + QString UserPassStr = ""; + //if ( !GlobalConfig->currentProfile->getSaveUserPassword() || AuthRetry ) + UserPassStr = GlobalConfig->TmpPassword; + //else + // UserPassStr = GlobalConfig->currentProfile->getUserPassword(); + + if ( GlobalConfig->KvpncDebugLevel > 8 ) + GlobalConfig->appendLogEntry ( "[racoonctl] " + i18n ( "User password: %1\n" ).arg ( UserPassStr ), GlobalConfig->debug ); + + RacoonctlProcess->writeToStdin ( UserPassStr ); + RacoonctlProcess->writeToStdin ( "\n" ); + } + + int tryCounter=0; + while ( RacoonctlProcess->isRunning() ) + { + if ( tryCounter ==20 ) + { + tryCounter=0; + if ( GlobalConfig->KvpncDebugLevel > 8 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" is still running waiting for terminate..." ).arg ( GlobalConfig->pathToRacoonctl ), GlobalConfig->debug ); + } + if (GlobalConfig->appPointer->hasPendingEvents()) + GlobalConfig->appPointer->processEvents(); + usleep ( 500 ); + } + disconnect ( RacoonctlProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_racoonctl() ) ); + disconnect ( RacoonctlProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_racoonctl() ) ); + disconnect ( RacoonctlProcess, SIGNAL ( processExited () ), this, SLOT ( racoonctlExited() ) ); + delete RacoonctlProcess; + RacoonctlProcess=0L; + } + + // else + // { + // // disconnectClicked(); + // } + // GlobalConfig->appendLogEntry( "[racoon] " + i18n( "Connection established." ), GlobalConfig->success ); + // + // sec = hour = min = 0; + // + // GlobalConfig->status = GlobalConfig->connected; + // + // connect( &durationTimer, SIGNAL( timeout() ), this, SLOT( slotDurationEvent() ) ); + // durationTimer.start( 1000, FALSE ); + // setGuiStatus( connected ); + // + // setFirewallAfterConnect(); + // if ( GlobalConfig->currentProfile->getExecuteCmdAfterConnect() ) + // executeCommandAfterConnect(); + // + // if ( GlobalConfig->currentProfile->getUseAdditionalNetworkRoutes() && !GlobalConfig->currentProfile->getAdditionalNetworkRoutes().isEmpty() ) + // addAdditionalNetworkRoutes(); + // + // if ( GlobalConfig->currentProfile->getUseConnectionStatusCheck() ) { + // startConnectionStatusCheck(); + // } +} + +void KVpnc::ipsecStarted() +{ + disconnect ( IpsecStartProcess, SIGNAL ( processExited () ), this, SLOT ( ipsecStarted() ) ); + disconnect ( IpsecStartProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_ipsec() ) ); + disconnect ( IpsecStartProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsec() ) ); + delete IpsecStartProcess; + IpsecStartProcess=0L; + +// ToolInfo *IpsecToolInfo = Utils ( GlobalConfig ).getToolInfo ( "ipsec" ) ; + +// if ( GlobalConfig->KvpncDebugLevel > 0 ) +// GlobalConfig->appendLogEntry ( "[ipsec] " + i18n ( "Starting connection \"%1\"..." ).arg ( GlobalConfig->currentProfile->getName() ) , GlobalConfig->debug ); + +// /* Kick up the connection */ +// IpsecProcess = new QProcess ( this ); +// // +// IpsecProcess->addArgument ( GlobalConfig->pathToIpsec ); +// IpsecProcess->addArgument ( "auto" ); +// // if ( GlobalConfig->enableFreeswanVerbose ) +// // IpsecProcess->addArgument( "--verbose" ); +// IpsecProcess->addArgument ( "--up" ); +// IpsecProcess->addArgument ( GlobalConfig->currentProfile->getName() ); +// +// +// connect ( IpsecStartProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStderr_ipsec() ) ); +// connect ( IpsecStartProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsec() ) ); +// // connect( IpsecStartProcess, SIGNAL( processExited () ), this, SLOT( doRouteFreeswan() ) ); +// +// if ( !IpsecStartProcess->start(env) ) +// { +// KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( "ipsec: connection" ) ); +// GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "ipsec: connection" ) , GlobalConfig->error ); +// // disconnectClicked(); +// } +// else +// { +// if ( GlobalConfig->KvpncDebugLevel > 2 ) +// GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( "ipsec: connection" ) , GlobalConfig->debug ); +// while (IpsecStartProcess->isRunning()) +// { +// sleep(1); +// } +// disconnect ( IpsecStartProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStderr_ipsec() ) ); +// disconnect ( IpsecStartProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsec() ) ); +// // disconnect( IpsecStartProcess, SIGNAL( processExited () ), this, SLOT( doRouteFreeswan() ) ); +// delete IpsecStartProcess; +// IpsecStartProcess=0L; +// } + + IpsecStatusCheck=true; + checkIpsecWhackStatus(); + IpsecStatusCheck=false; + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[ipsec] " + i18n ( "Starting \"%1\"..." ).arg ( GlobalConfig->pathToIpsec+" whack' --listen" ) , GlobalConfig->debug ); + + + connectCounter=0; + sleep ( 1 ); + putenv ( ( char* ) ( "LC_ALL=C" ) ); + IpsecWhackListenProcess = new QProcess ( this ); + IpsecWhackListenProcess->addArgument ( GlobalConfig->pathToIpsec ); + IpsecWhackListenProcess->addArgument ( "whack" ); + IpsecWhackListenProcess->addArgument ( "--listen" ); + + connect ( IpsecWhackListenProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_ipsecwhacklisten() ) ); + connect ( IpsecWhackListenProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsecwhacklisten() ) ); + + if ( !IpsecWhackListenProcess->start ( env ) ) + { + disconnect ( IpsecWhackListenProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_ipsecwhacklisten() ) ); + disconnect ( IpsecWhackListenProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsecwhacklisten() ) ); + delete IpsecWhackListenProcess; + IpsecWhackListenProcess=0L; + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( GlobalConfig->pathToIpsec+" whack' --listen" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( GlobalConfig->pathToIpsec+" whack' --listen" ) , GlobalConfig->error ); + disconnectClicked(); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( GlobalConfig->pathToIpsec+" whack --listen" ), GlobalConfig->debug ); + for (int i = 0 ; i < 12; i++) + { + usleep(250); + if (GlobalConfig->appPointer->hasPendingEvents()) + GlobalConfig->appPointer->processEvents(); + } + } +} + +void KVpnc::checkIpsecWhackStatus() +{ + + putenv ( ( char* ) ( "LC_ALL=C" ) ); + IpsecWhackStatusProcess = new QProcess ( this ); + IpsecWhackStatusProcess->addArgument ( GlobalConfig->pathToIpsec ); + IpsecWhackStatusProcess->addArgument ( "whack" ); + IpsecWhackStatusProcess->addArgument ( "--status" ); + + disconnect ( IpsecWhackStatusProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_ipsecwhackstatus() ) ); + disconnect ( IpsecWhackStatusProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsecwhackstatus() ) ); + connect ( IpsecWhackStatusProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_ipsecwhackstatus() ) ); + connect ( IpsecWhackStatusProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsecwhackstatus() ) ); + + connect ( IpsecWhackStatusProcess, SIGNAL ( processExited() ), this, SLOT ( IpsecWhackStatusProcessExited() ) ); + + if ( !IpsecWhackStatusProcess->start ( env ) ) + { + if ( IpsecStatusCheck == false && IpsecPhase2Up==false ) + { + disconnect ( IpsecWhackStatusProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_ipsecwhackstatus() ) ); + disconnect ( IpsecWhackStatusProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsecwhackstatus() ) ); + disconnect ( IpsecWhackStatusProcess, SIGNAL ( processExited() ), this, SLOT ( IpsecWhackStatusProcessExited() ) ); + delete IpsecWhackStatusProcess; + IpsecWhackStatusProcess=0L; + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( GlobalConfig->pathToIpsec+" whack' --status" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( GlobalConfig->pathToIpsec+" whack' --status" ) , GlobalConfig->error ); + disconnectClicked(); + } + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 5 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( GlobalConfig->pathToIpsec+" whack --status" ), GlobalConfig->debug ); + if ( IpsecStatusCheck == true && IpsecPhase2Up==false ) + { + if ( !timer.isActive() ) + { + disconnect ( &timer, SIGNAL ( timeout() ), this, SLOT ( slotConnectTimedOut() ) ); + connect ( &timer, SIGNAL ( timeout() ), this, SLOT ( slotConnectTimedOut() ) ); + // FIXME make connect timeout value in GUI available + timer.start ( 2000 * 1000, FALSE ); + } + if ( !IpsecWhackStatusTimer.isActive() ) + { + disconnect ( &IpsecWhackStatusTimer, SIGNAL ( timeout() ), this, SLOT ( checkIpsecWhackStatus() ) ); + connect ( &IpsecWhackStatusTimer, SIGNAL ( timeout() ), this, SLOT ( checkIpsecWhackStatus() ) ); + IpsecWhackStatusTimer.start ( 5 * 1000, FALSE ); + } + } + } +} + +void KVpnc::startStopIpsec ( bool stop, bool silent ) +{ + + ToolInfo *IpsecToolInfo = Utils ( GlobalConfig ).getToolInfo ( "ipsec" ) ; + + IpsecStartProcess = new QProcess ( this ); + + if ( IpsecToolInfo->Version.contains ( "Openswan" , false ) ) + { + if ( stop==false ) + { + IpsecStartProcess->addArgument ( GlobalConfig->pathToIpsec ); + IpsecStartProcess->addArgument ( "setup" ); + } + else + { + // ipsec setup stop does not cleanup right + IpsecStartProcess->addArgument ( "/etc/init.d/ipsec"); + } + } + else + { + IpsecStartProcess->addArgument ( GlobalConfig->pathToIpsec ); + } + + if ( stop==false ) + { + if ( silent==false || GlobalConfig->KvpncDebugLevel > 5 ) + { + if ( IpsecToolInfo->Version.contains ( "strongSwan", false ) /*&& ( (IpsecMajor >= 4 && IpsecMinor >= 2 && IpsecSubMinor >=2 ) || IpsecMajor > 4 )*/ ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[" + IpsecType + "] " + i18n ( "Starting %1..." ).arg ( "strongSwan" ), GlobalConfig->debug ); + } + + if ( IpsecToolInfo->Version.contains ( "Openswan" , false ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[" + IpsecType + "] " + i18n ( "Starting %1..." ).arg ( "Openswan" ), GlobalConfig->debug ); + } + } + + GlobalConfig->currentConnectRetry++; + IpsecStartProcess->addArgument ( "start" ); + } + else + { + if ( silent==false || GlobalConfig->KvpncDebugLevel > 5 ) + { + if ( IpsecToolInfo->Version.contains ( "strongSwan", false ) /*&& ( (IpsecMajor >= 4 && IpsecMinor >= 2 && IpsecSubMinor >=2 ) || IpsecMajor > 4 )*/ ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[" + IpsecType + "] " + i18n ( "Stopping %1..." ).arg ( "openswan" ), GlobalConfig->debug ); + } + + if ( IpsecToolInfo->Version.contains ( "Openswan" , false ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[" + IpsecType + "] " + i18n ( "Stopping %1..." ).arg ( "strongSwan" ), GlobalConfig->debug ); + } + } + IpsecStartProcess->addArgument ( "stop" ); + } + + if ( silent==false|| GlobalConfig->KvpncDebugLevel > 8 ) + { + connect ( IpsecStartProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_ipsec() ) ); + connect ( IpsecStartProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsec() ) ); + } + + IpsecStartingInProgress=true; + if ( !IpsecStartProcess->start ( env ) ) + { + if ( silent==false ) + { + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( "ipsec" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "ipsec" ) , GlobalConfig->error ); + } + // disconnectClicked(); + IpsecStartingInProgress=false; + } + else + { + if ( silent==false ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( "ipsec" ) , GlobalConfig->debug ); + } + int currentConnectCounter=0; + while ( currentConnectCounter < GlobalConfig->currentProfile->getMaxConnectTries() *1000 && IpsecStartProcess != 0 && IpsecStartProcess->isRunning() ) + { + if ( silent==false ) + { + if ( GlobalConfig->KvpncDebugLevel > 8 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" still running, waiting" ).arg ( "ipsec" ) , GlobalConfig->debug ); + } + currentConnectCounter++; + usleep ( 200 ); + if ( GlobalConfig->appPointer->hasPendingEvents () ) + GlobalConfig->appPointer->processEvents(); + + if ( currentConnectCounter > GlobalConfig->currentProfile->getMaxConnectTries() *1000 ) + { + if ( silent==false ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" still running but needs too long, stopping" ).arg ( "ipsec" ) , GlobalConfig->debug ); + disconnectClicked(); + IpsecStartingInProgress=false; + return; + } + + } + } + IpsecStartingInProgress=false; + if ( silent==false|| GlobalConfig->KvpncDebugLevel > 8 ) + { + disconnect ( IpsecStartProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_ipsec() ) ); + disconnect ( IpsecStartProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsec() ) ); + } + } +} + +void KVpnc::addIpsecConnection() +{ + + +} + +void KVpnc::start_ipsec_initiate() +{ + // strongswan after ipsec whack --listen + /* disconnect ( IpsecWhackProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_ipsecwhack() ) ); + disconnect ( IpsecWhackProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsecwhack() ) ); + delete(IpsecWhackProcess);*/ + + if ( IpsecGotError) + return; + sleep ( 4 ); + + putenv ( ( char* ) ( "LC_ALL=C" ) ); + IpsecWhackProcess = new QProcess ( this ); + IpsecWhackProcess->addArgument ( GlobalConfig->pathToIpsec ); + IpsecWhackProcess->addArgument ( "whack" ); + IpsecWhackProcess->addArgument ( "--name" ); + IpsecWhackProcess->addArgument ( GlobalConfig->currentProfile->getName() ); + IpsecWhackProcess->addArgument ( "--initiate" ); + connect ( IpsecWhackProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_ipsecwhack() ) ); + connect ( IpsecWhackProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsecwhack() ) ); + connect ( IpsecWhackProcess, SIGNAL ( exited() ), this, SLOT ( ipsecwhack_exited() ) ); + + if ( !IpsecWhackProcess->start ( env ) ) + { + disconnect ( IpsecWhackProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_ipsecwhack() ) ); + disconnect ( IpsecWhackProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsecwhack() ) ); + disconnect ( IpsecWhackProcess, SIGNAL ( exited() ), this, SLOT ( ipsecwhack_exited() ) ); + delete IpsecWhackProcess; + IpsecWhackProcess=0L; + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( GlobalConfig->pathToIpsec+" whack' --name "+GlobalConfig->currentProfile->getName() +" --initiate" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( GlobalConfig->pathToIpsec+" whack' --name "+GlobalConfig->currentProfile->getName() +" --initiate" ) , GlobalConfig->error ); + disconnectClicked(); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( GlobalConfig->pathToIpsec+" whack --name "+GlobalConfig->currentProfile->getName() +" --initiate" ), GlobalConfig->debug ); + + if (!IpsecGotError) + checkIpsecWhackStatus(); + } + + +} + +void KVpnc::ipsecPhase2Established() +{ + if ( IpsecPhase2Up ) + return; + else + { + timer.stop(); + IpsecWhackStatusTimer.stop(); + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + { + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan ) + { + GlobalConfig->appendLogEntry ( "[ipsec] " + i18n ( "IPSec phase 2 established." ), GlobalConfig->info ); + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { + GlobalConfig->appendLogEntry ( "[ipsec] " + i18n ( "Low level IPsec phase 2 established." ), GlobalConfig->info ); + } + } + + IpsecPhase2Up=true; + } + + doIptablesFreeswan(); + addRouteIpsec(); + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { + start_l2tpd(); + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan ) + { + sec = hour = min = 0; + + GlobalConfig->status = GlobalConfig->connected; + + disconnect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + connect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + durationTimer.start ( 1000, FALSE ); + setGuiStatus ( connected ); + + + setFirewallAfterConnect(); + if ( GlobalConfig->currentProfile->getExecuteCmdAfterConnect() ) + executeCommandAfterConnect(); + + if ( GlobalConfig->currentProfile->getUseAdditionalNetworkRoutes() && !GlobalConfig->currentProfile->getAdditionalNetworkRoutes().isEmpty() ) + addAdditionalNetworkRoutes(); + + if ( GlobalConfig->currentProfile->getUseConnectionStatusCheck() ) + { + startConnectionStatusCheck(); + } + } + +} + +void KVpnc::doAddRemoveVirtualIp(QString vaction) +{ + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "doAddRemoveVirtualIp() action: %1" ).arg ( vaction ), GlobalConfig->debug ); + + QString ActionPretty=i18n("Adding"); + if (vaction =="del") + ActionPretty=i18n("Removing"); + + if ( GlobalConfig->KvpncDebugLevel > 4 ) + GlobalConfig->appendLogEntry ( i18n ( "%1 virtual IP (%2) and special route..." ).arg(ActionPretty).arg(GlobalConfig->currentProfile->getLeftSourceIp()), GlobalConfig->debug ); + + // FIXME convert LeftSourceIp to Virtual IP + + QString tmpPath = locateLocal ( "data", "kvpnc/" ); + QString IpsecVirtualIpFilename = tmpPath+"do-"+vaction+"-"+GlobalConfig->currentProfile->getName()+".virtualip.sh"; + QFile virtualfile ( IpsecVirtualIpFilename ); + QTextStream stream ( &virtualfile ); + if ( virtualfile.open ( IO_WriteOnly ) ) + { + stream << "#!"<< GlobalConfig->InterpreterShell << "\n"; + stream << "# generated by kvpnc. Do not edit it." << "\n"; + stream << "# profile: " + GlobalConfig->currentProfile->getName() << "\n"; + stream << "" << "\n"; + + NetworkInterface iface ( GlobalConfig, parent ); + if ( GlobalConfig->currentProfile->getNetworkDevice() == "default" || GlobalConfig->currentProfile->getNetworkDevice() == "" ) + { + tmpInterface = iface.getDefaultInterface(); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Default interface: \"%1\"." ).arg ( tmpInterface ) , GlobalConfig->debug ); + LocalIP = iface.getInterfaceIP ( iface.getDefaultInterface() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "IP address of default interface: \"%1\"." ).arg ( LocalIP ) , GlobalConfig->debug ); + } + else + { + tmpInterface = GlobalConfig->currentProfile->getNetworkDevice(); + LocalIP = iface.getInterfaceIP ( GlobalConfig->currentProfile->getNetworkDevice() ); + } + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan) + { + // fix bad route from *swan + + if (vaction == "add") + stream << GlobalConfig->pathToIp << " route del " << GlobalConfig->currentProfile->getRemoteNetAddr() << "/" << GlobalConfig->currentProfile->getRemoteNetMask() << " src " << GlobalConfig->currentProfile->getLeftSourceIp() << " dev " << tmpInterface<< "\n"; + else + stream << GlobalConfig->pathToIp << " route add " << GlobalConfig->currentProfile->getRemoteNetAddr() << "/" << GlobalConfig->currentProfile->getRemoteNetMask() << " src " << GlobalConfig->currentProfile->getLeftSourceIp() << " dev " << tmpInterface<< "\n"; + } + + stream << GlobalConfig->pathToIp << " addr "+vaction+" " << GlobalConfig->currentProfile->getLeftSourceIp() << "/32 dev " << tmpInterface << "\n"; + stream << GlobalConfig->pathToIp << " route "+vaction+" " << GlobalConfig->currentProfile->getRemoteNetAddr() << "/" << GlobalConfig->currentProfile->getRemoteNetMask() << " via " << GlobalConfig->currentProfile->getLeftSourceIp() << " dev " << tmpInterface<< "\n"; + + + virtualfile.close(); + QProcess IpsecVirtualIpProcess; + IpsecVirtualIpProcess.addArgument ( GlobalConfig->InterpreterShell ); + IpsecVirtualIpProcess.addArgument ( IpsecVirtualIpFilename ); + + if ( !IpsecVirtualIpProcess.start ( env ) ) + { + KMessageBox::sorry ( this, i18n ( "\"%1\" (%2) start failed!" ).arg ( "VirtualIpScript" ).arg ( IpsecVirtualIpFilename )); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" (%2) started." ).arg ( "VirtualIpScript" ).arg ( IpsecVirtualIpFilename ) , GlobalConfig->debug ); + while ( IpsecVirtualIpProcess.isRunning() ) + { + if (GlobalConfig->appPointer->hasPendingEvents()) + GlobalConfig->appPointer->processEvents(); + usleep (250); + } + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" (%2) finished." ).arg ( "VirtualIpScript" ).arg ( IpsecVirtualIpFilename ) , GlobalConfig->debug ); + } + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "%1 file could not be written." ).arg("VirtualIpScript"), GlobalConfig->error ); + } + +} + +void KVpnc::pppdStarted() +{ +// disconnect ( PptpProcess, SIGNAL( processExited () ), this, SLOT( pppdStarted() ) ); +// disconnect ( pppdUpProcess, SIGNAL ( processExited () ), this, SLOT ( pppdStarted() ) ); + +// if ( GlobalConfig->KvpncDebugLevel > 0 ) +// GlobalConfig->appendLogEntry ( i18n ( "\"%1\" finished." ).arg ( "PppdUpScript" ), GlobalConfig->debug ); + +} + +void KVpnc::openvpnStarted() +{ + disconnect ( OpenvpnProcess, SIGNAL ( processExited () ), this, SLOT ( openvpnStarted() ) ); + +} + +void KVpnc::startStopOpenl2tp ( bool stop, bool silent ) +{ + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[openl2tp] " + i18n ( "Starting %1..." ).arg ( "/etc/init.d/openl2tpd" ) , GlobalConfig->debug ); + StartStopOpenl2tpProcess = new QProcess ( this ); + StartStopOpenl2tpProcess->addArgument ( "/etc/init.d/openl2tp" ); + + if ( stop==false ) + { + if ( silent==false || GlobalConfig->KvpncDebugLevel > 5 ) + { + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Starting %1..." ).arg ( "openl2tpd" ), GlobalConfig->debug ); + } + StartStopOpenl2tpProcess->addArgument ( "start" ); + GlobalConfig->currentConnectRetry++; + } + else + { + if ( silent==false || GlobalConfig->KvpncDebugLevel > 5 ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Stopping %1..." ).arg ( "openl2tp" ), GlobalConfig->debug ); + } + StartStopOpenl2tpProcess->addArgument ( "stop" ); + } + + if ( silent==false|| GlobalConfig->KvpncDebugLevel > 8 ) + { + connect ( StartStopOpenl2tpProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_startstopOpenl2tp() ) ); + connect ( StartStopOpenl2tpProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( rreadFromStderr_startstopOpenl2tp() ) ); + } + + IpsecStartingInProgress=true; + if ( !StartStopOpenl2tpProcess->start ( env ) ) + { + if ( silent==false ) + { + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( "ipsec" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "ipsec" ) , GlobalConfig->error ); + } + // disconnectClicked(); + StartStopOpenl2tpProcess->tryTerminate(); + usleep ( 500 ); + if ( StartStopOpenl2tpProcess->isRunning() ) + StartStopOpenl2tpProcess->kill(); + IpsecStartingInProgress=false; + } + else + { + if ( silent==false ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + { + if ( stop==false ) + { + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( "/etc/init.d/openl2tp start" ) , GlobalConfig->debug ); + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( "/etc/init.d/openl2tp stop" ) , GlobalConfig->debug ); + } + } + } + int currentConnectCounter=0; + while ( currentConnectCounter < GlobalConfig->currentProfile->getMaxConnectTries() *1000 && StartStopOpenl2tpProcess->isRunning() ) + { + if ( silent==false ) + { + if ( GlobalConfig->KvpncDebugLevel > 8 ) + { + if ( stop==false ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" still running, waiting" ).arg ( "/etc/init.d/openl2tp start" ) , GlobalConfig->debug ); + else + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" still running, waiting" ).arg ( "/etc/init.d/openl2tp stop" ) , GlobalConfig->debug ); + } + } + currentConnectCounter++; + usleep ( 200 ); + if ( GlobalConfig->appPointer->hasPendingEvents () ) + GlobalConfig->appPointer->processEvents(); + + if ( currentConnectCounter > GlobalConfig->currentProfile->getMaxConnectTries() *1000 ) + { + if ( silent==false ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + { + if ( stop==false ) + { + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" still running but needs too long, stopping" ).arg ( "/etc/init.d/openl2tp start" ) , GlobalConfig->debug ); + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" still running but needs too long, stopping" ).arg ( "/etc/init.d/openl2tp stop" ) , GlobalConfig->debug ); + } + } + disconnectClicked(); + return; + } + + } + } + } + delete StartStopOpenl2tpProcess; + StartStopOpenl2tpProcess=0L; + +} + +QString KVpnc::getX509CertificateID ( QString Cert, bool user ) +{ + issuerID = ""; + userID = ""; + + /* + issuer + openssl x509 -noout -issuer -in mykeys.pem + + user + openssl x509 -noout -subject -in mykeys.pem + */ + putenv ( ( char* ) ( "LC_ALL=C" ) ); + X509CertificateExtractProcess = new QProcess ( this ); + X509CertificateExtractProcess->addArgument ( GlobalConfig->pathToOpenssl ); + X509CertificateExtractProcess->addArgument ( "x509" ); + X509CertificateExtractProcess->addArgument ( "-noout" ); + if ( user ) + X509CertificateExtractProcess->addArgument ( "-subject" ); + else + X509CertificateExtractProcess->addArgument ( "-issuer" ); + + X509CertificateExtractProcess->addArgument ( "-in" ); + X509CertificateExtractProcess->addArgument ( Cert ); + + X509CertificateExtractUser = user; + + connect ( X509CertificateExtractProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_getX509CertificateID() ) ); + connect ( X509CertificateExtractProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_getX509CertificateID() ) ); + connect ( X509CertificateExtractProcess, SIGNAL ( processExited () ), this, SLOT ( openSSLEnded() ) ); + + if ( !X509CertificateExtractProcess->start ( env ) ) + { + disconnect ( X509CertificateExtractProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_getX509CertificateID() ) ); + disconnect ( X509CertificateExtractProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_getX509CertificateID() ) ); + disconnect ( X509CertificateExtractProcess, SIGNAL ( processExited () ), this, SLOT ( openSSLEnded() ) ); + delete X509CertificateExtractProcess; + X509CertificateExtractProcess=0L; + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( "openssl" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "openssl" ) , GlobalConfig->error ); + return ""; + } + else + { + //KMessageBox::information( this, i18n( "\"%1\" started." ).arg("openssl") ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( "openssl (getCertificate)" ), GlobalConfig->debug ); + X509CertificateExtractRunning = true; + + while ( X509CertificateExtractRunning ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Waiting for process end (getCertificate)." ), GlobalConfig->debug ); + parent->QApplication::processEvents(); + } + disconnect ( X509CertificateExtractProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_getX509CertificateID() ) ); + disconnect ( X509CertificateExtractProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_getX509CertificateID() ) ); + disconnect ( X509CertificateExtractProcess, SIGNAL ( processExited () ), this, SLOT ( openSSLEnded() ) ); + delete X509CertificateExtractProcess; + X509CertificateExtractProcess=0L; + if ( user ) + return userID; + else + return issuerID; + } + +} + +void KVpnc::readFromStdout_getX509CertificateID() +{ + QString ProcessMsg = ""; + if ( X509CertificateExtractProcess->canReadLineStdout() ) + ProcessMsg = X509CertificateExtractProcess->readLineStdout(); + if ( !ProcessMsg.isEmpty() ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "ID found: %1" ).arg ( ProcessMsg.section ( '=', 1 ) ), GlobalConfig->debug ); + if ( X509CertificateExtractUser ) + { + userID = ProcessMsg.section ( '=', 1 ); // subject = /C=DE... => /C=DE... + + while ( userID.left ( 1 ) == " " ) + userID = userID.right ( userID.length() - 1 ); + + } + else + { + issuerID = ProcessMsg.section ( '=', 1 ); // issuer= /C=DE... => /C=DE... + while ( issuerID.left ( 1 ) == " " ) + issuerID = issuerID.right ( issuerID.length() - 1 ); + } + } +} + +void KVpnc::readFromStderr_getX509CertificateID() +{ + QString ProcessMsg = QString ( X509CertificateExtractProcess->readStderr() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "getX509CertificateID() err: %1" ).arg ( ProcessMsg ), GlobalConfig->debug ); +} + +void KVpnc::openSSLEnded() +{ + X509CertificateExtractRunning = false; + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "OpenSSL finished.\n" ), GlobalConfig->debug ); + +} + +void KVpnc::importCertClicked() +{ + ImportCertificateDialog dlg ( this, i18n ( "Import certificate..." ).ascii(), GlobalConfig ); + //int result = + dlg.exec(); +} + +void KVpnc::manageCiscoCertClicked() +{ + ManageCiscoCert dlg ( this, i18n ( "Manage Cisco certificates..." ).ascii(), GlobalConfig ); + //int result = + dlg.exec(); +} + +void KVpnc::enrollCiscoCertClicked() +{ + QString ciscoCertMgr = GlobalConfig->pathToCiscoCertMgr; + if (!ciscoCertMgr.isEmpty() && QFile::exists(ciscoCertMgr)) + { + CiscoCertificateEnrollment dlg ( this, i18n ( "Enroll certificate..." ).ascii(), GlobalConfig ); + dlg.exec(); + } + else + { + KMessageBox::error(0, i18n("cisco_cert_mgr is missing.\nPlease install it and retry."), i18n("Missing tool")); + } +} + +void KVpnc::showProfileManagerClicked() +{ + showProfilesOnly=true; + slotSettings(); +} + +void KVpnc::executeCommandBeforeConnect() +{ + if ( GlobalConfig->currentProfile->getExecuteCmdBeforeConnect() && !GlobalConfig->currentProfile->getCommandBeforeConnect().isEmpty() ) + { + QStringList cmds = QStringList::split ( '\n',GlobalConfig->currentProfile->getCommandBeforeConnect() ); + + // write command after connect script + QString CmdBeforeConnectScript = tmpPath + "cmd_before_connect_script." + GlobalConfig->currentProfile->getName(); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "CmdBeforeConnectScript: " + CmdBeforeConnectScript + "\n", GlobalConfig->debug ); + QFile file ( CmdBeforeConnectScript ); + QTextStream stream ( &file ); + if ( file.open ( IO_WriteOnly ) ) + { + for ( QStringList::Iterator it = cmds.begin(); it != cmds.end(); ++it ) + stream << *it << " ; "; + file.close(); + + CmdBeforeConnectProcess = new QProcess ( this ); + CmdBeforeConnectProcess->addArgument ( GlobalConfig->InterpreterShell ); + CmdBeforeConnectProcess->addArgument ( CmdBeforeConnectScript ); + + connect ( CmdBeforeConnectProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_executeCommandBeforeConnect() ) ); + connect ( CmdBeforeConnectProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_executeCommandBeforeConnect() ) ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Executing command before connect:\n%1" ).arg ( cmds.join ( ";" ) ), GlobalConfig->debug ); + if ( !CmdBeforeConnectProcess->start ( env ) ) + { + KMessageBox::sorry ( this, i18n ( "\"%1\" start failed!" ).arg ( CmdBeforeConnectScript ) ); + disconnectClicked(); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( "CmdBeforeConnectScript" ), GlobalConfig->debug ); + while ( CmdBeforeConnectProcess->isRunning() ) + parent->QApplication::processEvents(); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" finished." ).arg ( "CmdBeforeConnectScript" ), GlobalConfig->debug ); + } + disconnect ( CmdBeforeConnectProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_executeCommandBeforeConnect() ) ); + disconnect ( CmdBeforeConnectProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_executeCommandBeforeConnect() ) ); + delete CmdBeforeConnectProcess; + CmdBeforeConnectProcess =0L; + } + else + { + // file could not written + } + } +} + +void KVpnc::executeCommandAfterConnect() +{ + if ( GlobalConfig->currentProfile->getExecuteCmdAfterConnect() && !GlobalConfig->currentProfile->getCommandAfterConnect().isEmpty() ) + { + QStringList cmds = QStringList::split ( '\n',GlobalConfig->currentProfile->getCommandAfterConnect() ); + + // write command after connect script + QString CmdAfterConnectScript = tmpPath + "cmd_after_connect_script." + GlobalConfig->currentProfile->getName(); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "CmdAfterConnectScript: " + CmdAfterConnectScript + "\n", GlobalConfig->debug ); + QFile file ( CmdAfterConnectScript ); + QTextStream stream ( &file ); + if ( file.open ( IO_WriteOnly ) ) + { + for ( QStringList::Iterator it = cmds.begin(); it != cmds.end(); ++it ) + stream << *it << " ; "; + + file.close(); + + CmdAfterConnectProcess = new QProcess ( this ); + CmdAfterConnectProcess->addArgument ( GlobalConfig->InterpreterShell ); + CmdAfterConnectProcess->addArgument ( CmdAfterConnectScript ); + + connect ( CmdAfterConnectProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_executeCommandAfterConnect() ) ); + connect ( CmdAfterConnectProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_executeCommandAfterConnect() ) ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Sleeping %1s before executing command after connect..." ).arg ( QString().setNum ( GlobalConfig->currentProfile->getCommandAfterConnectDelayTime() ) ), GlobalConfig->debug ); + sleep ( GlobalConfig->currentProfile->getCommandAfterConnectDelayTime() ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Executing command after connect:\n%1" ).arg ( cmds.join ( ";" ) ), GlobalConfig->debug ); + if ( !CmdAfterConnectProcess->start ( env ) ) + { + KMessageBox::sorry ( this, i18n ( "\"%1\" start failed!" ).arg ( CmdAfterConnectScript ) ); + disconnectClicked(); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( "CmdAfterConnectScript" ), GlobalConfig->debug ); + while ( CmdAfterConnectProcess->isRunning() ) + parent->QApplication::processEvents(); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" finished." ).arg ( "CmdAfterConnectScript" ), GlobalConfig->debug ); + } + disconnect ( CmdAfterConnectProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_executeCommandAfterConnect() ) ); + disconnect ( CmdAfterConnectProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_executeCommandAfterConnect() ) ); + delete CmdAfterConnectProcess; + CmdAfterConnectProcess=0L; + + } + else + { + // file could not written + } + + } +} + +void KVpnc::executeCommandBeforeDisconnect() +{ + if ( GlobalConfig->currentProfile->getExecuteCmdBeforeDisconnect() && !GlobalConfig->currentProfile->getCommandBeforeDisconnect().isEmpty() ) + { + QStringList cmds = QStringList::split ( '\n',GlobalConfig->currentProfile->getCommandBeforeDisconnect() ); + + // write command after connect script + QString CmdBeforeDisconnectScript = tmpPath + "cmd_before_disconnect_script." + GlobalConfig->currentProfile->getName(); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "CmdBeforeDisconnectScript: " + CmdBeforeDisconnectScript + "\n", GlobalConfig->debug ); + QFile file ( CmdBeforeDisconnectScript ); + QTextStream stream ( &file ); + if ( file.open ( IO_WriteOnly ) ) + { + for ( QStringList::Iterator it = cmds.begin(); it != cmds.end(); ++it ) + stream << *it << " ; "; + file.close(); + + CmdBeforeDisconnectProcess = new QProcess ( this ); + CmdBeforeDisconnectProcess->addArgument ( GlobalConfig->InterpreterShell ); + CmdBeforeDisconnectProcess->addArgument ( CmdBeforeDisconnectScript ); + + connect ( CmdBeforeDisconnectProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_executeCommandBeforeDisconnect() ) ); + connect ( CmdBeforeDisconnectProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_executeCommandBeforeDisconnect() ) ); + + if ( !CmdBeforeDisconnectProcess->start ( env ) ) + { + + KMessageBox::sorry ( this, i18n ( "\"%1\" start failed!" ).arg ( CmdBeforeDisconnectScript ) ); + disconnectClicked(); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( "CmdBeforeDisconnectScript" ) , GlobalConfig->debug ); + while ( CmdBeforeDisconnectProcess->isRunning() ) + { + usleep ( 500 ); + // parent->QApplication::processEvents(); + } + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" finished." ).arg ( "CmdBeforeDisconnectScript" ), GlobalConfig->debug ); + } + disconnect ( CmdBeforeDisconnectProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_executeCommandBeforeDisconnect() ) ); + disconnect ( CmdBeforeDisconnectProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_executeCommandBeforeDisconnect() ) ); + delete CmdBeforeDisconnectProcess; + CmdBeforeDisconnectProcess=0L; + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Executing command before disconnect:\n%1" ).arg ( cmds.join ( ";" ) ), GlobalConfig->debug ); + } + else + { + // file could not written + } + } +} + +void KVpnc::executeCommandAfterDisconnect() +{ + if ( GlobalConfig->currentProfile->getExecuteCmdAfterDisconnect() && !GlobalConfig->currentProfile->getCommandAfterDisconnect().isEmpty() ) + { + QStringList cmds = QStringList::split ( '\n',GlobalConfig->currentProfile->getCommandAfterDisconnect() ); + + // write command after connect script + QString CmdAfterDisconnectScript = tmpPath + "cmd_after_disconnect_script." + GlobalConfig->currentProfile->getName(); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "CmdAfterDisconnectScript: " + CmdAfterDisconnectScript + "\n", GlobalConfig->debug ); + QFile file ( CmdAfterDisconnectScript ); + QTextStream stream ( &file ); + if ( file.open ( IO_WriteOnly ) ) + { + for ( QStringList::Iterator it = cmds.begin(); it != cmds.end(); ++it ) + stream << *it << " ; "; + file.close(); + + CmdAfterDisconnectProcess = new QProcess ( this ); + CmdAfterDisconnectProcess->addArgument ( GlobalConfig->InterpreterShell ); + CmdAfterDisconnectProcess->addArgument ( CmdAfterDisconnectScript ); + + connect ( CmdAfterDisconnectProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_executeCommandAfterDisconnect() ) ); + connect ( CmdAfterDisconnectProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_executeCommandAfterDisconnect() ) ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Executing command after disconnect:\n%1" ).arg ( cmds.join ( ";" ) ), GlobalConfig->debug ); + if ( !CmdAfterDisconnectProcess->start ( env ) ) + { + KMessageBox::sorry ( this, i18n ( "\"%1\" start failed!" ).arg ( CmdAfterDisconnectScript ) ); + disconnectClicked(); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( "CmdAfterDisconnectScript" ), GlobalConfig->debug ); + while ( CmdAfterDisconnectProcess->isRunning() ) + { + usleep ( 500 ); + // parent->QApplication::processEvents(); + } + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" finished." ).arg ( "CmdAfterDisconnectScript" ), GlobalConfig->debug ); + } + disconnect ( CmdAfterDisconnectProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_executeCommandAfterDisconnect() ) ); + disconnect ( CmdAfterDisconnectProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_executeCommandAfterDisconnect() ) ); + delete CmdAfterDisconnectProcess; + CmdAfterDisconnectProcess=0L; + } + else + { + // file could not written + } + } +} + +void KVpnc::setFirewallAfterConnect() +{ + + // write firewall after connect script + QString SetFirewallAfterConnectScript = tmpPath + "firewall_after_connect_script." + GlobalConfig->currentProfile->getName(); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "setFirewallAfterConnectScript: " + SetFirewallAfterConnectScript + "\n", GlobalConfig->debug ); + QFile file ( SetFirewallAfterConnectScript ); + QTextStream stream ( &file ); + if ( file.open ( IO_WriteOnly ) ) + { + if ( GlobalConfig->currentProfile->getFixPathMtuDiscoveryProblem() && Utils ( GlobalConfig ).getToolInfo ( "iptables" )->found ) + { + // iptables --append FORWARD --protocol tcp --tcp-flags SYN,RST SYN --jump TCPMSS --clamp-mss-to-pmtu + // see http://pptpclient.sourceforge.net/howto-diagnosis.phtml#connections_freeze + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Insert rule for fixing path MTU discovery problem" ), GlobalConfig->debug ); + + stream << "\n"; + stream << GlobalConfig->pathToIptables << " --append FORWARD --protocol tcp --tcp-flags SYN,RST SYN --jump TCPMSS --clamp-mss-to-pmtu" << "\n"; + } + file.close(); + + SetFirewallAfterConnectProcess = new QProcess ( this ); + SetFirewallAfterConnectProcess->addArgument ( GlobalConfig->InterpreterShell ); + SetFirewallAfterConnectProcess->addArgument ( SetFirewallAfterConnectScript ); + + +// if ( GlobalConfig->KvpncDebugLevel > 2 ) +// { +// disconnect ( SetFirewallAfterConnectProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_setFirewallAfterConnect() ) ); +// disconnect ( SetFirewallAfterConnectProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_setFirewallAfterConnect() ) ); +// connect ( SetFirewallAfterConnectProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_setFirewallAfterConnect() ) ); +// connect ( SetFirewallAfterConnectProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_setFirewallAfterConnect() ) ); +// } + + +// if ( GlobalConfig->KvpncDebugLevel > 0 ) +// GlobalConfig->appendLogEntry ( i18n ( "Set firewall after connect:\n%1" ).arg ( cmd ), GlobalConfig->debug ); + if ( !SetFirewallAfterConnectProcess->start ( env ) ) + { + KMessageBox::sorry ( this, i18n ( "\"%1\" start failed!" ).arg ( SetFirewallAfterConnectScript ) ); +// disconnectClicked(); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( "SetFirewallAfterConnectScript" ), GlobalConfig->debug ); + while ( SetFirewallAfterConnectProcess != 0 && SetFirewallAfterConnectProcess->isRunning() ) + { + usleep ( 2500 ); + if (GlobalConfig->appPointer->hasPendingEvents()) + GlobalConfig->appPointer->processEvents(); + } + + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" finished." ).arg ( "SetFirewallAfterConnectScript" ), GlobalConfig->debug ); + } +// disconnect ( SetFirewallAfterConnectProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_setFirewallAfterConnect() ) ); +// disconnect ( SetFirewallAfterConnectProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_setFirewallAfterConnect() ) ); + delete SetFirewallAfterConnectProcess; + SetFirewallAfterConnectProcess=0L; + + } + else + { + // file could not written + } + +} + +void KVpnc::setFirewallBeforeDisconnect() +{ + // write firewall after connect script + QString SetFirewallBeforeDisconnect = tmpPath + "firewall_after_connect_script." + GlobalConfig->currentProfile->getName(); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "SetFirewallBeforeDisconnect: " + SetFirewallBeforeDisconnect + "\n", GlobalConfig->debug ); + QFile file ( SetFirewallBeforeDisconnect ); + QTextStream stream ( &file ); + if ( file.open ( IO_WriteOnly ) ) + { + // see http://pptpclient.sourceforge.net/howto-diagnosis.phtml#connections_freeze + if ( GlobalConfig->currentProfile->getFixPathMtuDiscoveryProblem() && Utils ( GlobalConfig ).getToolInfo ( "iptables" )->found ) + { + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Remove rule for fixing path MTU discovery problem" ), GlobalConfig->debug ); + + stream << "\n"; + stream << GlobalConfig->pathToIptables << " --delete FORWARD --protocol tcp --tcp-flags SYN,RST SYN --jump TCPMSS --clamp-mss-to-pmtu" << "\n"; + } + file.close(); + + SetFirewallBeforeDisconnectProcess = new QProcess ( this ); + SetFirewallBeforeDisconnectProcess->addArgument ( GlobalConfig->InterpreterShell ); + SetFirewallBeforeDisconnectProcess->addArgument ( SetFirewallBeforeDisconnect ); + + +// if ( GlobalConfig->KvpncDebugLevel > 2 ) +// { +// disconnect ( SetFirewallBeforeDisconnectProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_setFirewallBeforeDisconnect() ) ); +// disconnect ( SetFirewallBeforeDisconnectProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_setFirewallBeforeDisconnect() ) ); +// connect ( SetFirewallBeforeDisconnectProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_setFirewallBeforeDisconnect() ) ); +// connect ( SetFirewallBeforeDisconnectProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_setFirewallBeforeDisconnect() ) ); +// } + + +// if ( GlobalConfig->KvpncDebugLevel > 0 ) +// GlobalConfig->appendLogEntry ( i18n ( "Set firewall before disconnect:\n%1" ).arg ( cmd ), GlobalConfig->debug ); + if ( !SetFirewallBeforeDisconnectProcess->start ( env ) ) + { + KMessageBox::sorry ( this, i18n ( "\"%1\" start failed!" ).arg ( SetFirewallBeforeDisconnect ) ); +// disconnectClicked(); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( "setFirewallBeforeDisconnect" ), GlobalConfig->debug ); + while ( SetFirewallBeforeDisconnectProcess->isRunning() ) + { + sleep ( 1 ); + parent->QApplication::processEvents(); + } + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" finished." ).arg ( "setFirewallBeforeDisconnect" ), GlobalConfig->debug ); + } +// disconnect ( SetFirewallBeforeDisconnectProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_setFirewallBeforeDisconnect() ) ); +// disconnect ( SetFirewallBeforeDisconnectProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_setFirewallBeforeDisconnect() ) ); + delete SetFirewallBeforeDisconnectProcess; + SetFirewallBeforeDisconnectProcess=0L; + } + else + { + // file could not written + } + +} + +void KVpnc::doRoutePptp() +{ + /* + route add -net 192.168.1.0/24 eth0 + */ + putenv ( ( char* ) ( "LC_ALL=C" ) ); + RouteProcess = new QProcess ( this ); + RouteProcess->addArgument ( "/sbin/route" ); + RouteProcess->addArgument ( "add" ); + RouteProcess->addArgument ( "-net" ); + QString RemoteNetAddr = GlobalConfig->currentProfile->getRemoteNetAddr(); + QString RemoteNetMask = GlobalConfig->currentProfile->getRemoteNetMask(); + QString RemoteNet = RemoteNetAddr + "/" + RemoteNetMask; + RouteProcess->addArgument ( RemoteNet ); + QString dev; + + if ( !GlobalConfig->currentProfile->getNetworkDevice().isEmpty() ) + dev = GlobalConfig->currentProfile->getNetworkDevice(); + else + dev = "ppp0"; + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + { + NetworkInterface iface ( GlobalConfig, parent ); + QString defaultinterface = iface.getDefaultInterface(); + GlobalConfig->appendLogEntry ( i18n ( "Default interface %1" ).arg ( defaultinterface ), GlobalConfig->debug ); + } + + RouteProcess->addArgument ( dev ); + tmpInterface = dev; + + connect ( RouteProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_pptp() ) ); + connect ( RouteProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_pptp() ) ); + + if ( !RouteProcess->start ( env ) ) + { + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( "route" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "route" ) , GlobalConfig->error ); + disconnectClicked(); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "route: \"route add -net " + RemoteNet + " " + tmpInterface + "\"", GlobalConfig->debug ); + while ( RouteProcess->isRunning() ) + { + sleep ( 1 ); + } + } + disconnect ( RouteProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_pptp() ) ); + disconnect ( RouteProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_pptp() ) ); + delete RouteProcess; + RouteProcess=0L; +} + +void KVpnc::slotConnecting() +{ + setGuiStatus ( connecting ); +} + +void KVpnc::profileAddedOrDeleted() +{ + + + + if ( !GlobalConfig->AccountList->isEmpty() ) + { + this->DeleteSessionAction->setEnabled ( TRUE ); + // this->advancedSessionAction->setEnabled ( TRUE ); + this->SaveSessionAction->setEnabled ( TRUE ); + this->ImportSessionAction->setEnabled ( TRUE ); + + this->ConnectAction->setEnabled ( TRUE ); + mw->buttonConnect->setEnabled ( TRUE ); + + mw->SessionCombo->clear(); + QuickConnectMenu->clear(); + VpnAccountData *it; + for ( it = GlobalConfig->AccountList->first(); it; it = GlobalConfig->AccountList->next() ) + { + QuickConnectMenu->insertItem ( it->getName() ); + mw->SessionCombo->insertItem ( it->getName() ); + } + + // if ( !GlobalConfig->lastProfile.isEmpty() ) { + // mw->SessionCombo->setCurrentItem( 1 ); + if ( GlobalConfig->currentProfile != 0 ) + sessionToggled ( GlobalConfig->currentProfile->getName() ); + else + sessionToggled ( GlobalConfig->AccountList->first()->getName() ); + // } + + } + else + { + this->DeleteSessionAction->setEnabled ( FALSE ); + // this->advancedSessionAction->setEnabled ( FALSE ); + this->SaveSessionAction->setEnabled ( FALSE ); + this->ImportSessionAction->setEnabled ( TRUE ); + + this->ConnectAction->setEnabled ( FALSE ); + mw->buttonConnect->setEnabled ( FALSE ); + } + +} + +bool KVpnc::setVirtualIP() +{ + /* + if (GlobalConfig->currentProfile->getNetworkDevice().isEmpty() || GlobalConfig->currentProfile->getVirtualIP().isEmpty()){ + KMessageBox::error ( this, i18n( "Empty interface or empty virtual IP!" ), i18n( "Bad Value" ) ); + return false; + } + if (!Utils( GlobalConfig, parent ).isValidNetworkDevice(GlobalConfig->currentProfile->getNetworkDevice())){ + KMessageBox::error ( this, i18n( "Interface doesnt exits!" ), i18n( "No Interface" ) ); + return false; + } + + setVirtualIPSuccess=true; + SetVirtualIPProcess = new QProcess(this); + SetVirtualIPProcess->addArgument(GlobalConfig->pathToIfconfig); + SetVirtualIPProcess->addArgument(QString(NetworkDevice+":100")); + SetVirtualIPProcess->addArgument(GlobalConfig->currentProfile->getVirtualIP()); + connect( SetVirtualIPProcess, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdout_setVirtualIP() ) ); + connect( SetVirtualIPProcess, SIGNAL( readyReadStderr() ), this, SLOT( readFromStderr_setVirtualIP() ) ); + + if ( !SetVirtualIPProcess->start(env) ) + { + std::cerr << i18n("Unable to set virtual IP!") << std::endl; + return false; + } + else { + while (SetVirtualIPProcess->isRunning()) + { + sleep(1); + } + delete SetVirtualIPProcess; + SetVirtualIPProcess=0L; + return setVirtualIPSuccess; + } + */ + + + return false; +} + +void KVpnc::toggleDebugConsole() +{ + if ( !GlobalConfig->showDebugConsole ) + { + GlobalConfig->showDebugConsole = true; + DebugconsoleAction ->setChecked ( true ); + mw->DebugOutput->show(); + //resize( minimumSizeHint() ); + } + else + { + GlobalConfig->showDebugConsole = false; + DebugconsoleAction ->setChecked ( false ); + mw->DebugOutput->hide(); + // setMinimumSize(0,0); + // this->resize( minimumSizeHint() ); + } +} + +void KVpnc::addAdditionalNetworkRoutes() +{ + if ( GlobalConfig->currentProfile == 0 ) + return ; + + if ( !GlobalConfig->currentProfile->getAdditionalNetworkRoutes().isEmpty() ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Setting additional network routes..." ), GlobalConfig->debug ); + QStringList AdditionalNetworkRoutes = GlobalConfig->currentProfile->getAdditionalNetworkRoutes(); + + int count=1; + + QString dev = GlobalConfig->currentProfile->getNetworkDevice(); + + NetworkInterface iface ( GlobalConfig, parent ); + QString defaultinterface = iface.getDefaultInterface(); + + + if ( dev.isEmpty() ) + { + if ( defaultinterface.isEmpty() ) + dev = "lo"; + else + dev = defaultinterface; + } + if ( dev == "default" ) + dev = defaultinterface; + else + dev = "lo"; + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Default interface: %1" ).arg ( dev ), GlobalConfig->debug ); + + QString tmpPath = locateLocal ( "data", "kvpnc/" ); + QFile file ( tmpPath + "addAdditionalNetworkRoutes." + GlobalConfig->currentProfile->getName() + ".sh" ); + QString Route=""; + QStringList RoutesList; + QTextStream stream ( &file ); + if ( file.open ( IO_WriteOnly ) ) + { + stream << "#!"<< GlobalConfig->InterpreterShell << "\n"; + for ( QStringList::Iterator it = AdditionalNetworkRoutes.begin(); it != AdditionalNetworkRoutes.end();++it ) + { + Route += "\t"+QString().setNum ( count ) +": "; + count++; + QString net = ( *it ).section ( '#', 0, 0 ); + + QString Gateway = QString ( *it ).section ( '#', 1, 1 ); + QString GatewayString = ""; + QString Interface = QString ( *it ).section ( '#', 2, 2 ); + QString InterfaceString = ""; + bool extended = false; + Route += net; + if ( !Gateway.isEmpty() && Gateway != "-" ) + { + GatewayString += "gateway "; + GatewayString += Gateway; + Route += " " + i18n ( "over gateway" ) + " " + Gateway + "\n"; + extended = true; + } + if ( !Interface.isEmpty() && Interface != "-" ) + { + InterfaceString += Interface; + if ( Interface != "default" ) + dev = Interface; + Route += " " + i18n ( "over interface" ) + " " + dev + "\n"; + extended = true; + } + else + { + dev=defaultinterface; + Route += " " + i18n ( "over interface" ) + " " + dev + "\n"; + } + + RoutesList.append ( Route ); + Route=""; + + if ( net.find ( "/32" ) > 0 ) + stream << GlobalConfig->pathToRoute << " add " << net << " " << GatewayString << " " << dev << "\n"; + else + stream << GlobalConfig->pathToRoute << " add -net " << net << " " << GatewayString << " " << dev << "\n"; + + } + file.close(); + RouteProcess = new QProcess ( this ); + RouteProcess->addArgument ( GlobalConfig->InterpreterShell ); + RouteProcess->addArgument ( tmpPath + "addAdditionalNetworkRoutes." + GlobalConfig->currentProfile->getName() + ".sh" ); + tmpInterface = dev; + + connect ( RouteProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_route() ) ); + connect ( RouteProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_route() ) ); + + if ( !RouteProcess->start ( env ) ) + { + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( "route (addtitional network routes)" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "route (addtitional network routes)" ) , GlobalConfig->error ); + //disconnectClicked(); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + { + GlobalConfig->appendLogEntry ( i18n ( "Adding the following additional network routes:" ), GlobalConfig->debug ); + for ( QStringList::Iterator it = RoutesList.begin(); it != RoutesList.end(); ++it ) + GlobalConfig->appendLogEntry ( *it , GlobalConfig->debug ); + } + while ( RouteProcess->isRunning() ) + { + usleep ( 500 ); + // parent->processEvents(); + } + } + disconnect ( RouteProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_route() ) ); + disconnect ( RouteProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_route() ) ); + delete RouteProcess; + RouteProcess=0L; + } + } +} + +void KVpnc::removeAdditionalNetworkRoutes() +{ + if ( !GlobalConfig->currentProfile->getAdditionalNetworkRoutes().isEmpty() ) + { + QStringList AdditionalNetworkRoutes = GlobalConfig->currentProfile->getAdditionalNetworkRoutes(); + QString dev = GlobalConfig->currentProfile->getNetworkDevice(); + + NetworkInterface iface ( GlobalConfig, parent ); + QString defaultinterface = iface.getDefaultInterface(); + int count=1; + + if ( dev.isEmpty() ) + { + if ( defaultinterface.isEmpty() ) + dev = "lo"; + else + dev = defaultinterface; + } + if ( dev == "default" ) + dev = defaultinterface; + else + dev = "lo"; + + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Default interface: %1" ).arg ( defaultinterface ), GlobalConfig->debug ); + + tmpPath = locateLocal ( "data", "kvpnc/" ); + QFile file ( tmpPath + "delAdditionalNetworkRoutes." + GlobalConfig->currentProfile->getName() + ".sh" ); + QString Route=""; + QStringList RoutesList; + QTextStream stream ( &file ); + if ( file.open ( IO_WriteOnly ) ) + { + stream << "#!"<< GlobalConfig->InterpreterShell << "\n"; + for ( QStringList::Iterator it = AdditionalNetworkRoutes.begin(); it != AdditionalNetworkRoutes.end();++it ) + { + Route += "\t"+QString().setNum ( count ) +": "; + count++; + + QString net = ( *it ).section ( '#', 0, 0 ); + + QString Gateway = QString ( *it ).section ( '#', 1, 1 ); + QString GatewayString = ""; + QString Interface = QString ( *it ).section ( '#', 2, 2 ); + QString InterfaceString = ""; + bool extended = false; + Route += net; + if ( !Gateway.isEmpty() && Gateway != "-" ) + { + GatewayString += "gw "; + GatewayString += Gateway; + Route += " " + i18n ( "over gateway" ) + " " + Gateway + "\n"; + extended = true; + } + if ( !Interface.isEmpty() && Interface != "-" ) + { + InterfaceString += Interface; + if ( Interface != "default" ) + dev = Interface; + Route += " " + i18n ( "over interface" ) + " " + dev + "\n"; + extended = true; + } + else + { + Route += " "; + dev=defaultinterface; + Route += " " + i18n ( "over interface" ) + " " + dev + "\n"; + } + + RoutesList.append ( Route ); + Route=""; + + if ( net.find ( "/32" ) > 0 ) + stream << GlobalConfig->pathToRoute << " del " << net << " " << GatewayString << " " << dev << "\n"; + else + stream << GlobalConfig->pathToRoute << " del -net " << net << " " << GatewayString << " " << dev << "\n"; + + } + file.close(); + RouteProcess = new QProcess ( this ); + RouteProcess->addArgument ( GlobalConfig->InterpreterShell ); + RouteProcess->addArgument ( tmpPath + "delAdditionalNetworkRoutes." + GlobalConfig->currentProfile->getName() + ".sh" ); + tmpInterface = dev; + + if ( !RouteProcess->start ( env ) ) + { + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( "route (addtitional network routes)" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "route (addtitional network routes)" ) , GlobalConfig->error ); + //disconnectClicked(); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + { + GlobalConfig->appendLogEntry ( i18n ( "Removing the following additional network routes:" ), GlobalConfig->debug ); + for ( QStringList::Iterator it = RoutesList.begin(); it != RoutesList.end(); ++it ) + GlobalConfig->appendLogEntry ( *it , GlobalConfig->debug ); + } + while ( RouteProcess->isRunning() ) + { + usleep ( 500 ); + parent->processEvents(); + } + } + delete RouteProcess; + RouteProcess=0L; + } + } +} + +void KVpnc::showLogViewer() +{ + LogViewerDialog dlg ( this, parent , GlobalConfig, i18n ( "Log Viewer" ),150 ); + LogViewerAction->setChecked ( true ); + dlg.show(); + dlg.exec(); + LogViewerAction->setChecked ( false ); +} + +void KVpnc::doQuickConnect ( int id ) +{ + QString itemtext = QuickConnectMenu->text ( id ); + + if ( GlobalConfig->KvpncDebugLevel > 4 ) + GlobalConfig->appendLogEntry ( i18n ( "Quick connect to \"%1\" selected. Current profile: \"%2\"" ).arg ( itemtext ).arg ( GlobalConfig->currentProfile->getName() ), GlobalConfig->info ); + + if ( GlobalConfig->status == GlobalConfig->connected ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Connect to \"%1\" requested but still to \"%2\" connected, current connection will be terminated." ).arg ( GlobalConfig->currentProfile->getName() ).arg ( itemtext ), GlobalConfig->info ); + disconnectClicked(); + } + //KMessageBox::information(0,"item",QString("item: "+itemtext)); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Connect to \"%1\" requested." ).arg ( itemtext ), GlobalConfig->debug ); + + if ( itemtext != GlobalConfig->currentProfile->getName() ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Switching to %1" , QString ( itemtext ) ), GlobalConfig->debug ); + bool profileInList = false; + for ( uint i = 0; i < GlobalConfig->AccountList->count();i++ ) + { + if ( GlobalConfig->AccountList->at ( i ) ->getName() == itemtext ) + { + profileInList = true; + + sessionToggled ( itemtext ); + mw->SessionCombo->setCurrentText ( itemtext ); + GlobalConfig->currentProfile = GlobalConfig->AccountList->at ( i ); + connectClicked(); + break; + } + } + + } + else + { + connectClicked(); + } + +} + +void KVpnc::saveGuiOptions() +{ + GlobalConfig->config->setGroup ( "General Options" ); + GlobalConfig->config->writeEntry ( "Mainwindow width", width() ); + GlobalConfig->config->writeEntry ( "Mainwindow height", height() ); + GlobalConfig->config->writeEntry ( "Mainwindow position x", x() ); + GlobalConfig->config->writeEntry ( "Mainwindow position y", y() ); + toolBar ( "mainToolBar" ) ->saveSettings ( GlobalConfig->config, "ToolBar Settings" ); + GlobalConfig->config->sync(); +} + +void KVpnc::startConnectionStatusCheck() +{ + KStandardDirs * dirs = KGlobal::dirs(); + QString PingCheckScript = QString ( dirs->findResource ( "data", "kvpnc/ping_check.sh" ) ); + //GlobalConfig->appendLogEntry( QString("PingCheckScript : " +PingCheckScript), GlobalConfig->debug); + ConnectionStatusCheckProcess = new QProcess ( this ); + ConnectionStatusCheckProcess->addArgument ( GlobalConfig->InterpreterShell ); + ConnectionStatusCheckProcess->addArgument ( PingCheckScript ); + QString PathToPing = Utils ( GlobalConfig ).getToolInfo ( "ping" ) ->PathToExec; + + ConnectionStatusCheckProcess->addArgument ( PathToPing ); + + QString pingDevice="default"; + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::cisco ) + pingDevice = VpncDevice; + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ciscoorig ) + pingDevice = CiscoVpncDevice; + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::pptp ) + pingDevice = PppdDevice; + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon ) + pingDevice = "default"; + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan ) + pingDevice = "ipsec0"; + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::openvpn ) + pingDevice = OpenvpnDevice; + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) + pingDevice = L2tpPppDevice; + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + pingDevice = L2tpPppDevice; + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::vtun ) + pingDevice = ""; + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ssh ) + pingDevice = SshDevice; + + // fallback + if ( pingDevice.isEmpty() ) + pingDevice="default"; + + ConnectionStatusCheckProcess->addArgument ( pingDevice ); + if ( GlobalConfig->KvpncDebugLevel > 4 ) + GlobalConfig->appendLogEntry ( i18n ( "Use device %1 for connection status check." ).arg ( pingDevice ), GlobalConfig->debug ); + + if ( GlobalConfig->currentProfile->getDoPingIP() ) + { + ConnectionStatusCheckProcess->addArgument ( GlobalConfig->currentProfile->getPingHostIP() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Use userdefined hostname/IP address (%1) for connection status check." ).arg ( GlobalConfig->currentProfile->getPingHostIP() ), GlobalConfig->debug ); + } + else + { + ConnectionStatusCheckProcess->addArgument ( GlobalConfig->currentProfile->getGateway() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Use gateway address (%1) for connection status check." ).arg ( GlobalConfig->currentProfile->getGateway() ), GlobalConfig->debug ); + } + ConnectionStatusCheckProcess->addArgument ( QString().setNum ( GlobalConfig->currentProfile->getConnectionStatusInterval() ) ); + ConnectionStatusCheckProcess->addArgument ( QString().setNum ( GlobalConfig->currentProfile->getConnectionStatusCheckSuccessCount() ) ); + ConnectionStatusCheckProcess->addArgument ( QString().setNum ( 1 ) ); // verbosity + + connect ( ConnectionStatusCheckProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_connectionStatusCheck() ) ); + connect ( ConnectionStatusCheckProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_connectionStatusCheck() ) ); + + if ( !ConnectionStatusCheckProcess->start ( env ) ) + { + disconnect ( ConnectionStatusCheckProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_connectionStatusCheck() ) ); + disconnect ( ConnectionStatusCheckProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_connectionStatusCheck() ) ); + delete ConnectionStatusCheckProcess; + ConnectionStatusCheckProcess=0L; + //KMessageBox::sorry( this, i18n( "\"%1\" start failed!" ).arg( "ping_check.sh" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "ping_check.sh" ) , GlobalConfig->error ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( "ping_check.sh" ), GlobalConfig->debug ); + } + +} + +void KVpnc::generateOpenvpnKey() +{ + GenerateOpenvpnKeyDialog dlg ( GlobalConfig, this, i18n ( "Generate Key" ) ); + dlg.exec(); +} + +void KVpnc::preserveNetworkEnvironment() +{ + // TODO really needed? What must be also saved? + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Preserving network environment" ), KVpncConfig::debug ); + + // resolv.conf + QFile originalResolvConfFile ( "/etc/resolv.conf" ); + QString originalResolvConfFileContent = ""; + if ( originalResolvConfFile.open ( IO_ReadOnly ) ) + { + originalResolvConfFileContent = QString ( originalResolvConfFile.readAll() ); + originalResolvConfFile.close(); + } + + QFile backupOriginalResolvConfFile ( "/etc/resolv.conf.before.kvpnc" ); + QTextStream stream ( &backupOriginalResolvConfFile ); + if ( backupOriginalResolvConfFile.open ( IO_WriteOnly ) ) + { + stream << originalResolvConfFileContent; + backupOriginalResolvConfFile.close(); + } + + // defaultroute + QString tmpPath = locateLocal ( "data", "kvpnc/" ); + + QString GetRouteScript = tmpPath + "get_route.sh"; + + QString backupOriginalRoute = locateLocal ( "data", "kvpnc/" ); + backupOriginalRoute += "route_before_kvpnc"; + + QFile file ( GetRouteScript ); + stream.setDevice ( &file ); + if ( file.open ( IO_WriteOnly ) ) + { + stream << "# generated by kvpnc. Do not edit it." << "\n"; + stream << "\n"; + stream << GlobalConfig->pathToIp + " route show > " + backupOriginalRoute + "\n"; + file.close(); + } + + + QProcess *proc = new QProcess ( this ); + proc->addArgument ( GlobalConfig->InterpreterShell ); + proc->addArgument ( GetRouteScript ); + + + // connect( proc, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdout() ) ); + // connect( proc, SIGNAL( readyReadStderr() ), this, SLOT( readFromStderr() ) ); + // connect( proc, SIGNAL( processExited () ), this, SLOT( processHasFinished() ) ); + + if ( !proc->start ( env ) ) + { + GlobalConfig->appendLogEntry ( i18n ( "unable to start proc (%1)!" ).arg ( i18n ( "script for getting original route info" ) ), KVpncConfig::error ); + } + else + { + //std::cout << "getDefaultInterface() started." << std::endl; + while ( proc->isRunning() ) + { + parent->processEvents(); + } + // disconnect( proc, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdout() ) ); + // disconnect( proc, SIGNAL( readyReadStderr() ), this, SLOT( readFromStderr() ) ); + // disconnect( proc, SIGNAL( processExited () ), this, SLOT( processHasFinished() ) ); + delete proc; + proc=0L; + } + +} + +void KVpnc::restoreNetworkEnvironment() +{ + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Restoring network environment" ), KVpncConfig::debug ); + + // resolv.conf + QFile originalResolvConfFile ( "/etc/resolv.conf.before.kvpnc" ); + QString originalResolvConfFileContent = ""; + if ( originalResolvConfFile.open ( IO_ReadOnly ) ) + { + originalResolvConfFileContent = QString ( originalResolvConfFile.readAll() ); + if ( originalResolvConfFileContent.length() > 0 ) + { + originalResolvConfFile.close(); + QFile backupOriginalResolvConfFile ( "/etc/resolv.conf" ); + QTextStream stream ( &backupOriginalResolvConfFile ); + if ( backupOriginalResolvConfFile.open ( IO_WriteOnly ) ) + { + stream << originalResolvConfFileContent; + backupOriginalResolvConfFile.close(); + originalResolvConfFile.remove(); + } + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "Warning: %1 has size 0, dont restoring it." ).arg ( "/etc/resolv.conf" ), KVpncConfig::debug ); + } + } + + // default route + // TODO + QString backupOriginalRoute = locateLocal ( "data", "kvpnc/" ); + backupOriginalRoute += "route_before_kvpnc"; + QFile backupOriginalRouteFile ( backupOriginalRoute ); + + // FIXME make it in GlobalConfig + + if ( backupOriginalRouteFile.open ( IO_ReadOnly ) ) + { + QTextStream stream ( &backupOriginalRouteFile ) + ; + QString line; + while ( !stream.atEnd() ) + { + line = stream.readLine(); + if ( line.contains ( "default via", false ) ) // default via 192.168.0.5 dev eth0 + { + QString tmpPath = locateLocal ( "data", "kvpnc/" ); + QString RestoreDefaultrouteKvpncExitScript = tmpPath + "restore_defaultroute_kvpnc_exit.sh"; + + QFile file ( RestoreDefaultrouteKvpncExitScript ); + QTextStream stream ( &file ); + if ( file.open ( IO_WriteOnly ) ) + { + stream << "# generated by kvpnc. Do not edit it." << "\n"; + stream << GlobalConfig->pathToRoute + " del default > /dev/null 2>&1\n"; + stream << GlobalConfig->pathToIp + " route add " + line + "\n"; // ip route add default via 192.168.0.5 dev eth0 + file.close(); + } + + QProcess *proc = new QProcess ( this ); + proc->addArgument ( GlobalConfig->InterpreterShell ); + proc->addArgument ( RestoreDefaultrouteKvpncExitScript ); + + + // connect( proc, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdout() ) ); + // connect( proc, SIGNAL( readyReadStderr() ), this, SLOT( readFromStderr() ) ); + //connect( proc, SIGNAL( processExited () ), this, SLOT( processHasFinished() ) ); + + if ( !proc->start ( env ) ) + { + GlobalConfig->appendLogEntry ( i18n ( "unable to start proc (%1)!" ).arg ( i18n ( "script for restoring defaultroute on kvpnc exit" ) ), KVpncConfig::error ); + } + else + { + while ( proc->isRunning() ) + { + usleep ( 500 ); + // parent->processEvents(); + } + } + // disconnect( proc, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdout() ) ); + // disconnect( proc, SIGNAL( readyReadStderr() ), this, SLOT( readFromStderr() ) ); + //disconnect( proc, SIGNAL( processExited () ), this, SLOT( processHasFinished() ) ); + delete proc; + proc=0L; + break; + } + } + backupOriginalRouteFile.close(); + } +} + +bool KVpnc::backupResolvConf() +{ + bool success=true; + QString ResolvConfBackupProfile = tmpPath + "resolv.conf.before.kvpnc_" + GlobalConfig->currentProfile->getName(); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Backup file of %1: %1" ).arg ( "resolv.conf" ).arg ( ResolvConfBackupProfile ), GlobalConfig->debug ); + + QFile ResolvConfBackupProfileFile ( ResolvConfBackupProfile + ".sh" ); + QTextStream ResolvConfBackupProfileStream ( &ResolvConfBackupProfileFile ); + if ( ResolvConfBackupProfileFile.open ( IO_WriteOnly ) ) + { + ResolvConfBackupProfileStream << "# generated by kvpnc. Do not edit it." << "\n"; + ResolvConfBackupProfileStream << "\n"; + ResolvConfBackupProfileStream << "cat /etc/resolv.conf > " + ResolvConfBackupProfile + "\n"; + ResolvConfBackupProfileFile.close(); + QProcess ResolvConfBackupProfileProcess ( this ); + ResolvConfBackupProfileProcess.addArgument ( GlobalConfig->InterpreterShell ); + ResolvConfBackupProfileProcess.addArgument ( ResolvConfBackupProfile + ".sh" ); + if ( !ResolvConfBackupProfileProcess.start() ) + { + // if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Backup process of %1 could not be started." ).arg ( "resolv.conf" ), GlobalConfig->error ); + success=false; + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "%1 backup process started." ).arg ( "resolv.conf" ), GlobalConfig->debug ); + while ( ResolvConfBackupProfileProcess.isRunning() ) + { + sleep ( 1 ); + } + } + } + return success; +} + +bool KVpnc::restoreResolvConf() +{ + bool success=true; + QString ResolvConfBackupProfile = tmpPath + "resolv.conf.before.kvpnc_" + GlobalConfig->currentProfile->getName(); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Restore file of %1: %1" ).arg ( "resolv.conf" ).arg ( ResolvConfBackupProfile ), GlobalConfig->debug ); + + QFile ResolvConfRestoreProfileFile ( ResolvConfBackupProfile + ".sh" ); + QTextStream ResolvConfRestoreProfileStream ( &ResolvConfRestoreProfileFile ); + if ( ResolvConfRestoreProfileFile.open ( IO_WriteOnly ) ) + { + ResolvConfRestoreProfileStream << "# generated by kvpnc. Do not edit it." << "\n"; + ResolvConfRestoreProfileStream << "\n"; +// ResolvConfRestoreProfileStream << "chmod u+w /etc/resolv.conf" << "\n"; + ResolvConfRestoreProfileStream << "cat " + ResolvConfBackupProfile + " > /etc/resolv.conf\n"; + ResolvConfRestoreProfileFile.close(); + QProcess ResolvConfRestoreProfileProcess ( this ); + ResolvConfRestoreProfileProcess.addArgument ( GlobalConfig->InterpreterShell ); + ResolvConfRestoreProfileProcess.addArgument ( ResolvConfBackupProfile + ".sh" ); + if ( !ResolvConfRestoreProfileProcess.start() ) + { + // if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Restore process of %1 could not be started." ).arg ( "resolv.conf" ), GlobalConfig->error ); + success=false; + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Restore process of %1 started." ).arg ( "resolv.conf" ), GlobalConfig->debug ); + while ( ResolvConfRestoreProfileProcess.isRunning() ) + { + sleep ( 1 ); + } + } + } + + return success; +} + +void KVpnc::backupIpsecSystemConfig() +{ + // backup system files + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Backing up %1" ).arg ( "ipsec.conf, ipsec.secrets" ), GlobalConfig->debug ); + + + QString IpsecPrefix = "/etc"; // prefix where ipsec.conf and ipsec.secrets + // ipsec.conf + QFile originalIpsecConfFile ( "/etc/ipsec.conf" ); + QTextStream stream ( &originalIpsecConfFile ); + QString originalIpsecConfFileContent = ""; + if ( !originalIpsecConfFile.exists() ) + { + originalIpsecConfFile.setName ( "/etc/ipsec.d/ipsec.conf" ); + if ( originalIpsecConfFile.exists() ) + { + IpsecPrefix = "/etc/ipsec.d"; + } + else + { + originalIpsecConfFile.setName ( "/etc/ipsec/ipsec.conf" ); + if ( originalIpsecConfFile.exists() ) + { + IpsecPrefix = "/etc/ipsec"; + } + } + } + if ( originalIpsecConfFile.exists() ) + { + if ( originalIpsecConfFile.open ( IO_ReadOnly ) ) + { + originalIpsecConfFileContent = QString ( originalIpsecConfFile.readAll() ); + originalIpsecConfFile.close(); + } + stream.unsetDevice(); + } + QFile backupOriginalIpsecConfFile ( IpsecPrefix + "/ipsec.conf.before.kvpnc" ); + stream.setDevice ( &backupOriginalIpsecConfFile ); + if ( backupOriginalIpsecConfFile.open ( IO_WriteOnly ) ) + { + stream << originalIpsecConfFileContent; + backupOriginalIpsecConfFile.close(); + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "%1 could not opened. Stop." ).arg ( IpsecPrefix + "/ipsec.conf.before.kvpnc" ),GlobalConfig->error ); + setGuiStatus ( disconnected ); + return; + } + + stream.unsetDevice(); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "%1 found in %2, assuming %3 as prefix for %4." ).arg ( "ipsec.conf" ).arg ( IpsecPrefix ).arg ( IpsecPrefix ).arg ( IpsecType ), GlobalConfig->debug ); + + // ipsec.secret + QFile originalIpsecSecretFile ( IpsecPrefix + "/ipsec.secrets" ); + stream.setDevice ( &originalIpsecSecretFile ); + QString originalIpsecSecretFileContent = ""; + if ( originalIpsecSecretFile.open ( IO_ReadOnly ) ) + { + originalIpsecSecretFileContent = QString ( originalIpsecSecretFile.readAll() ); + originalIpsecSecretFile.close(); + } + QFile backupOriginalIpsecSecretFile ( IpsecPrefix + "/ipsec.secrets.before.kvpnc" ); + stream.setDevice ( &backupOriginalIpsecSecretFile ); + if ( backupOriginalIpsecSecretFile.open ( IO_WriteOnly ) ) + { + stream << originalIpsecSecretFileContent; + backupOriginalIpsecSecretFile.close(); + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "%1 could not opened. Stop." ).arg ( IpsecPrefix + "/ipsec.secrets.before.kvpnc" ),GlobalConfig->error ); + setGuiStatus ( disconnected ); + return; + } + stream.unsetDevice(); +} + +void KVpnc::backupDefaultRoute() +{ + OldDefaultroute = tmpPath + "default-route." + GlobalConfig->currentProfile->getName(); // default-route. + QString OldDefaultrouteFilePath = tmpPath + "backup_default-route." + GlobalConfig->currentProfile->getName() +".sh"; // default-route. + QFile BackupDefaultRouteFile ( OldDefaultrouteFilePath ); // warning: static + QTextStream stream2 ( &BackupDefaultRouteFile ); + if ( BackupDefaultRouteFile.open ( IO_WriteOnly ) ) + { + stream2 << " #!" << GlobalConfig->InterpreterShell << "\n"; + stream2 << GlobalConfig->pathToIp << " route show | grep default > " << OldDefaultroute << "\n"; + BackupDefaultRouteFile.close(); + + QProcess BackupDefaultRouteProcess ( this ); + BackupDefaultRouteProcess.addArgument ( GlobalConfig->InterpreterShell ); + BackupDefaultRouteProcess.addArgument ( OldDefaultrouteFilePath ); + + if ( !BackupDefaultRouteProcess.start() ) + { + KMessageBox::sorry ( this, i18n ( "\"%1\" start failed!" ).arg ( "backup default route process" ) ); + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( "backup default route process" ), GlobalConfig->error ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( "backup default route process" ), GlobalConfig->debug ); + + while ( BackupDefaultRouteProcess.isRunning() ) + { + sleep ( 1 ); + } + } + } + else + { + //KMessageBox::error ( this, i18n ( "Default route could not backuped!" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Default route could not backuped!" ), GlobalConfig->error ); + } +} + +void KVpnc::showNewProfileWizardClicked() +{ + NewProfileWizard wizard ( GlobalConfig ); + if ( wizard.exec() == QDialog::Accepted && wizard.newProfileCreated ) + { + + bool importOK = true; + if ( importOK ) + { + VpnAccountData * account = wizard.profileData; + // if (account->getUseConnectionStatusCheck()) + // KMessageBox::information ( this, "Use connection status check: true", "value" ); + // else + // KMessageBox::information ( this, "Use connection status check: false", "value" ); + + VpnAccountData * it; + bool nameOk = false; + bool ok = false; + QString newName = wizard.getName(); + while ( nameOk == false ) + { + for ( it = GlobalConfig->AccountList->first(); it; it = GlobalConfig->AccountList->next() ) + { + if ( it->getName() == account->getName() ) + { + //account->setName( QString( account->getName() + "_2" ) ); + // KMessageBox::information ( this, i18n( "Profile name exists!\n It will be renamed to \"%1\"." ).arg( account->getName() ), i18n( "Name exist, renamed" ) ); + KMessageBox::error ( this, i18n ( "Profile name exists!" ), i18n ( "Name Exists" ) ); + QString newName = KInputDialog::getText ( i18n ( "New Name" ), i18n ( "New name for profile:" ), QString ( account->getName() += "_2" ), &ok ); + if ( ok == false ) + { + KMessageBox::information ( 0, i18n ( "Import was canceled." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Import was canceled." ), GlobalConfig->info ); + slotStatusMsg ( i18n ( "Import was canceled." ), ID_FLASH_MSG ); + return ; + } + else + { + it = GlobalConfig->AccountList->first(); + account->setName ( newName ); + nameOk = true; + } + + } + if ( newName.isEmpty() ) + nameOk=false; + else + nameOk = true; + } + if ( newName.isEmpty() ) + nameOk=false; + else + nameOk = true; + } + + + GlobalConfig->AccountList->append ( account ); + mw->SessionCombo->clear(); + QuickConnectMenu->clear(); + + for ( uint i = 0; i < GlobalConfig->AccountList->count();i++ ) + { + QuickConnectMenu->insertItem ( GlobalConfig->AccountList->at ( i ) ->getName() ); + mw->SessionCombo->insertItem ( GlobalConfig->AccountList->at ( i ) ->getName() ); + if ( GlobalConfig->AccountList->at ( i ) ->getName() == account->getName() ) + { + GlobalConfig->currentProfile = GlobalConfig->AccountList->at ( i ); + if (GlobalConfig->prefDlgOpen && prefDlg) + { + // called from prefDlg + emit newProfileCreated (account->getName()); + } + } + } + + + mw->SessionCombo->setCurrentText ( account->getName() ); + setProfile ( account->getName() ); + + if ( !mw->SessionCombo->isEnabled() ) + mw->SessionCombo->setEnabled ( TRUE ); + + this->ConnectAction->setEnabled ( true ); + mw->SessionCombo->setCurrentText ( account->getName() ); + sessionToggled ( account->getName() ); + mw->SessionCombo->setCurrentText ( account->getName() ); + + GlobalConfig->saveOptions(); + // std::cout << "save done" << std::endl; + + + // showProfileManagerClicked(); + // std::cout << "show profilemanager" << std::endl; + + + mw->SessionCombo->setEnabled ( TRUE ); + DeleteSessionAction->setEnabled ( TRUE ); + SaveSessionAction->setEnabled ( TRUE ); + ImportSessionAction->setEnabled ( TRUE ); + ConnectAction->setEnabled ( TRUE ); + mw->buttonConnect->setEnabled ( TRUE ); + + slotStatusMsg ( i18n ( "Profile \"%1\" added." ).arg ( mw->SessionCombo->currentText() ), ID_FLASH_MSG ); + GlobalConfig->appendLogEntry ( i18n ( "Profile \"%1\" added." ).arg ( mw->SessionCombo->currentText() ) , GlobalConfig->info ); + GlobalConfig->saveOptions(); + saveGuiOptions(); + + if ( wizard.connectaftercreating ) + { + if ( wizard.daemonavailable ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Connecting to profile \"%1\" after creating it." ).arg ( mw->SessionCombo->currentText() ) , GlobalConfig->debug ); + connectClicked(); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Connecting to profile \"%1\" is requested but daemon is not available, skipping connecting." ).arg ( mw->SessionCombo->currentText() ) , GlobalConfig->debug ); + } + } + } + else + { + KMessageBox::information ( 0, i18n ( "Import was unsuccessful." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Import was unsuccessful." ), GlobalConfig->info ); + slotStatusMsg ( i18n ( "Import was unsuccessful." ), ID_FLASH_MSG ); + } + } + else + { + slotStatusMsg ( i18n ( "Creating new profile canceled." ), ID_FLASH_MSG ); + GlobalConfig->appendLogEntry ( i18n ( "Creating new profile canceled." ), GlobalConfig->info ); + } +} + +void KVpnc::exportOpenvpnProfileClicked() +{ + if ( !GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::openvpn ) + return ; + + QString filename = KFileDialog::getOpenFileName ( QString ( "." ), QString ( "*.ovpn" ), 0, i18n ( "Enter filename for export profile %1:" ).arg ( GlobalConfig->currentProfile->getName() ) ); + if ( !filename.isEmpty() ) + { + // write openvpn..conf + QFile openvpn_file ( filename ); + QTextStream openvpn_stream ( &openvpn_file ); + if ( openvpn_file.open ( IO_WriteOnly ) ) + { + openvpn_stream << "# generated by kvpnc" << "\n"; + openvpn_stream << "# profile: " + GlobalConfig->currentProfile->getName() << "\n\n"; + openvpn_stream << "# verbosity" << "\n"; + openvpn_stream << "verb " << GlobalConfig->OpenvpnDebugLevel << "\n\n"; + + QString certPath = "/etc/openvpn"; + if ( !GlobalConfig->currentProfile->getCertPath().isEmpty() ) + certPath = GlobalConfig->currentProfile->getCertPath(); + + openvpn_stream << "# change to prefix" << "\n"; + openvpn_stream << "cd " << certPath << "\n"; + + if ( GlobalConfig->currentProfile->getTunnelDeviceType() == "tun" ) + { + openvpn_stream << "# use tun device" << "\n"; + openvpn_stream << "dev tun" << "\n\n"; + } + else + { + openvpn_stream << "# use tap device" << "\n"; + openvpn_stream << "dev tap" << "\n\n"; + } + + // client mode + openvpn_stream << "# dont listen" << "\n"; + openvpn_stream << "nobind" << "\n\n"; + + if ( GlobalConfig->currentProfile->getDisableLzoCompression() == false ) + { + openvpn_stream << "# compression" << "\n"; + openvpn_stream << "comp-lzo" << "\n\n"; + } + openvpn_stream << "" << "\n"; + + openvpn_stream << "# try to resolve names infinite" << "\n"; + openvpn_stream << "resolv-retry infinite" << "\n\n"; + + // TODO make it dynamiclly + openvpn_stream << "" << "\n"; + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::cert ) + { + openvpn_stream << "# client cert" << "\n"; + openvpn_stream << "cert " << GlobalConfig->currentProfile->getX509Certificate() << "\n\n"; + openvpn_stream << "" << "\n"; + openvpn_stream << "# client private key" << "\n"; + if ( !GlobalConfig->currentProfile->getPskIsInFile() ) + openvpn_stream << "key " << GlobalConfig->currentProfile->getPrivateKey() << "\n\n"; + else + openvpn_stream << "key " << GlobalConfig->currentProfile->getPrivateKey() << "\n\n"; + openvpn_stream << "" << "\n"; + openvpn_stream << "# ca" << "\n"; + openvpn_stream << "ca " << GlobalConfig->currentProfile->getCaCertificate() << "\n\n"; + + openvpn_stream << "# client side" << "\n"; + openvpn_stream << "tls-client" << "\n\n"; + openvpn_stream << "pull" << "\n\n"; + openvpn_stream << "# diffie hellman parameters" << "\n"; + openvpn_stream << "dh dh1024.pem" << "\n\n"; + + } + else if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::psk ) + { + openvpn_stream << "# client psk" << "\n"; + if ( GlobalConfig->currentProfile->getPskIsInFile() ) + { + openvpn_stream << "secret " << GlobalConfig->currentProfile->getPreSharedKeyFile() << "\n\n"; + } + else + { + // write openvpn..secret + QFile openvpn_secretfile ( tmpPath + "openvpn." + GlobalConfig->currentProfile->getName() + ".secret" ); + QTextStream openvpn_secretstream ( &openvpn_secretfile ); + if ( openvpn_secretfile.open ( IO_WriteOnly ) ) + { + openvpn_secretstream << "# generated by kvpnc. Do not edit it." << "\n"; + openvpn_secretstream << "# profile: " + GlobalConfig->currentProfile->getName() << "\n\n"; + openvpn_secretstream << GlobalConfig->currentProfile->getPreSharedKey() << "\n\n"; + } + openvpn_secretfile.close(); + openvpn_stream << "secret " << tmpPath + "openvpn." + GlobalConfig->currentProfile->getName() + ".secret" << "\n\n"; + } + } + + if ( GlobalConfig->currentProfile->getUseUdp() ) + { + openvpn_stream << "\n"; + openvpn_stream << "# use udp" << "\n"; + openvpn_stream << "proto udp" << "\n\n"; + + if ( GlobalConfig->currentProfile->getUseMssfix() ) + { + openvpn_stream << "\n"; + openvpn_stream << "# userdefined packet size" << "\n"; + openvpn_stream << "mssfix " << GlobalConfig->currentProfile->getMssfix() << "\n\n"; + } + + if ( GlobalConfig->currentProfile->getUseFragment() ) + { + openvpn_stream << "\n"; + openvpn_stream << "# userdefined packet size for fragmentation" << "\n"; + openvpn_stream << "fragment " << GlobalConfig->currentProfile->getFragment() << "\n\n"; + } + } + else + { + openvpn_stream << "" << "\n"; + openvpn_stream << "# use tcp" << "\n"; + openvpn_stream << "proto tcp-client" << "\n\n"; + } + openvpn_stream << "" << "\n"; + openvpn_stream << "# remote side" << "\n"; + openvpn_stream << "remote " << GlobalConfig->currentProfile->getGateway() << "\n"; + if ( GlobalConfig->currentProfile->getUseRemotePort() ) + { + openvpn_stream << "\n" << "# port" << "\n" << GlobalConfig->currentProfile->getRemotePort(); + } + openvpn_stream << "\n\n"; + + if ( GlobalConfig->currentProfile->getUseVirtualIP() ) + { + openvpn_stream << "" << "\n"; + openvpn_stream << "# virtual ip addresses" << "\n"; + openvpn_stream << GlobalConfig->pathToIfconfig << " " << GlobalConfig->currentProfile->getLocalVirtualIP() << GlobalConfig->currentProfile->getRemoteVirtualIP() << "\n\n"; + + + QString RemoteNetAddr = GlobalConfig->currentProfile->getRemoteNetAddr(); + int RemoteNetMaskNum = GlobalConfig->currentProfile->getRemoteNetMask().toInt(); + QString RemoteNetMask = "255.255.255.0"; + if ( RemoteNetMaskNum == 24 ) + RemoteNetMask = "255.255.255.0"; + else if ( RemoteNetMaskNum == 25 ) + RemoteNetMask = "255.255.255.128"; + else if ( RemoteNetMaskNum == 26 ) + RemoteNetMask = "255.255.255.192"; + else if ( RemoteNetMaskNum == 27 ) + RemoteNetMask = "255.255.255.224"; + else if ( RemoteNetMaskNum == 28 ) + RemoteNetMask = "255.255.255.240"; + else if ( RemoteNetMaskNum == 29 ) + RemoteNetMask = "255.255.255.248"; + else if ( RemoteNetMaskNum == 30 ) + RemoteNetMask = "255.255.255.252"; + else if ( RemoteNetMaskNum == 31 ) + RemoteNetMask = "255.255.255.254"; + else if ( RemoteNetMaskNum == 32 ) + RemoteNetMask = "255.255.255.255"; + + openvpn_stream << "" << "\n"; + openvpn_stream << "# route to remote network" << "\n"; + openvpn_stream << "route " << RemoteNetAddr << " " << RemoteNetMask << "\n"; + } + //openvpn_stream << "" << "\n"; + //openvpn_stream << "# permissions" << "\n"; + // openvpn_stream << "user nobody" << "\n"; + // openvpn_stream << "group nogroup" << "\n"; + + openvpn_stream << "" << "\n"; + openvpn_stream << "# port" << "\n"; + if ( GlobalConfig->currentProfile->getUseUserdefinedPort() ) + openvpn_stream << "port " << GlobalConfig->currentProfile->getUserdefinedPort() << "\n\n"; + else + openvpn_stream << "port 1194" << "\n"; + + openvpn_stream << "" << "\n"; + openvpn_stream << "# don't re-read key files across SIGUSR1 or --ping-restart" << "\n"; + openvpn_stream << "persist-key" << "\n\n"; + + openvpn_stream << "" << "\n"; + openvpn_stream << "# don't close and reopen TUN/TAP device across SIGUSR1 or --ping-restart restarts" << "\n"; + openvpn_stream << "persist-tun" << "\n\n"; + + if ( GlobalConfig->currentProfile->getUseNsCertType() ) + { + openvpn_stream << "" << "\n"; + if ( GlobalConfig->currentProfile->getNsCertType() == "client" ) + { + openvpn_stream << "# Require that peer certificate was signed with an explicit nsCertType designation of \"client\"" << "\n"; + openvpn_stream << "ns-cert-type client" << "\n\n"; + } + else + { + openvpn_stream << "# Require that peer certificate was signed with an explicit nsCertType designation of \"server\"" << "\n"; + openvpn_stream << "ns-cert-type server" << "\n\n"; + } + } + + openvpn_stream << "# disable ping restart\n"; + openvpn_stream << "ping-restart 0\n"; + + + + // openvpn_stream << "# keep the connection alive" << "\n"; + + // // TODO make it dynamiclly + // openvpn_stream << "keepalive 10 60" << "\n\n"; + + // openvpn_stream << "# keepalive\n"; + // // openvpn_stream << "keepalive 10000\n"; + + + // openvpn_stream << "# What happen if auth fails\n"; + // // TODO made option for other types + // openvpn_stream << "auth-retry none\n\n"; + + // FIXME: can user auth only used in cert mode? + if ( GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) + { + openvpn_stream << "# we want to authenticate with username and password\n"; + openvpn_stream << "auth-user-pass\n\n"; + } + + if ( GlobalConfig->currentProfile->getUseUserdefiniedCipher() ) + { + openvpn_stream << "# Use a userdefined cipher\n"; + openvpn_stream << "cipher " << GlobalConfig->currentProfile->getUserdefiniedCipher() << "\n\n"; + } + + if ( GlobalConfig->currentProfile->getUseRedirectGateway() ) + { + openvpn_stream << "# Automatically execute routing commands to cause all outgoing IP traffic to be redirected over the VPN\n"; + openvpn_stream << "redirect-gateway\n\n"; + } + + if ( GlobalConfig->currentProfile->getUseTlsAuth() && !GlobalConfig->currentProfile->getTlsAuthFile().isEmpty() ) + { + openvpn_stream << "# Add an additional layer of HMAC authentication on top of the TLS control channel to protect against DoS attacks\n"; + QString direction=""; + if ( GlobalConfig->currentProfile->getAuthenticationDirection() != "none" ) + direction= GlobalConfig->currentProfile->getAuthenticationDirection(); + openvpn_stream << "tls-auth " << GlobalConfig->currentProfile->getTlsAuthFile() << " " << direction << "\n\n"; + + if ( GlobalConfig->currentProfile->getUseTlsRemoteHost() ) + { + openvpn_stream << "# Accept connections only from a host with X509 name or common name equal to host\n"; + openvpn_stream << "tls-remote " << GlobalConfig->currentProfile->getTlsRemoteHost() << "\n\n"; + } + + if ( GlobalConfig->currentProfile->getUseTlsRemoteHost() && GlobalConfig->currentProfile->getUseTlsAuth() ) + openvpn_stream << "tls-client" << "\n\n"; + + } + + if ( GlobalConfig->currentProfile->getUseHttpProxy() ) + { + openvpn_stream << "# Use a HTTP proxy\n"; + openvpn_stream << "http-proxy " << GlobalConfig->currentProfile->getHttpProxy() << " " << GlobalConfig->currentProfile->getHttpProxyPort() << "\n"; + openvpn_stream << "http-proxy-timeout " << GlobalConfig->currentProfile->getHttpProxyTimeout() << "\n\n"; + } + + //openvpn_stream << "up " << tmpPath << "openvpn." << GlobalConfig->currentProfile->getName() << ".up" << "\n"; + //openvpn_stream << "down " << tmpPath + "openvpn." << GlobalConfig->currentProfile->getName() << ".down" << "\n"; + } + openvpn_stream << "# end #\n"; + openvpn_file.close(); + KMessageBox::information ( 0, i18n ( "Export of profile %1 was sucessful." ).arg ( GlobalConfig->currentProfile->getName() ), i18n ( "Export successful" ) ); + } +} + +void KVpnc::pptpProcessExited() +{ +// GlobalConfig->appendLogEntry ( i18n ( "Connection has been terminated." ), GlobalConfig->info ); +// disconnectClicked(); + +// if (QFile("/sbin/resolvconf").exists() && QFile("/etc/init.d/resolvconf").exists()) +// { +// +// QFile downfile ( tmpPath + "pptpd." + GlobalConfig->currentProfile->getName() + ".down" ); +// QTextStream downstream ( &downfile ); +// if ( downfile.open ( IO_WriteOnly ) ) +// { +// downstream << "#!"<< GlobalConfig->InterpreterShell << "\n"; +// downstream << "# generated by kvpnc. Do not edit it." << "\n"; +// downstream << "# profile: " + GlobalConfig->currentProfile->getName() << "\n\n"; +// +// if (QFile("/sbin/resolvconf").exists() && QFile("/etc/init.d/resolvconf").exists()) +// downstream << "/etc/init.d/resolvconf start\n"; +// downfile.close(); +// +// QProcess *pppdDownProcess = new QProcess ( this ); +// pppdDownProcess->addArgument ( GlobalConfig->InterpreterShell ); +// pppdDownProcess->addArgument ( tmpPath + "pptpd." + GlobalConfig->currentProfile->getName() + ".down" ); +// +// if ( !pppdDownProcess->start(env) ) +// { +// KMessageBox::sorry ( this, i18n ( "\"%1\" start failed!" ).arg ( "PptpdDownScript" ) ); +// } +// else +// { +// +// } +// delete pppdDownProcess; +// pppdDownProcess=0L; +// } +// } +} + +void KVpnc::vtun_exited() +{ +// GlobalConfig->appendLogEntry(i18n("%1 has been exited.").arg("vtund"),GlobalConfig->error); +// sleep(2); +// if (GlobalConfig->status == GlobalConfig->connecting || GlobalConfig->connected) +// disconnectClicked(); +} + +void KVpnc::openvpn_exited() +{ + disconnect ( OpenvpnProcess, SIGNAL ( processExited() ), this, SLOT ( openvpn_exited() ) ); +} + +void KVpnc::sshExited() +{ + +} + +void KVpnc::ipsecwhack_exited() +{ + disconnect ( IpsecWhackProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_ipsecwhack() ) ); + disconnect ( IpsecWhackProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsecwhack() ) ); + delete ( IpsecWhackProcess ); +} + +void KVpnc::IpsecWhackStatusProcessExited() +{ +// disconnect ( IpsecWhackStatusProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_ipsecwhackstatus() ) ); +// disconnect ( IpsecWhackStatusProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_ipsecwhackstatus() ) ); +// disconnect ( IpsecWhackStatusProcess, SIGNAL ( processExited() ), this, SLOT ( IpsecWhackStatusProcessExited() ) ); +// delete(IpsecWhackStatusProcess); +// IpsecWhackStatusProcess=0; +} + +void KVpnc::racoonctlExited() +{ +// disconnect( RacoonctlProcess, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdout_racoonctl() ) ); +// disconnect( RacoonctlProcess, SIGNAL( readyReadStderr() ), this, SLOT( readFromStderr_racoonctl() ) ); +// disconnect ( RacoonctlProcess, SIGNAL ( processExited () ), this, SLOT ( racoonctlExited() ) ); +} + +void KVpnc::prepareL2tpd() +{ + + if ( GlobalConfig->currentProfile->getL2tpDaemon() == VpnAccountData::l2tpd ) + { + // bug in openswan: only 80 chars in line allowed!!! + int pppdoptionsfilepathlen = QString ( "pppoptfile = "+tmpPath + "options." + GlobalConfig->currentProfile->getName() + ".l2tpd" ).length(); + if ( pppdoptionsfilepathlen > 80 ) + { + KMessageBox::error ( this, i18n ( "The line length for pppoptfile is too longer than 80 chars: %1. Openswan has an bug and cant handle that. Please rename profile to a shorter name." ).arg ( QString().setNum ( pppdoptionsfilepathlen ) ) ); + GlobalConfig->appendLogEntry ( i18n ( "The line length for pppoptfile is too longer than 80 chars: %1. Openswan has an bug and cant handle that. Please rename profile to a shorter name." ).arg ( QString().setNum ( pppdoptionsfilepathlen ) ), GlobalConfig->error ); + stopContinue = true; + return; + } + + NetworkInterface iface ( GlobalConfig, parent ); + if ( GlobalConfig->currentProfile->getNetworkDevice() == "default" || GlobalConfig->currentProfile->getNetworkDevice() == "" ) + { + tmpInterface = iface.getDefaultInterface(); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Default interface: \"%1\"." ).arg ( tmpInterface ) , GlobalConfig->debug ); + LocalIP = iface.getInterfaceIP ( iface.getDefaultInterface() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "IP address of default interface: \"%1\"." ).arg ( LocalIP ) , GlobalConfig->debug ); + } + else + { + tmpInterface = GlobalConfig->currentProfile->getNetworkDevice(); + LocalIP = iface.getInterfaceIP ( GlobalConfig->currentProfile->getNetworkDevice() ); + } + + // write l2tpd.conf + QFile L2tpdConfigFile ( tmpPath + "l2tpd." + GlobalConfig->currentProfile->getName() + ".conf" ); + QTextStream stream ( &L2tpdConfigFile ); + if ( L2tpdConfigFile.open ( IO_WriteOnly ) ) + { + stream << "[global]" << "\n"; + + // if ( !LocalIP.isEmpty() ) + stream << "listen-addr = " << LocalIP << "\n"; + // else + // stream << "listen-addr = 127.0.0.1" <<"\n"; + // stream << "listen-addr = 0.0.0.0" <<"\n"; + + stream << "port = 1701" << "\n"; + + + if ( !GlobalConfig->pathToXl2tpd.isEmpty() && QFile ( GlobalConfig->pathToXl2tpd ).exists() ) + { + if ( GlobalConfig->enableDebugXl2tpdNetwork ) + stream << "debug network = yes" << "\n"; + if ( GlobalConfig->enableDebugXl2tpdpacket ) + stream << "debug packet = yes" << "\n"; + if ( GlobalConfig->enableDebugXl2tpdstate ) + stream << "debug state = yes" << "\n"; + if ( GlobalConfig->enableDebugXl2tpdtunnel ) + stream << "debug tunnel = yes" << "\n"; + } + + + stream << "[lac " << GlobalConfig->currentProfile->getName() << "]" << "\n"; + stream << "lns = " << GlobalConfig->currentProfile->getGateway() << "\n"; + stream << "redial = yes" << "\n"; + stream << "redial timeout = 20" << "\n"; + stream << "max redials = 15" << "\n"; + // stream << "hidden bit = yes" << "\n"; + stream << "length bit = yes" << "\n"; + + // dont need to let authenticate the peer + stream << "require authentication = no" << "\n"; + + if ( GlobalConfig->currentProfile->getAuthMethod() == "chap" || GlobalConfig->currentProfile->getAuthMethod() == "mschap" || GlobalConfig->currentProfile->getAuthMethod() == "mschap-v2" ) + { + stream << "require chap = yes" << "\n"; + stream << "refuse pap = yes" << "\n"; + } + if ( GlobalConfig->currentProfile->getAuthMethod() == "pap" ) + { + stream << "refuse chap = yes" << "\n"; + stream << "require pap = yes" << "\n"; + } + + QString UsernameStr=""; + if ( !GlobalConfig->currentProfile->getUserName().isEmpty() ) + UsernameStr = GlobalConfig->currentProfile->getUserName(); + + if ( UsernameStr.isEmpty() && !GlobalConfig->TmpUsername ) + UsernameStr = GlobalConfig->TmpUsername; + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Username: %1" ).arg ( UsernameStr ), GlobalConfig->debug ); + + + + stream << "name = " << UsernameStr << "\n"; + stream << "pppoptfile = " << tmpPath + "options." + GlobalConfig->currentProfile->getName() + ".l2tpd" << "\n"; + stream << "ppp debug = yes" << "\n"; + stream << "autodial = yes" << "\n"; + L2tpdConfigFile.close(); + + L2tpdProcess = 0L; + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "Creating of %1 failed!" ).arg ( "l2tpd config file" ), GlobalConfig->error ); + stopContinue = true; + } + + + // write options.l2tpd + QFile L2tpdPppdOptionsFile ( tmpPath + "options." + GlobalConfig->currentProfile->getName() + ".l2tpd" ); + stream.setDevice ( &L2tpdPppdOptionsFile ); + if ( L2tpdPppdOptionsFile.open ( IO_WriteOnly ) ) + { + stream << "noauth" << "\n"; + stream << "user " << GlobalConfig->currentProfile->getUserName() << "\n"; + stream << "ipcp-accept-local" << "\n"; + stream << "ipcp-accept-remote" << "\n"; + // stream << "crtscts" << "\n"; + stream << "idle 180" << "\n"; + stream << "lock" << "\n"; + // stream << "proxyarp" << "\n"; + // stream << "connect-delay 5000" << "\n"; + // stream << "persist" << "\n"; + // stream << "hide-password" << "\n"; + // if (!GlobalConfig->currentProfile->getUseDnsServer()) + // stream << "usepeerdns" << "\n"; + // stream << "asyncmap 0" << "\n"; + // stream << "crtscts" << "\n"; + // stream << "lock" << "\n"; + // stream << "lcp-echo-interval 10" << "\n"; + // stream << "lcp-echo-failure 3" << "\n"; + // stream << "noipx" << "\n"; + + stream << "linkname kvpnc." << GlobalConfig->currentProfile->getName() << "\n"; + // FIXME how i can get safe the right interface name otherway? + + + if ( GlobalConfig->PppdDebugLevel ) + stream << "debug" << "\n"; + // // stream << "kdebug 1" << "\n"; + + Utils::PppdCapabilities pppdcap = Utils ( GlobalConfig ).checkPppdCapabilities(); + pppdHasReplacedefaultrouteSupport = pppdcap.pppdHasReplacedefaultrouteSupport; + + + if ( GlobalConfig->currentProfile->getAuthMethod() == "chap" ) + { + stream << "# use chap" << "\n"; + stream << pppdcap.RequireAuthChapOption << "\n"; + } + + if ( GlobalConfig->currentProfile->getAuthMethod() == "mschap" ) + { + stream << "# use mschap" << "\n"; + stream << pppdcap.RequireAuthMschapOption << "\n"; + } + + if ( GlobalConfig->currentProfile->getAuthMethod() == "mschap-v2" ) + { + stream << "# use mschap-v2" << "\n"; + stream << pppdcap.RequireAuthMschapv2Option << "\n"; + } + + if ( GlobalConfig->currentProfile->getAuthMethod() == "pap" ) + { + stream << "# use pap" << "\n"; + stream << pppdcap.RequireAuthPapOption << "\n"; + } + + QString deamon=""; + if ( !GlobalConfig->pathToXl2tpd.isEmpty() && QFile ( GlobalConfig->pathToXl2tpd ).exists() ) + { + if ( GlobalConfig->enableDebugPppd ) + stream << "debug" << "\n"; + } + else + { + if ( GlobalConfig->enableDebugPppd ) + stream << "debug" << "\n"; + } + + if ( !GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + { + stream << "# dont set defaultroute\n"; + stream << "nodefaultroute"; + stream << "\n"; + } + else + { + if ( GlobalConfig->currentProfile->getReplaceDefaultRoute() ) + { + stream << "# set defaultroute\n"; + stream << "defaultroute\n"; + if ( pppdcap.pppdHasReplacedefaultrouteSupport ) + stream << "replacedefaultroute\n"; + } + stream << "\n"; + } + + if ( GlobalConfig->currentProfile->getUseMtu() ) + { + stream << "mtu " << GlobalConfig->currentProfile->getMtu() << "\n"; + } + if ( GlobalConfig->currentProfile->getUseMru() ) + { + + stream << "mru " << GlobalConfig->currentProfile->getMru() << "\n"; + } + + stream << "connect-delay 5000" << "\n"; + + + + L2tpdPppdOptionsFile.close(); + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "Creating of %1 failed!" ).arg ( i18n ( "l2tpd options file for pppd" ) ), GlobalConfig->error ); + stopContinue = true; + } + +// // write l2tp secrets file +// QString L2tpSecrets = tmpPath + "l2tp-secrets." + GlobalConfig->currentProfile->getName(); +// +// if ( GlobalConfig->KvpncDebugLevel > 0 ) +// GlobalConfig->appendLogEntry ( i18n ( "l2tp secrets file: %1" ).arg ( tmpPath + "l2tp-secrets." + GlobalConfig->currentProfile->getName() ), GlobalConfig->debug ); +// QFile L2tpdSecretsFile ( L2tpSecrets ); +// stream.setDevice ( &L2tpdSecretsFile ); +// if ( L2tpdSecretsFile.open ( IO_WriteOnly | IO_WriteOnly ) ) +// { +// stream << "# +++ generated by kvpnc. Do not edit it." << "\n"; +// stream << "# profile: " + GlobalConfig->currentProfile->getName() << "\n"; +// +// if ( GlobalConfig->currentProfile->getSaveUserPassword() ) +// GlobalConfig->TmpPassword = GlobalConfig->currentProfile->getUserPassword(); +// +// QString UsernameStr; +// if ( !GlobalConfig->currentProfile->getDontSaveUsername() ) +// UsernameStr = GlobalConfig->currentProfile->getUserName(); +// else +// UsernameStr = GlobalConfig->TmpUsername; +// +// if (GlobalConfig->TmpUsername.isEmpty() && !GlobalConfig->currentProfile->getUserName().isEmpty() ) +// GlobalConfig->TmpUsername = GlobalConfig->currentProfile->getUserName(); +// +// +// if (GlobalConfig->KvpncDebugLevel > 1) +// GlobalConfig->appendLogEntry ( i18n ( "Username: %1" ).arg ( GlobalConfig->TmpUsername.isEmpty() ), GlobalConfig->debug ); +// +// stream << "* " << GlobalConfig->currentProfile->getGateway() + " \"" << GlobalConfig->TmpPassword << "\" *\n"; +// stream << GlobalConfig->currentProfile->getGateway() << " \"" << GlobalConfig->TmpPassword << "\" *\n"; +// +// stream << "# --- generated by kvpnc. Do not edit it." << "\n"; +// L2tpdSecretsFile.close(); +// Utils ( GlobalConfig, this ).doChmod ( L2tpdSecretsFile.name(), "go-rwx" ); +// +// } +// else +// { +// GlobalConfig->appendLogEntry ( i18n ( "Creating of %1 failed!" ).arg ( "l2tpd secrets file" ), GlobalConfig->error ); +// stopContinue = true; +// } + + if ( GlobalConfig->currentProfile->getAuthMethod() == "chap" || GlobalConfig->currentProfile->getAuthMethod() == "mschap" || GlobalConfig->currentProfile->getAuthMethod() == "mschap-v2" ) + { + + Utils ( GlobalConfig, this ).doChmod ( "/etc/ppp/pap-secrets", "go-rwx" ); + + // write pppd /etc/ppp/chap-secrets + QString ChapSecrets = "/etc/ppp/chap-secrets"; // /etc/ppp/chap-secrets + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "pppd secrets file: %1" ).arg ( "/etc/ppp/chap-secrets" ), GlobalConfig->debug ); + QFile ChapSecretsFile ( ChapSecrets ); + stream.setDevice ( &ChapSecretsFile ); + if ( ChapSecretsFile.open ( IO_WriteOnly | IO_Append ) ) + { + stream << "# +++ generated by kvpnc. Do not edit it." << "\n"; + stream << "# profile: " + GlobalConfig->currentProfile->getName() << "\n"; + + if ( GlobalConfig->currentProfile->getSaveUserPassword() ) + GlobalConfig->TmpPassword = GlobalConfig->currentProfile->getUserPassword(); + + QString UsernameStr; + if ( !GlobalConfig->currentProfile->getDontSaveUsername() ) + UsernameStr = GlobalConfig->currentProfile->getUserName(); + else + UsernameStr = GlobalConfig->TmpUsername; + + GlobalConfig->appendLogEntry ( i18n ( "Username: %1" ).arg ( UsernameStr ), GlobalConfig->debug ); + + if ( GlobalConfig->currentProfile->getUseNtDomainName() && !GlobalConfig->currentProfile->getNtDomainName().isEmpty() ) + { + // line: "\\""" + stream << "\"" << GlobalConfig->currentProfile->getNtDomainName() << "\\\\" << UsernameStr << "\"\t" << "*" << "\t" << " \"" << GlobalConfig->TmpPassword << "\"\t*\n"; + } + else + { + // line: """" + stream << "\"" << UsernameStr << "\"\t" << "*" << "\t" << " \"" << GlobalConfig->TmpPassword << "\"\t*\n"; + + } + stream << "# --- generated by kvpnc. Do not edit it." << "\n"; + ChapSecretsFile.close(); + + + Utils ( GlobalConfig, this ).doChmod ( "/etc/ppp/chap-secrets", "go-rwx" ); + } + } + if ( GlobalConfig->currentProfile->getAuthMethod() == "pap" ) + { + + //GlobalConfig->appendLogEntry ( i18n ( "Creating of %1 failed!" ).arg ( "pppd secrets file" ), GlobalConfig->error ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Authentication method: %1" ).arg ( GlobalConfig->currentProfile->getAuthMethod() ), GlobalConfig->debug ); + + + Utils ( GlobalConfig, this ).doChmod ( "/etc/ppp/chap-secrets", "go-rwx" ); + + // write pppd /etc/ppp/pap-secrets + QString papSecrets = "/etc/ppp/pap-secrets"; // /etc/ppp/pap-secrets + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "pppd secrets file: %1" ).arg ( "/etc/ppp/pap-secrets" ), GlobalConfig->debug ); + QFile papSecretsFile ( papSecrets ); + papSecretsFile.setName ( papSecrets ); + stream.setDevice ( &papSecretsFile ); + if ( papSecretsFile.open ( IO_WriteOnly | IO_Append ) ) + { + stream << "# +++ generated by kvpnc. Do not edit it." << "\n"; + stream << "# profile: " + GlobalConfig->currentProfile->getName() << "\n"; + + if ( GlobalConfig->currentProfile->getSaveUserPassword() ) + GlobalConfig->TmpPassword = GlobalConfig->currentProfile->getUserPassword(); + + QString UsernameStr; + if ( !GlobalConfig->currentProfile->getDontSaveUsername() ) + UsernameStr = GlobalConfig->currentProfile->getUserName(); + else + UsernameStr = GlobalConfig->TmpUsername; + + GlobalConfig->appendLogEntry ( i18n ( "Username: %1" ).arg ( UsernameStr ), GlobalConfig->debug ); + + if ( GlobalConfig->currentProfile->getUseNtDomainName() && !GlobalConfig->currentProfile->getNtDomainName().isEmpty() ) + { + // line: "\\""" + stream << "\"" << GlobalConfig->currentProfile->getNtDomainName() << "\\\\" << UsernameStr << "\"\t" << "*" << "\t" << GlobalConfig->TmpPassword << "\t*\n"; + } + else + { + // line: """" + stream << UsernameStr << "\t" << "*" << "\t" << "\"" << GlobalConfig->TmpPassword << "\""<< "\t*\n"; + } + stream << "# --- generated by kvpnc. Do not edit it." << "\n"; + papSecretsFile.close(); + + + Utils ( GlobalConfig, this ).doChmod ( "/etc/ppp/pap-secrets", "go-rwx" ); + } + } + L2tpdProcess=0L; + } + if ( GlobalConfig->currentProfile->getL2tpDaemon() == VpnAccountData::openl2tp ) + { + // write openl2tp..conf + QString tmpPath = locateLocal ( "data", "kvpnc/" ); + QString OpenL2tpContName = tmpPath + "openl2tp." + GlobalConfig->currentProfile->getName() + ".conf"; + QFile OpenL2tpConfigFile ( OpenL2tpContName ); + QTextStream stream ( &OpenL2tpConfigFile ); + if ( OpenL2tpConfigFile.open ( IO_WriteOnly ) ) + { + stream << "# generated by kvpnc. Do not edit it." << "\n"; + stream << "# profile: " + GlobalConfig->currentProfile->getName() << "\n"; + stream << "" << "\n"; + stream << "ppp profile modify profile_name=default "; + if ( GlobalConfig->currentProfile->getAuthMethod() == "chap" ) + stream << "auth_eap=no auth_pap=no auth_mschapv1=no auth_mschapv2=no"; + + if ( GlobalConfig->currentProfile->getAuthMethod() == "mschap" ) + stream << "auth_eap=no auth_pap=no auth_mschapv1=yes auth_mschapv2=yes"; + + if ( GlobalConfig->currentProfile->getAuthMethod() == "mschap-v2" ) + stream << "auth_eap=no auth_pap=no auth_mschapv1=no auth_mschapv2=yes"; + + if ( GlobalConfig->currentProfile->getAuthMethod() == "pap" ) + stream << "auth_eap=no auth_pap=yes auth_mschapv1=no auth_mschapv2=no"; + + stream << "\n"; + stream << "tunnel create tunnel_name=" << GlobalConfig->currentProfile->getName() << " dest_ipaddr=" << GlobalConfig->TmpGatewayIP << " persist=yes" << "\n"; + + + if ( GlobalConfig->currentProfile->getSaveUserPassword() ) + GlobalConfig->TmpPassword = GlobalConfig->currentProfile->getUserPassword(); + + QString UsernameStr; + if ( !GlobalConfig->currentProfile->getDontSaveUsername() ) + UsernameStr = GlobalConfig->currentProfile->getUserName(); + else + UsernameStr = GlobalConfig->TmpUsername; + + + stream << "session create tunnel_name=" << GlobalConfig->currentProfile->getName() << " session_name=" << GlobalConfig->currentProfile->getName() << " user_name=" << UsernameStr << " user_password=" << GlobalConfig->TmpPassword << "\n"; + + OpenL2tpConfigFile.close(); + + OpenL2tpProcess=0L; + + if ( !Utils ( GlobalConfig, parent ).loadKernelModule ( "slhc", parent ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Loading module \"%1\" failed" ).arg ( "slhc" ).arg ( "/etc/modprobe.conf" ), GlobalConfig->debug ); + else + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Loading module \"%1\" succeded" ).arg ( "slhc" ), GlobalConfig->debug ); + } + if ( !Utils ( GlobalConfig, parent ).loadKernelModule ( "ppp_generic", parent ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Loading module \"%1\" failed." ).arg ( "ppp_generic" ), GlobalConfig->debug ); + else + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Loading module \"%1\" succeded" ).arg ( "ppp_generic" ), GlobalConfig->debug ); + } + if ( !Utils ( GlobalConfig, parent ).loadKernelModule ( "pppox", parent ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Loading module \"%1\" failed." ).arg ( "pppox" ), GlobalConfig->debug ); + else + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Loading module \"%1\" succeded" ).arg ( "pppox" ), GlobalConfig->debug ); + } + if ( !Utils ( GlobalConfig, parent ).loadKernelModule ( "pppol2tp", parent ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Loading module \"%1\" failed" ).arg ( "pppol2tp" ), GlobalConfig->debug ); + else + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry ( i18n ( "Loading module \"%1\" succeded" ).arg ( "pppol2tp" ), GlobalConfig->debug ); + } + + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "Creating of %1 failed!" ).arg ( "openl2tp config file" ), GlobalConfig->error ); + stopContinue = true; + } + } +} + +void KVpnc::start_l2tpd() +{ + QString daemon=""; + if ( GlobalConfig->currentProfile->getL2tpDaemon() == VpnAccountData::l2tpd ) + { + if ( !GlobalConfig->pathToXl2tpd.isEmpty() && QFile ( GlobalConfig->pathToXl2tpd ).exists() ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Using %1." ).arg ( "xl2tpd" ),GlobalConfig->debug ); + daemon="xl2tpd"; + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Using %1." ).arg ( "l2tpd" ),GlobalConfig->debug ); + daemon="l2tpd"; + } + + bool control_interface_success=true; + + QString L2tpdPid=""; + if ( daemon == "xl2tpd" ) + L2tpdPid="/var/run/xl2tpd.pid"; + else + L2tpdPid="/var/run/l2tpd.pid"; + + + QString L2tpdControl=""; + if ( daemon == "xl2tpd" ) + L2tpdControl="/var/run/l2tp-control"; + else + L2tpdControl="/var/run/l2tp-control"; + + + +// if (QFile(L2tpdPid).exists()) +// { +// if (GlobalConfig->KvpncDebugLevel > 1) +// GlobalConfig->appendLogEntry(i18n("Using control interface for starting l2tp connection"),GlobalConfig->debug); +// +// QString L2tpdControl=""; +// if (daemon == "xl2tpd") +// L2tpdControl="/var/run/xl2tpd/l2tp-control"; +// else +// L2tpdControl="/var/run/l2tp-control"; +// +// QFile L2tpdControlFile ( L2tpdControl ); +// QTextStream stream( &L2tpdControlFile ); +// if ( L2tpdControlFile.open( IO_WriteOnly ) ) { +// stream << "c " << GlobalConfig->currentProfile->getName() << "\n"; +// L2tpdControlFile.close(); +// } +// else +// { +// control_interface_success=false; +// GlobalConfig->appendLogEntry(i18n("Starting l2tp connection via control interface has been failed"),GlobalConfig->error); +// } +// } +// if (!QFile("/var/run/l2tpd.pid").exists() || control_interface_success==false) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Starting l2tpd manually" ),GlobalConfig->debug ); + sleep ( 2 ); + + // start l2tpd + L2tpdProcess = new QProcess ( this ); + // + if ( daemon == "xl2tpd" ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Using %1." ).arg ( "xl2tpd" ),GlobalConfig->debug ); + L2tpdProcess->addArgument ( GlobalConfig->pathToXl2tpd ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Using %1." ).arg ( "l2tpd" ),GlobalConfig->debug ); + L2tpdProcess->addArgument ( GlobalConfig->pathToL2tpd ); + } + L2tpdProcess->addArgument ( "-p" ); + L2tpdProcess->addArgument ( "/var/run/l2tpd." + GlobalConfig->currentProfile->getName() + ".pid" ); + + if ( daemon == "xl2tpd" ) + { + L2tpdProcess->addArgument ( "-C" ); + L2tpdProcess->addArgument ( L2tpdControl ); + } + L2tpdProcess->addArgument ( "-c" ); + L2tpdProcess->addArgument ( tmpPath + "l2tpd." + GlobalConfig->currentProfile->getName() + ".conf" ); + // L2tpdProcess->addArgument ( "-s" ); + // L2tpdProcess->addArgument ( tmpPath + "l2tp-secrets." + GlobalConfig->currentProfile->getName() ); + L2tpdProcess->addArgument ( "-D" ); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + { + QString cmdline = ""; + QStringList cmdarguments = L2tpdProcess->arguments(); + for ( QStringList::Iterator it = cmdarguments.begin(); it != cmdarguments.end(); ++it ) + { + cmdline += " " + QString ( *it ); + } + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( "\""+daemon+"\" cmd line: " + cmdline , GlobalConfig->debug ); + } + + connect ( L2tpdProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_l2tpd() ) ); + connect ( L2tpdProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_l2tpd() ) ); + + connect ( this, SIGNAL ( L2tpdStdoutRecieved() ), this, SLOT ( processStdout_l2tpd() ) ); + connect ( this, SIGNAL ( L2tpdStderrRecieved() ), this, SLOT ( processStderr_l2tpd() ) ); + + if ( !L2tpdProcess->start ( env ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( daemon ), GlobalConfig->error ); + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( daemon ) ); + setGuiStatus ( disconnected ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( "l2tpd" ), GlobalConfig->debug ); + + +// if (GlobalConfig->KvpncDebugLevel > 1) +// GlobalConfig->appendLogEntry(i18n("Using control interface for starting l2tp connection"),GlobalConfig->debug); +// +// QString L2tpdControl=""; +// if (daemon == "xl2tpd") +// L2tpdControl="/var/run/xl2tpd/l2tp-control"; +// else +// L2tpdControl="/var/run/l2tp-control"; +// +// QFile L2tpdControlFile ( L2tpdControl ); +// QTextStream stream( &L2tpdControlFile ); +// if ( L2tpdControlFile.open( IO_WriteOnly ) ) { +// stream << "c " << GlobalConfig->currentProfile->getName() << "\n"; +// L2tpdControlFile.close(); +// } +// else +// { +// control_interface_success=false; +// GlobalConfig->appendLogEntry(i18n("Starting l2tp connection via control interface has been failed"),GlobalConfig->error); +// } + } + } + } + if ( GlobalConfig->currentProfile->getL2tpDaemon() == VpnAccountData::openl2tp ) + { + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Using %1." ).arg ( "openl2tp" ),GlobalConfig->debug ); + daemon="openl2tp"; + } + +// bool control_interface_success=true; + +// QString L2tpdPid=""; +// if (daemon == "xl2tpd") +// L2tpdPid="/var/run/xl2tpd.pid"; +// else +// L2tpdPid="/var/run/l2tpd.pid"; + + startStopOpenl2tp ( true ); + sleep ( 2 ); + startStopOpenl2tp(); + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Starting openl2tpd manually" ),GlobalConfig->debug ); +// sleep ( 2 ); + + // start openl2tpd + OpenL2tpProcess = new QProcess ( this ); + // + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Using %1." ).arg ( "openl2tpd" ),GlobalConfig->debug ); + OpenL2tpProcess->addArgument ( GlobalConfig->pathToOpenl2tp ); + +// if (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon) +// { +// // use ipsec tools extensions +// OpenL2tpProcess->addArgument ( "-p" ); +// OpenL2tpProcess->addArgument ( "ipsec.so" ); +// } + OpenL2tpProcess->addArgument ( "-f" ); // foreground + OpenL2tpProcess->addArgument ( "-c" ); + + QString tmpPath = locateLocal ( "data", "kvpnc/" ); + QString OpenL2tpContName = tmpPath + "openl2tp." + GlobalConfig->currentProfile->getName() + ".conf"; + + OpenL2tpProcess->addArgument ( OpenL2tpContName ); + + OpenL2tpProcess->addArgument ( "-D" ); // debug + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + { + QString cmdline = ""; + QStringList cmdarguments = OpenL2tpProcess->arguments(); + for ( QStringList::Iterator it = cmdarguments.begin(); it != cmdarguments.end(); ++it ) + { + cmdline += " " + QString ( *it ); + } + GlobalConfig->appendLogEntry ( "\""+daemon+"\" cmd line: " + cmdline , GlobalConfig->debug ); + } + + connect ( OpenL2tpProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_openl2tp() ) ); + connect ( OpenL2tpProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_openl2tp() ) ); + + if ( !OpenL2tpProcess->start ( env ) ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" start failed!" ).arg ( daemon ), GlobalConfig->error ); + KMessageBox::error ( this, i18n ( "\"%1\" start failed!" ).arg ( daemon ) ); + setGuiStatus ( disconnected ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "\"%1\" started." ).arg ( "openl2tp" ), GlobalConfig->debug ); + + + } + + + } +} + +void KVpnc::checkL2tpPppUp() +{ + + GlobalConfig->appendLogEntry ( i18n ( "Check ppp device..." ), GlobalConfig->debug ); + QString tmpPath = locateLocal ( "data", "kvpnc/" ); + QFile L2tpPppPidFile ( "/var/run/ppp-kvpnc." +GlobalConfig->currentProfile->getName() +".pid" ); + + if ( L2tpPppPidFile.exists() ) + { + if ( L2tpPppPidFile.open ( IO_ReadOnly ) ) + { + L2tpPppDevice=""; + QTextStream stream ( &L2tpPppPidFile ); + QString line = ""; + while ( !stream.atEnd() ) + { + line = stream.readLine(); + if ( line.contains ( "ppp", false ) ) + { + L2tpPppDevice= line.stripWhiteSpace(); + break; + } + } + + L2tpPppPidFile.close(); + if ( L2tpPppDevice.length() > 1 ) + { + + // ok, we got the device + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Tunnel device: %1\n" ).arg ( L2tpPppDevice ), GlobalConfig->debug ); + + L2tpWaitForPppUpTimer.stop(); + bool connectSuccess=false; + + NetworkInterface iface ( GlobalConfig, parent ); + if ( iface.interfaceExist ( L2tpPppDevice ) ) + { + TunnelInterfaceIP = iface.getInterfaceIP ( L2tpPppDevice ); + if ( !TunnelInterfaceIP.isEmpty() ) + GlobalConfig->appendLogEntry ( i18n ( "Tunnel interface IP address: %1\n" ).arg ( TunnelInterfaceIP ), GlobalConfig->debug ); + } + + + if ( TunnelInterfaceIP.isEmpty() ) + { + sleep ( 10 ); + if ( iface.interfaceExist ( L2tpPppDevice ) ) + { + TunnelInterfaceIP = iface.getInterfaceIP ( L2tpPppDevice ); + if ( !TunnelInterfaceIP.isEmpty() ) + GlobalConfig->appendLogEntry ( i18n ( "Tunnel interface IP address: %1\n" ).arg ( TunnelInterfaceIP ), GlobalConfig->debug ); + if ( !TunnelInterfaceIP.isEmpty() ) + { + connectSuccess=true; + } + } + } + else + { + connectSuccess=true; + } + + if ( connectSuccess ) + { + sec = hour = min = 0; + + GlobalConfig->status = GlobalConfig->connected; + + disconnect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + connect ( &durationTimer, SIGNAL ( timeout() ), this, SLOT ( slotDurationEvent() ) ); + durationTimer.start ( 1000, FALSE ); + setGuiStatus ( connected ); + + + setFirewallAfterConnect(); + if ( GlobalConfig->currentProfile->getExecuteCmdAfterConnect() ) + executeCommandAfterConnect(); + + sleep ( 2 ); + + if ( GlobalConfig->currentProfile->getUseAdditionalNetworkRoutes() && !GlobalConfig->currentProfile->getAdditionalNetworkRoutes().isEmpty() ) + addAdditionalNetworkRoutes(); + + if ( GlobalConfig->currentProfile->getUseConnectionStatusCheck() ) + { + startConnectionStatusCheck(); + } + + } + } + + } +// else +// { +// +// } + } + +} + +bool KVpnc::checkCiscoVpncStatus() +{ + ciscoVpncRunning = false; + TestCiscoVpncProcess = new QProcess ( this ); + TestCiscoVpncProcess->setCommunication ( QProcess::Stdin | QProcess::Stdout | QProcess::Stderr | QProcess::DupStderr ); + TestCiscoVpncProcess->addArgument ( GlobalConfig->InterpreterShell ); + TestCiscoVpncProcess->addArgument ( "/etc/init.d/vpnclient_init" ); + TestCiscoVpncProcess->addArgument ( "status" ); + + connect ( TestCiscoVpncProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readCiscoVpncTestProcessOutput() ) ); + connect ( TestCiscoVpncProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readCiscoVpncTestProcessOutput() ) ); + + if ( !TestCiscoVpncProcess->start ( env ) ) + { + disconnect ( TestCiscoVpncProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readCiscoVpncTestProcessOutput() ) ); + disconnect ( TestCiscoVpncProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readCiscoVpncTestProcessOutput() ) ); + delete TestCiscoVpncProcess; + TestCiscoVpncProcess=0L; + GlobalConfig->appendLogEntry ( i18n ( "unable to start proc (%1)!" ).arg ( i18n ( "Test Cisco vpnclient" ) ) , KVpncConfig::error ); + return false; + } + else + { + while ( TestCiscoVpncProcess->isRunning() ) + { + usleep ( 500 ); + parent->processEvents(); + } + disconnect ( TestCiscoVpncProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readCiscoVpncTestProcessOutput() ) ); + disconnect ( TestCiscoVpncProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readCiscoVpncTestProcessOutput() ) ); + delete TestCiscoVpncProcess; + TestCiscoVpncProcess=0L; + } + return ciscoVpncRunning; +} + +void KVpnc::startCiscoVpnc() +{ + TestCiscoVpncProcess = new QProcess ( this ); + TestCiscoVpncProcess->setCommunication ( QProcess::Stdin | QProcess::Stdout | QProcess::Stderr | QProcess::DupStderr ); + TestCiscoVpncProcess->addArgument ( GlobalConfig->InterpreterShell ); + TestCiscoVpncProcess->addArgument ( "/etc/init.d/vpnclient_init" ); + TestCiscoVpncProcess->addArgument ( "start" ); + +// connect ( TestCiscoVpncProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readCiscoVpncTestProcessOutput() ) ); +// connect ( TestCiscoVpncProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readCiscoVpncTestProcessOutput() ) ); + + if ( !TestCiscoVpncProcess->start ( env ) ) + { +// disconnect ( TestCiscoVpncProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readCiscoVpncTestProcessOutput() ) ); +// disconnect ( TestCiscoVpncProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readCiscoVpncTestProcessOutput() ) ); + delete TestCiscoVpncProcess; + TestCiscoVpncProcess=0L; + GlobalConfig->appendLogEntry ( i18n ( "unable to start proc (%1)!" ).arg ( i18n ( "Start Cisco vpnclient" ) ) , KVpncConfig::error ); + return; + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "proc (%1) started." ).arg ( i18n ( "Start Cisco vpnclient" ) ) , KVpncConfig::debug ); + while ( TestCiscoVpncProcess->isRunning() ) + { + usleep ( 500 ); + parent->processEvents(); + } +// disconnect ( TestCiscoVpncProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readCiscoVpncTestProcessOutput() ) ); +// disconnect ( TestCiscoVpncProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readCiscoVpncTestProcessOutput() ) ); + delete TestCiscoVpncProcess; + TestCiscoVpncProcess=0L; + } +} + +void KVpnc::sendFeedbackMail() +{ + FeedbackDialog = new KFeedbackDialog ( "crissi99@gmx.de", "feedback_mail" ); + connect ( FeedbackDialog->form(), SIGNAL ( mailSent() ), this, SLOT ( feedbackMailSent() ) ); + + KFeedbackQuestionList * list = FeedbackDialog->form() ->questionList(); + + KFeedbackQuestion * question = list->addQuestion ( i18n ( "What is your general opinion about this program?" ), "general_opinion", true, true ); + + question->addAnswer ( i18n ( "It's one of my favourites" ), "1/8_favourite" ); + question->addAnswer ( i18n ( "I like it" ), "2/8_like_it" ); + question->addAnswer ( i18n ( "It's sometimes useful" ), "3/8_sometimes_useful" ); + question->addAnswer ( i18n ( "It's average" ), "4/8_average" ); + question->addAnswer ( i18n ( "Nice try, but this could be done better" ), "5/8_nice_try" ); + question->addAnswer ( i18n ( "It's poor" ), "6/8_poor" ); + question->addAnswer ( i18n ( "It's useless" ), "7/8_useless" ); + question->addAnswer ( i18n ( "It's crap" ), "8/8_crap" ); + + question = list->addQuestion ( i18n ( "Which features of this program do you like?" ), "features_liked", false ); + addFeatureList ( question ); + + question = list->addQuestion ( i18n ( "Which features don't you like?" ), "features_not_liked", false ); + addFeatureList ( question ); + + question = list->addQuestion ( i18n ( "Which features do you never use?" ), "features_never_used", false ); + addFeatureList ( question ); + + question = list->addQuestion ( i18n ( "What is your favourite feature?" ), "favourite_feature", true ); + addFeatureList ( question ); + + question = list->addQuestion ( i18n ( "Are there features you are missing?" ), "features_missing", true ); + question->addAnswer ( i18n ( "Yes, a lot! (please add comment below)" ), "1/4_lots" ); + question->addAnswer ( i18n ( "Some (please add comment below)" ), "2/4_some" ); + question->addAnswer ( i18n ( "None" ), "3/4_none" ); + question->addAnswer ( i18n ( "It has too many features already!" ), "4/4_too_many_already" ); + + question = list->addQuestion ( i18n ( "How do you rate the stability of this program?" ), "stability", true, true ); + question->addAnswer ( i18n ( "Rock solid" ), "1/5_rock_solid" ); + question->addAnswer ( i18n ( "Good" ), "2/5_good" ); + question->addAnswer ( i18n ( "Average" ), "3/5_average" ); + question->addAnswer ( i18n ( "Poor" ), "4/5_poor" ); + question->addAnswer ( i18n ( "It keeps crashing all the time" ), "5/5_keeps_crashing" ); + + question = list->addQuestion ( i18n ( "How do you rate the performance of this program?" ), "performance", true ); + question->addAnswer ( i18n ( "Great" ), "1/5_great" ); + question->addAnswer ( i18n ( "Good" ), "2/5_good" ); + question->addAnswer ( i18n ( "Average" ), "3/5_average" ); + question->addAnswer ( i18n ( "Poor" ), "4/5_poor" ); + question->addAnswer ( i18n ( "It's so slow it drives me nuts" ), "5/5_drives_me_nuts" ); + + question = list->addQuestion ( i18n ( "What is your experience with computers in general?" ), "computer_experience", true ); + question->addAnswer ( i18n ( "Expert" ), "1/5_expert" ); + question->addAnswer ( i18n ( "Fair" ), "2/5_fair" ); + question->addAnswer ( i18n ( "Average" ), "3/5_average" ); + question->addAnswer ( i18n ( "Learning" ), "4/5_learning" ); + question->addAnswer ( i18n ( "Newbie" ), "5/5_newbie" ); + + question = list->addQuestion ( i18n ( "What is your experience with Unix/Linux systems?" ), "unix_experience", true ); + question->addAnswer ( i18n ( "Expert" ), "1/5_expert" ); + question->addAnswer ( i18n ( "Fair" ), "2/5_fair" ); + question->addAnswer ( i18n ( "Average" ), "3/5_average" ); + question->addAnswer ( i18n ( "Learning" ), "4/5_learning" ); + question->addAnswer ( i18n ( "Newbie" ), "5/5_newbie" ); + + question = list->addQuestion ( i18n ( "Did you have trouble figuring out how to work with this program in general?" ), + "learning_curve", true, true ); + question->addAnswer ( i18n ( "No problem" ), "1/5_no_problem" ); + question->addAnswer ( i18n ( "Some" ), "2/5_some_problems" ); + question->addAnswer ( i18n ( "I'm still learning" ), "3/5_still_learing" ); + question->addAnswer ( i18n ( "I didn't have a clue what to do at first" ), "4/5_no_clue_at_first" ); + question->addAnswer ( i18n ( "I still don't have a clue what to do" ), "5/5_still_no_clue" ); + + question = list->addQuestion ( i18n ( "Where do you use this program most?" ), "usage_where", true ); + question->addAnswer ( i18n ( "At work" ), "at_work" ); + question->addAnswer ( i18n ( "At home" ), "at_home" ); + question->addAnswer ( i18n ( "At university / school" ), "university" ); + + question = list->addQuestion ( i18n ( "What is your primary role there?" ), "primary_role", true ); + question->addAnswer ( i18n ( "Home user" ), "home_user" ); + question->addAnswer ( i18n ( "Student" ), "student" ); + question->addAnswer ( i18n ( "Educational (teacher / professor)" ), "educational" ); + question->addAnswer ( i18n ( "Non-computer related work" ), "non_computer" ); + question->addAnswer ( i18n ( "Developer" ), "developer" ); + question->addAnswer ( i18n ( "System administrator" ), "sysadmin" ); + + question = list->addQuestion ( i18n ( "Do you have any other roles there?" ), "other_roles", false ); + question->addAnswer ( i18n ( "Home user" ), "home_user" ); + question->addAnswer ( i18n ( "Student" ), "student" ); + question->addAnswer ( i18n ( "Educational (teacher / professor)" ), "educational" ); + question->addAnswer ( i18n ( "Non-computer related work" ), "non_computer" ); + question->addAnswer ( i18n ( "Developer" ), "developer" ); + question->addAnswer ( i18n ( "System administrator" ), "sysadmin" ); + + question = list->addQuestion ( i18n ( "How did you get to know this program?" ), "first_contact", true ); + question->addAnswer ( i18n ( "In a menu on my machine" ), "menu" ); + question->addAnswer ( i18n ( "Somebody told me about it" ), "told" ); + question->addAnswer ( i18n ( "On the internet" ), "internet" ); + question->addAnswer ( i18n ( "Printed magazine / book" ), "print_media" ); + question->addAnswer ( i18n ( "Other (please add comment below)" ), "other" ); + + list->addYesNoQuestion ( i18n ( "Would you recommend this program to a friend?" ), "recommend", true ); + + if ( ! FeedbackDialog->isVisible() ) + FeedbackDialog->show(); +} + +void KVpnc::addFeatureList ( KFeedbackQuestion * ) +{ + // question->addAnswer( i18n( "The directory tree display in general" ), "tree_view" ); + // question->addAnswer( i18n( "Percentage bars as graphical display of relative sizes" ), "percentage_bars" ); + // question->addAnswer( i18n( "Files apart from directories in a separate item"), "files_item" ); + +} + +void KVpnc::feedbackMailSent() +{ + GlobalConfig->feedbackMailSent = true; +} + +// --- DCOP stuff --- +QString KVpnc::getVersion() +{ + return parent->aboutData() ->version(); +} + +void KVpnc::doConnect() +{ + connectClicked(); +} + +void KVpnc::doDisconnect() +{ + disconnectClicked(); +} + +uint KVpnc::getConnectedTime() +{ + + if ( GlobalConfig->status == GlobalConfig->connected ) + { + // return secs + return hour * 60 * 60 + min * 60 + sec; + } + else + return 0; +} + +QString KVpnc::getStatus() +{ + if ( GlobalConfig->status == GlobalConfig->connected ) + return "connected"; + else if ( GlobalConfig->status == GlobalConfig->disconnected ) + return "disconnected"; + else if ( GlobalConfig->status == GlobalConfig->connecting ) + return "connecting"; + else + return "unknown"; +} + +QString KVpnc::getCurrentProfile() +{ + return GlobalConfig->currentProfile->getName(); +} + +void KVpnc::setProfile ( QString profilename ) +{ + for ( uint i = 0; i < GlobalConfig->AccountList->count();i++ ) + { + if ( GlobalConfig->AccountList->at ( i ) ->getName() == profilename ) + { + sessionToggled ( profilename ); + mw->SessionCombo->setCurrentText ( profilename ); + GlobalConfig->currentProfile = GlobalConfig->AccountList->at ( i ); + break; + } + } +} + +void KVpnc::createNewProfile() +{ + newSessionClicked(); +} + +void KVpnc::createNewProfileWithWizard() +{ + showNewProfileWizardClicked(); +} + +void KVpnc::deleteCurrentProfile() +{ + deleteSessionClicked(); +} + +void KVpnc::openPreferences() +{ + slotSettings(); +} + +void KVpnc::doImportCert() +{ + importCertClicked(); +} + +void KVpnc::doImportPcf() +{ + importProfileClicked ( "" ); +} + +void KVpnc::doImportPcf ( QString file ) +{ + importProfileClicked ( file ); +} + +void KVpnc::doImportOpenvpnConfig() +{ + importOpenvpnProfileClicked ( "" ); +} + +void KVpnc::doImportOpenvpnConfig ( QString file ) +{ + importOpenvpnProfileClicked ( file ); +} + +QStringList KVpnc::profiles() +{ + QStringList profiles; + VpnAccountData * it; + if ( !GlobalConfig->AccountList->isEmpty() ) + { + for ( it = GlobalConfig->AccountList->first(); it; it = GlobalConfig->AccountList->next() ) + { + //std::cout << it->getName() << "\n"; + profiles.append ( it->getName() ); + } + } + return profiles; +} + +void KVpnc::doQuit() +{ + quitCalled(); +} + +QStringList KVpnc::toolinfo() +{ + QStringList toolinfo; + ToolInfo *tool = 0; + for ( tool = GlobalConfig->ToolList->first(); tool; tool = GlobalConfig->ToolList->next() ) + { + QString toolstring; + std::cout << "tool: " << tool->Name.ascii() << std::endl; + // std::cout << "Version: " << tool->Version << std::endl; + // std::cout << "Path: " << tool->PathToExec << std::endl << std::endl; + QString state = ""; + QString usability = ""; + QString comment = ""; + + //FIXME how it could be better? + if ( tool->Name == "vpnc" ) + { + if ( !GlobalConfig->pathToVpnc.isEmpty() ) + { + tool->addSearchPath ( GlobalConfig->pathToVpnc.section ( '/', 0, -2 ) ); + tool->collectToolInfo(); + } + } + else if ( tool->Name == "ipsec" ) + { + if ( !GlobalConfig->pathToIpsec.isEmpty() ) + { + tool->addSearchPath ( GlobalConfig->pathToIpsec.section ( '/', 0, -2 ) ); + tool->collectToolInfo(); // crash if enabled (why the hell?) + } + } + else if ( tool->Name == "racoon" ) + { + if ( !GlobalConfig->pathToRacoon.isEmpty() ) + { + tool->addSearchPath ( GlobalConfig->pathToRacoon.section ( '/', 0, -2 ) ); + tool->collectToolInfo(); + } + } + else if ( tool->Name == "setkey" ) + { + if ( !GlobalConfig->pathToSetkey.isEmpty() ) + { + tool->addSearchPath ( GlobalConfig->pathToSetkey.section ( '/', 0, -2 ) ); + tool->collectToolInfo(); + } + } + else if ( tool->Name == "openvpn" ) + { + if ( !GlobalConfig->pathToOpenvpn.isEmpty() ) + { + tool->addSearchPath ( GlobalConfig->pathToOpenvpn.section ( '/', 0, -2 ) ); + tool->collectToolInfo(); + } + } + else if ( tool->Name == "openssl" ) + { + if ( !GlobalConfig->pathToOpenssl.isEmpty() ) + { + tool->addSearchPath ( GlobalConfig->pathToOpenssl.section ( '/', 0, -2 ) ); + tool->collectToolInfo(); + } + } + else if ( tool->Name == "pppd" ) + { + if ( !GlobalConfig->pathToPppd.isEmpty() ) + { + tool->addSearchPath ( GlobalConfig->pathToPppd.section ( '/', 0, -2 ) ); + tool->collectToolInfo(); + } + + } + else if ( tool->Name == "iptables" ) + { + if ( !GlobalConfig->pathToIptables.isEmpty() ) + { + tool->addSearchPath ( GlobalConfig->pathToIptables.section ( '/', 0, -2 ) ); + tool->collectToolInfo(); + } + } + else if ( tool->Name == "kill" ) + { + if ( !GlobalConfig->pathToKill.isEmpty() ) + { + tool->addSearchPath ( GlobalConfig->pathToKill.section ( '/', 0, -2 ) ); + tool->collectToolInfo(); + } + } + else if ( tool->Name == "killall" ) + { + if ( !GlobalConfig->pathToKillall.isEmpty() ) + { + tool->addSearchPath ( GlobalConfig->pathToKillall.section ( '/', 0, -2 ) ); + tool->collectToolInfo(); + } + } + else if ( tool->Name == "ping" ) + { + if ( !GlobalConfig->pathToPing.isEmpty() ) + { + tool->addSearchPath ( GlobalConfig->pathToPing.section ( '/', 0, -2 ) ); + tool->collectToolInfo(); + } + } + else if ( tool->Name == "ip" ) + { + if ( !GlobalConfig->pathToIp.isEmpty() ) + { + tool->addSearchPath ( GlobalConfig->pathToIp.section ( '/', 0, -2 ) ); + tool->collectToolInfo(); + } + } + else if ( tool->Name == "ifconfig" ) + { + if ( !GlobalConfig->pathToIfconfig.isEmpty() ) + { + tool->addSearchPath ( GlobalConfig->pathToIfconfig.section ( '/', 0, -2 ) ); + tool->collectToolInfo(); + } + } + else if ( tool->Name == "route" ) + { + if ( !GlobalConfig->pathToRoute.isEmpty() ) + { + tool->addSearchPath ( GlobalConfig->pathToRoute.section ( '/', 0, -2 ) ); + tool->collectToolInfo(); + } + } + else + { + //std::cout << "Invalid tool!" << std::endl; + } + + if ( !tool->PathToExec.isEmpty() ) + { + state = i18n ( "Found" ); + if ( tool->Name == "vpnc" ) + { + if ( tool->Version.find ( "3.3", 0, -1 ) > -1 ) + { + usability = i18n ( "full" ); + } + else if ( tool->Version.find ( "3.2", 0, -1 ) > -1 ) + { + usability = i18n ( "limited" ); + comment = i18n ( "no split DNS support" ); + } + else if ( tool->Version.find ( "2.", 0, -1 ) > -1 ) + { + usability = i18n ( "basic" ); + comment = i18n ( "no NAT-T, IPSec over IP, no split DNS support" ); + } + } + else if ( tool->Name == "freeswan" ) + { + if ( tool->Version.find ( "2.", 0, -1 ) > -1 ) + usability = i18n ( "full" ); + else if ( tool->Version.find ( "1.", 0, -1 ) > -1 ) + usability = i18n ( "limited" ); + } + else if ( tool->Name == "racoon" ) + { + //if ( tool->Version.find("2.",0,-1) > -1) + usability = i18n ( "full" ); + //else if ( tool->Version.find("2.",0,-1) > -1) + // usability=i18n("limited"); + } + else if ( tool->Name == "openvpn" ) + { + if ( tool->Version.find ( "2.", 0, -1 ) > -1 ) + { + usability = i18n ( "full" ); + int major = tool->Version.section ( '.', 0, 0 ).toInt(); + int minor = tool->Version.section ( '.', 1, 1 ).toInt(); + // int subminor=tool->Version.section('.',2,2).toInt(); + + if ( major >= 2 && minor >= 1 ) + usability += ", " + i18n ( "pcks11 support" ); + } + else if ( tool->Version.find ( "1.", 0, -1 ) > -1 ) + //else + usability = i18n ( "limited" ); + } + else if ( tool->Name == "pppd" ) + { + //if ( tool->Version.find("2.",0,-1) > -1) + usability = i18n ( "full" ); + //else if ( tool->Version.find("2.",0,-1) > -1) + // usability=i18n("limited"); + } + else if ( tool->Name == "kill" ) + { + //if ( tool->Version.find("2.",0,-1) > -1) + usability = i18n ( "full" ); + //else if ( tool->Version.find("2.",0,-1) > -1) + // usability=i18n("limited"); + } + else if ( tool->Name == "ip" ) + { + //if ( tool->Version.find("2.",0,-1) > -1) + usability = i18n ( "full" ); + //else if ( tool->Version.find("2.",0,-1) > -1) + // usability=i18n("limited"); + } + else if ( tool->Name == "ifconfig" ) + { + //if ( tool->Version.find("2.",0,-1) > -1) + usability = i18n ( "full" ); + //else if ( tool->Version.find("2.",0,-1) > -1) + // usability=i18n("limited"); + } + else if ( tool->Name == "route" ) + { + //if ( tool->Version.find("2.",0,-1) > -1) + usability = i18n ( "full" ); + //else if ( tool->Version.find("2.",0,-1) > -1) + // usability=i18n("limited"); + } + else + { + // other tools + usability = i18n ( "full" ); + } + } + else + { + state = i18n ( "Not found" ); + usability = i18n ( "none" ); + } + + std::cout << "Version: " << tool->Version.ascii() << std::endl; + + toolstring += tool->Name; + toolstring += ","; + toolstring += state; + toolstring += ","; + toolstring += tool->Version; + toolstring += ","; + toolstring += usability; + toolstring += ","; + toolstring += comment; + + toolinfo.append ( toolstring ); + + } + + return toolinfo; +} + +void KVpnc::doGenerateOpenvpnKey() +{ + generateOpenvpnKey(); +} + +void KVpnc::doSendFeedbackMail() +{ + sendFeedbackMail(); +} + +QStringList KVpnc::getProfileTypes() +{ + QStringList ProfileTypes; + + ProfileTypes.append ( "Cisco (vpnc)" ); + ProfileTypes.append ( "IPSec (racoon)" ); + ProfileTypes.append ( "IPSec (FreeSWAN/Openswan/strongSwan)" ); + ProfileTypes.append ( "PPTP" ); + ProfileTypes.append ( "OpenVPN" ); + ProfileTypes.append ( "L2TP (racoon)" ); + ProfileTypes.append ( "L2TP (freeswan)" ); + ProfileTypes.append ( "Vtun" ); + ProfileTypes.append ( "SSH" ); + return ProfileTypes; +} + diff --git a/src/kvpnc.desktop b/src/kvpnc.desktop new file mode 100644 index 0000000..fea7e46 --- /dev/null +++ b/src/kvpnc.desktop @@ -0,0 +1,27 @@ +[Desktop Entry] +Encoding=UTF-8 +Comment=GUI for various VPN clients +Comment[es]=Interfaces para varios clientes VPN +Comment[de]=Oberfläche für VPN-Clients +Comment[pt]=Interface para vários clientes de VPNs +Comment[sv]=Grafiskt gränssnitt för diverse VPN-klienter +Comment[xx]=xxGUI for various VPN clientsxx + +Name=KVpnc +Name[xx]=xxKVpncxx + +GenericName=VPN Client GUI +GenericName[es]=Interfaz del cliente VPN +GenericName[de]=VPN-Client-GUI +GenericName[pt]=GUI de Cliente de VPN +GenericName[sv]=Grafiskt gränssnitt för VPN-klienter +GenericName[xx]=xxVPN Client GUIxx + +Categories=Network;RemoteAccess;KDE;Qt +Exec=kvpnc +X-KDE-SubstituteUID=true +Icon=kvpnc +Type=Application + +Version=0.9.4 + diff --git a/src/kvpnc.h b/src/kvpnc.h new file mode 100644 index 0000000..51e29fb --- /dev/null +++ b/src/kvpnc.h @@ -0,0 +1,548 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* Contains parts of code from klcc project * +* (Peter Simonsson ). * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +//BEGIN #includes +#ifndef __KVPNC_H__ +#define __KVPNC_H__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "kvpnckicker.h" +#include "preferencesdialog.h" +#include "mainview.h" +#include "vpnaccountdata.h" +#include "networkinterface.h" +#include "kvpncconfig.h" +#include "toolinfo.h" +#include "openvpnmanagementhandler.h" + +// ID for statusbar +#define ID_STATUS_MSG 1 +#define ID_CONNECTION_MSG 2 +#define ID_FLASH_MSG 3 +//END #includes + + + +/** +* main class of kvpnc +* @author Christoph Thielecke +*/ +class KVpnc : public KMainWindow , DCOPObject +{ + Q_OBJECT + K_DCOP +public: + /** + * Konstruktor + * @param parent Parent widget + * @param name Name of the Mainwindow + */ + KVpnc( KApplication *parent, QWidget *qparent = 0, const char *name = 0 ); + + /** + * Destruktor + */ + ~KVpnc(); +protected: + /** + * init the actions + */ + void initAction(); + + /** + * init the main view + */ + void initView(); + + /** + * init the statusbar + */ + void initStatusbar(); + + /** + * init the kicker system tray icon + */ + void initDockWindow(); + + /** + * sets the gui status + * @param status The status that will be set + */ + void setGuiStatus( int status ); + + /** + * terminates the connection + * @param proc the connect process + */ + void terminateConnection ( QProcess *proc ); + /** + * called when quit requested + */ + virtual bool queryExit(); + + void saveProperties( KConfig* ); + void readProperties( KConfig* ); + +public: + void restore(KConfig *config, int i); + void restore(); + + /** + * return the user id of the certificate + * @param Cert certificate from wich should be extracted + * @param user true if user id, false if issuer id + */ + QString getX509CertificateID( QString Cert, bool user ); + + void profileAddedOrDeleted(); + bool setVirtualIP(); + +private: + // FIXME also declared at kvpncconfig -> made it only in one place + enum ConnectionStatus {disconnected=0, connecting=1, connected=2}; + enum LogType {info=0, remote=1, error=2, success=3, debug=4}; + + KApplication *parent; + QStringList *env; + + KVpncConfig *GlobalConfig; + KVpncKicker* KVpncDock; //< kicker menu + KAction* ConnectAction; //< connect action + KAction* DisconnectAction; //< disconnect action + KAction *NewSessionAction; + KAction *SaveSessionAction; + KAction *DeleteSessionAction; + KAction *RenameSessionAction; + KAction *ImportSessionAction; + KAction *ImportOpenvpnProfileAction; + KAction *ExportOpenvpnProfileAction; + KAction *ImportFreeswanProfileAction; + KAction *ImportFritzboxProfileAction; + KAction *ImportKvpncSettingsAction; + KAction *ExportKvpncSettingsAction; + KAction *ImportCertAction; + KAction *SelectAction; //< line select action + KAction *ProfileManagerAction; + KAction *NewProfileWizardAction; + KAction *HelpAction; + KAction *PrefAction; + KAction *DonateAction; + KAction *ReportBugAction; + KAction *SendFeedbackMailAction; + KAction *PreferencesAction; //< show preferences dialog + KAction *ManageCiscoCertAction; //< show cisco cert manager + KAction *CiscoCertEnrollmentAction; //< show cisco cert enrollment dialog + KToggleAction *ToolsInfoAction; + KToggleAction *VpnTypesInfoAction; + KToggleAction *LogViewerAction; + KToggleAction *ShowToolbarAction; //< toggle toolbar on/off + KToggleAction *ShowStatusbarAction; //< toggle statusbar on/off + KToggleAction *DebugconsoleAction; //< toggle debug console + KToggleAction *GenerateOpenvpnKeyAction; //< generate OpenVPN key + MainView* mw; //< Main gui + QTimer timer; + QTimer durationTimer; //< timer for counting connection time + QTimer IpsecWhackStatusTimer; //< getting ipsec status periodically + QTimer L2tpWaitForPppUpTimer; //< getting ppp device + int connectCounter; //< counter for connecting + int RacoonctlConnectCounter; //<< counter for waiting of adminsock + int sec, min, hour; + int racoon_tunnel_state; // 0 => no tunnel, 1 => first tunnel, 2 => second tunnel + int prevConnectionState; //< needed for setGuiStatus(), holds previous state before disconnect (connected, connecting) + + bool cancelClicked; + bool deviceaddrstr2addr; + bool pingtest; + bool getUserID; + bool X509CertificateExtractRunning; + bool X509CertificateExtractUser; + bool setVirtualIPSuccess; + bool AuthRetry; + bool quitFromKicker; + bool shutdownIsCalled; + bool stopContinue; //< if something happens that causes to abort now + bool ciscoVpncRunning; //< true if vpnclient is started and cipsec0 is up + bool showProfilesOnly; //< if true only the profiles will shown in preferencesdialog + bool IpsecStartingInProgress; + bool IpsecGotError; + + bool IpsecPhase1Up; + bool IpsecPhase2Up; + + bool IpsecStatusCheck; + + bool pppdHasReplacedefaultrouteSupport; + + QString OldDefaultroute; + QString VpncConnectScript; + QString VpncDisconnectScript; + QString tmpPath; + QString ProcessMsg_connect; + QString ProcessMsg_disconnect; + QString deviceaddrstr; + QString deviceaddr; + QString tmpInterface; + QString LocalIP; + QString VpncGateway; + QString PptpGateway; + QString VpncScript; + QString issuerID; // for id extract + QString userID; // for id extract + QString TunnelInterfaceIP; + QString TmpDns1; + QString TmpDns2; + QString VpncDevice; + QString CiscoVpncDevice; + QString L2tpPppDevice; + QString PppdDevice; + QString OpenvpnDevice; + QString SshDevice; + QString IpsecType; //< openswan, strongswan, freeswan + QString Pkcs11PIN; + QString PrettyTypeString; + QString PrettyStatusMessage; + + QProcess *VpncProcess; + KProcess *IpsecConnectProcess; + QProcess *DisconnectProcess; + QProcess *CiscoVpncProcess; //< vpnclient + QProcess *RacoonProcess; //< racoon + QProcess *RacoonHelperProcess; + QProcess *IpsecProcess; //< freeswan/openswan/strongswan + QProcess *IpsecStartProcess; + QProcess *IpsecWhackProcess; //< ipsec whack --initate + QProcess *IpsecWhackStatusProcess; //< ipsec whack --status + QProcess *IpsecWhackListenProcess; //< ipsec whack --listen + QProcess *IpsecWhackDeleteProcess; //< ipsec whack --delete + QProcess *PingProcess; + QProcess *RacoonTailProcess; + QProcess *RacoonctlProcess; //< racoonctl + QProcess *X509CertificateExtractProcess; + QProcess *PptpProcess; + QProcess *OpenvpnProcess; + QProcess *CmdBeforeConnectProcess; + QProcess *CmdBeforeDisconnectProcess; + QProcess *CmdAfterConnectProcess; + QProcess *CmdAfterDisconnectProcess; + QProcess *SetFirewallAfterConnectProcess; + QProcess *SetFirewallBeforeDisconnectProcess; + QProcess *RouteProcess; + QProcess *SetVirtualIPProcess; + QProcess *ReplaceDefaultRouteProcess; + QProcess *ConnectionStatusCheckProcess; + QProcess *TestCiscoVpncProcess; + QProcess *IptablesProcess; + QProcess *KillProcess; + QProcess *PptpRouteProcess; + QProcess *ChmodProcess; + QProcess *pppdUpProcess; + QProcess *pppdDelDefaultRouteProcess; + QProcess *L2tpdProcess; + QProcess *OpenL2tpProcess; + QProcess *RemoveSetkeyProcess; + QProcess *BugReportProcess; + QProcess *DonateProcess; + QProcess *VtundProcess; + QProcess *StartStopOpenl2tpProcess; + KProcess *SshProcess; + QProcess *backupDefaultRouteProcess; + QProcess *pptpdKillProcess; + QProcess *SshDownProcess; + QProcess *pppdDownProcess; + QProcess *killracoonprocess; + QProcess *killl2tpdprocess; + QProcess *SshUpProcess; + + int TimeOutProcess; //< for timeout + int ConnectingProcess; //< for killing process + QPixmap connectedIcon; + QPixmap disconnectedIcon; + QPixmap connectingIcon; + QPixmap *connectingStatusPixmap; + QPixmap *disconnectedStatusPixmap; + QPixmap *connectedStatusPixmap; + + QLabel *statusColorLabel; + QPopupMenu *QuickConnectMenu; + + OpenvpnManagementHandler *managementhandler ; + KFeedbackDialog *FeedbackDialog; + + QString L2tpdBufferStdoutString; + QString L2tpdBufferStderrString; + + PreferencesDialog *prefDlg; + + +public slots: + /** setup KVpnc */ + void slotSettings(); + /** show / hide toolbar */ + void slotShowToolbar(); + /** show / hide statusbar */ + void slotShowStatusbar(); + /** configure key bindings */ + void slotKeyBindings(); + /** configure toolbars */ + void slotConfigToolbars(); + + void slotConfigNotifications(); + + + /** + * Slot for status message + * @param text The text that will be set + * @param id What type its is + */ + void slotStatusMsg( const QString &text, int id = ID_STATUS_MSG ); + + void connectClicked(); + void disconnectClicked(); + void saveSessionClicked(); + void newSessionClicked(); + void deleteSessionClicked(); + void renameSessionClicked (); + void sessionToggled( const QString& ); + void helpClicked(); + void toolsInfoClicked(); + void vpnTypesInfoClicked(); + void donateClicked(); + void reportBugClicked(); + void saveGuiOptions(); + void showNewProfileWizardClicked(); + + +private slots: + + /** + * called if close clicked + * @param e the event which happen + */ + void closeEvent( QCloseEvent* e ); + bool queryClose(); + void shutdownCalled(); + void slotCancelClicked(); + void slotConnectTimedOut(); + void slotDurationEvent(); + void showDockTooltip(); + void readOutputFrom_vpnc(); + void readOutputFrom_ciscovpnc(); + void wroteToStdin_vpncConfig(); + void readFromStdout_disconnect(); + void readFromStderr_disconnect(); + void readFromStdout_racoon(); + void readFromStderr_racoon(); + void readFromStdout_racoon_helper(); + void readFromStderr_racoon_helper(); + void readFromStdout_ipsec(); + void readFromStderr_ipsec(); + void readFromStdout_ipsecwhack(); + void readFromStderr_ipsecwhack(); + void readFromStdout_ipsecwhacklisten(); + void readFromStderr_ipsecwhacklisten(); + void readFromStdout_ipsecwhackstatus(); + void readFromStderr_ipsecwhackstatus(); + void readFromStdout_ipsecwhackdelete(); + void readFromStderr_ipsecwhackdelete(); + void readFromStdout_pptp(); + void readFromStderr_pptp(); + void readFromStdout_l2tpd(); + void readFromStderr_l2tpd(); + void processStdout_l2tpd(); + void processStderr_l2tpd(); + void readFromStdout_openl2tp(); + void readFromStderr_openl2tp(); + void readFromStdout_startstopOpenl2tp(); + void readFromStderr_startstopOpenl2tp(); + void checkL2tpPppUp(); + void readOutput_openvpn(); + void readFromStdout_vtun(); + void readFromStderr_vtun(); + void readFromStdout_ssh(KProcess *proc, char *buffer, int buflen); + void readFromStderr_ssh(KProcess *proc, char *buffer, int buflen); + void readFromStdout_executeCommandBeforeConnect(); + void readFromStderr_executeCommandBeforeConnect(); + void readFromStdout_executeCommandAfterConnect(); + void readFromStderr_executeCommandAfterConnect(); + void readFromStdout_executeCommandBeforeDisconnect(); + void readFromStderr_executeCommandBeforeDisconnect(); + void readFromStdout_executeCommandAfterDisconnect(); + void readFromStderr_executeCommandAfterDisconnect(); + + + void readFromStdout_tail_racoon(); + void readFromStderr_tail_racoon(); + void readFromStdout_racoonctl(); + void readFromStderr_racoonctl(); + void readFromStdout_ping(); + void readFromStderr_ping(); + void readFromStdout_route(); + void readFromStderr_route(); + void readFromStdout_getX509CertificateID(); + void readFromStderr_getX509CertificateID(); + void readFromStdout_setVirtualIP(); + void readFromStderr_setVirtualIP(); + void readFromStdout_connectionStatusCheck(); + void readFromStderr_connectionStatusCheck(); + void readCiscoVpncTestProcessOutput(); + void quitCalled(); + void quitCalledKicker(); + void pptpProcessExited(); + void vtun_exited(); //< vtund has been exited + void openvpn_exited(); //< openvpn has been exited + void ipsecwhack_exited(); //< ipsec whack has been exited + void IpsecWhackStatusProcessExited(); + void racoonctlExited(); + void prepareL2tpd(); //< write l2tpd conf etc. + void start_ipsec_initiate(); + void doAddRemoveVirtualIp(QString action); + + void importProfileClicked(); //< PCF import + void importIpsecProfileClicked(); + void importFritzboxProfileClicked(); + void importKvpncSettingsClicked(); + void exportKvpncSettingsClicked(); + + void importOpenvpnProfileClicked(); //< OpenVPN config file import + void doRacoon(); + void stopRacoon(); + void doRoutePptp(); + void addRouteIpsec(); + void delRouteIpsec(); + void doTailRacoonLog(); + void doIptablesRacoon(); + void doIptablesFreeswan(); + void addRouteRacoon(); + void delRouteRacoon(); + void doPingKickupTunnel(); + void removeIptablesRacoon(); + void removeIptablesFreeswan(); + void removeSetkey(); + void connectionEnded(); + void doPingTest(); + void pingTestExited(); + void sshExited(); + void vpncStarted(); + void ipsecStarted(); + void ipsecPhase2Established(); + void checkIpsecWhackStatus(); + void addIpsecConnection(); + void racoonStarted(); + void pppdStarted(); + void openvpnStarted(); + void openSSLEnded(); + void importCertClicked(); + void manageCiscoCertClicked(); + void enrollCiscoCertClicked(); + void showProfileManagerClicked(); + void executeCommandBeforeConnect(); + void executeCommandAfterConnect(); + void executeCommandBeforeDisconnect(); + void executeCommandAfterDisconnect(); + void setFirewallAfterConnect(); + void setFirewallBeforeDisconnect(); + void slotConnecting(); + void toggleDebugConsole(); + void addAdditionalNetworkRoutes(); + void removeAdditionalNetworkRoutes(); + void showLogViewer(); + void doQuickConnect(int id); + void startConnectionStatusCheck(); + void generateOpenvpnKey(); + void preserveNetworkEnvironment(); //< save route and resolv.conf + void restoreNetworkEnvironment(); //< restore route and resolv.conf + void backupIpsecSystemConfig(); // backup ipsec.conf and ipsec.secrets + void backupDefaultRoute(); + void exportOpenvpnProfileClicked(); + void addFeatureList( KFeedbackQuestion * question ); + void sendFeedbackMail(); + void feedbackMailSent(); + void start_l2tpd(); + bool checkCiscoVpncStatus(); + void startCiscoVpnc(); + void startStopIpsec(bool stop=false, bool silent=false); + void startStopOpenl2tp(bool stop=false, bool silent=false); + +signals: + void L2tpdStdoutRecieved(); + void L2tpdStderrRecieved(); + void newProfileCreated(QString Name); + +public: + void importOpenvpnProfileClicked(QString file); //< OpenVPN config file import + void importProfileClicked(QString file); //< PCF import + + bool backupResolvConf(); + bool restoreResolvConf(); + +public: +k_dcop: + QString getVersion(); + void doConnect(); + void doDisconnect(); + uint getConnectedTime(); + QString getStatus(); + QString getCurrentProfile(); + void setProfile(QString profilename); + void createNewProfile(); + void createNewProfileWithWizard(); + void deleteCurrentProfile(); + void openPreferences(); + void doImportCert(); + void doImportPcf(); + void doImportPcf(QString file); + void doImportOpenvpnConfig(); + void doImportOpenvpnConfig(QString file); + QStringList profiles(); + QStringList toolinfo(); + void doQuit(); + void doGenerateOpenvpnKey(); + void doSendFeedbackMail(); + QStringList getProfileTypes(); + +}; + +#endif + diff --git a/src/kvpnc.lsm b/src/kvpnc.lsm new file mode 100644 index 0000000..dfeca9f --- /dev/null +++ b/src/kvpnc.lsm @@ -0,0 +1,14 @@ +Begin +Title: KVpnc - KDE frontend for various VPN clients +Version: 0.9.1 +Entered-date: +Description: KVpnc is a KDE Desktop Environment frontend for various vpn clients. It supports Cisco VPN (vpnc, vpnclient), IPSec (FreeS/WAN, Openswan, strongSwan, racoon), PPTP (pptpclient), OpenVPN, L2TP (l2tpd, xl2tpd, openl2tp) over IPsec (FreeS/WAN, Openswan, strongSwan, racoon), Vtun and SSH. Smartcard will be supported for OpenVPN and IPsec (strongSwan). +Keywords: KDE Qt vpnc vpn pptp certificate openvpn freeswan openswan cisco ipsec psk l2tp smartcard vtun openssh +Author: Christoph Thielecke +Maintained-by: Christoph Thielecke +Home-page: http://home.gna.org/kvpnc/ +Alternate-site: ftp://ftp.kde.org/pub/kde/unstable/apps/utils +Primary-site: http://download.gna.org/kvpnc/ +Platform: Linux. Needs KDE +Copying-policy: GPL +End diff --git a/src/kvpncconfig.cpp b/src/kvpncconfig.cpp new file mode 100644 index 0000000..b232d86 --- /dev/null +++ b/src/kvpncconfig.cpp @@ -0,0 +1,4524 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +//BEGIN INCLUDES +#include "kvpncconfig.h" +#include "utils.h" +#include "kvpncimportprofileselectiondialog.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//END INCLUDES + +KVpncConfig::KVpncConfig(QWidget *parent,KStatusBar *statusbar) +{ + this->parent = parent; + this->statusbar = statusbar; + + pathToVpnc = ""; + pathToCiscoVpnc = ""; + pathToRacoon = ""; + pathToRacoonctl = ""; + pathToSetkey = ""; + pathToIpsec = ""; + pathToPppd=""; + pathToPptp=""; + pathToL2tpd=""; + pathToXl2tpd=""; + pathToSsh="/usr/bin/ssh"; + pathToKill=""; + pathToKillall=""; + pathToPing=""; + pathToOpenvpn=""; + pathToIp="/sbin/ip"; + pathToIfconfig="/sbin/ifconfig"; + pathToRoute="/sbin/route"; + pathToNetstat="/bin/netstat"; + pathToL2tpd="/usr/sbin/l2tpd"; + pathToPkcs11Tool="/usr/bin/pkcs11-tool"; + pathToVtund="/usr/sbin/vtund"; + pathToCiscoCertMgr="/usr/local/bin/cisco_cert_mgr"; + pathToTail="/usr/bin/tail"; + pathToSsh="/usr/bin/ssh"; + pathToKsshAskpass="/usr/bin/ksshaskpass"; + pathToGnomeSshAskpass="/usr/lib/openssh/gnome-ssh-askpass"; + AutoConnectProfile=""; + Vpnc_pid_file = ""; + Pppd_pid_file = ""; + lastProfile = ""; + logfileName = ""; + InterpreterShell="/bin/bash"; + + TmpPassword=""; + TmpGroupPassword=""; + TmpUsername=""; + TmpPrivKeyPassStr=""; + TmpGatewayIP=""; + TmpXauthInterPasscode=""; + TmpPrivateKeyPass=""; + TmpHttpProxyPassword=""; + DnsDevice = ""; + + OldDefaultGw=""; + OldDefaultDev=""; + + connectSleepDelay = 15; + connectSleepRetry = 0; + tryConnectTimeout = 10; + runningCheckCounter = 0; + runningCheckTimeout = 60; + mainwindow_pos_x=0; + mainwindow_pos_y=0; + mainwindow_height=200; + mainwindow_width=400; + AuthRetryCount=0; + PppdKernelLogLevel=0; + maxConnectRetry=3; + currentConnectRetry=0; + + OpenvpnManagementPort=2222; + + minimizeAfterConnect = true; + //showDebugConsole = false; + useDefaultPaths = false; + writeLogFile = true; + useSilentQuit = false; + holdGeneratedScripts = true; + enableDebugPppd=false; + enableDebugPptpd=false; + enableDebugL2tpd=false; + enableDebugXl2tpd=false; + enableDebugXl2tpdNetwork=false; + enableDebugXl2tpdpacket=false; + enableDebugXl2tpdstate=false; + enableDebugXl2tpdtunnel=false; + enableDebugOpenvpn=false; + useColorizedLogOutput=true; + showInterfaceIPinTooltip=true; + dontQuitOnCloseEvent=true; + PppdDebugLevel = false; + doAutoConnectAtStartup=false; + useKwallet=true; + showStatusBar=true; + showToolBar=true; + firstUseOfKwallet=true; + shutdownIsCalled=false; + skipKwalletStoring = false; + hideOnCloseInfo = false; + enableFreeswanVerbose=false; + doKillL2tpdIfStillRunning=true; + doKillRacoonIfStillRunning=true; + hideMainWindow=false; + showInterfaceIPinTooltip = true; + showConnectionTimeInTooltip = true; + OpenvpnNeedSecurityParameter = false; + haveUserData=false; + prefDlgOpen=false; + + VpncDebugLevel = 0; + RacoonDebugLevel = "info"; + KvpncDebugLevel = 0; + OpenvpnDebugLevel =0; + LogViewerFontSize=0; // can be from -3 up to +3 + + DebugBackgroundcolor=black; + + ToolList = new QPtrList(); + ToolList->setAutoDelete( TRUE ); + + AccountList = new QPtrList(); + AccountList->setAutoDelete( TRUE ); // the list owns the objects + + InfoLogColor=Qt::black; + ErrorLogColor=Qt::red; + SuccessLogColor=Qt::darkGreen; + DebugLogColor=Qt::yellow; + + KStandardDirs *dirs = KGlobal::dirs(); + logfileName = QString(dirs->saveLocation( "data" )); + QString logfilePath = QString(logfileName + "/kvpnc/kvpnc.log"); + logfile.setName( logfilePath ); + logFileStream.setDevice( &logfile ); + + currentProfile=0L; +} + +KVpncConfig::~KVpncConfig() +{ + delete AccountList; + delete ToolList; +} + +void KVpncConfig::setLogOutput(QTextEdit *LogOutput) +{ + this->LogOutput = LogOutput; +} + +void KVpncConfig::appendLogEntry( QString msg, LogType type ) +{ + + // write to logfile + if ( writeLogFile ) + { + if ( !logfile.isOpen() ) + { + KStandardDirs * dirs = KGlobal::dirs(); + QString logfileName = dirs->saveLocation( "data" ); + logfileName += "/kvpnc/kvpnc.log"; // /root.kde/share/apps/kvpnc.log + // KMessageBox::information( this, logfileName, "info" ); + logfile.setName( logfileName ); + if ( !logfile.open( IO_WriteOnly | IO_Append ) ) + KMessageBox::error( 0, i18n( "Log file can not be opened!" ) ); + else + { + // QTextStream s( &logfile ); + logFileStream << i18n( "Log session started at: " ); + logFileStream << QDateTime::currentDateTime().toString( Qt::TextDate ); + logFileStream << "\n"; + logfile.flush(); + } + } + else + { + QString date = QDate().currentDate().toString(Qt::ISODate)+ " "; + QString time = QTime().currentTime().toString(Qt::ISODate)+ " "; + QString prefix=""; + switch ( type ) + { + case info: + prefix=i18n("info")+": "; + break; + case remote: + prefix=i18n("remote")+": "; + break; + case error: + prefix=i18n("error")+": "; + break; + case success: + prefix=i18n("success")+": "; + break; + case debug: + prefix=i18n("debug")+": "; + break; + } +// appPointer->processEvents(); + logFileStream << date << time << prefix << msg << "\n"; + logfile.flush(); +// appPointer->processEvents(); + } + + } + // write into debug console + QString prefix=""; + QString postfix=""; + + // font size + prefix+=""; + postfix+="<\\font>"; + + if (useColorizedLogOutput) + prefix+=""; + } + prefix+=i18n("info")+": "; + break; + case remote: + if (useColorizedLogOutput) + { + prefix+=RemoteLogColor.name(); + prefix+="\">"; + } + prefix+=i18n("remote")+": "; + + break; + case error: + if (useColorizedLogOutput) + { + prefix+=ErrorLogColor.name(); + prefix+="\">"; + } + prefix+=i18n("error")+": "; + + break; + case success: + if (useColorizedLogOutput) + { + prefix+=SuccessLogColor.name(); + prefix+="\">"; + } + prefix+=i18n("success")+": "; + break; + case debug: + if (useColorizedLogOutput) + { + prefix+=DebugLogColor.name(); + prefix+="\">"; + } + prefix+=i18n("debug")+": "; + break; + } + + if (useColorizedLogOutput) + postfix+=""; + + LogOutput->append( prefix+msg+postfix ); +// if (appPointer->hasPendingEvents ()) +// appPointer->processEvents(); +} + +void KVpncConfig::slotStatusMsg( const QString &text, int id ) +{ + if ( id != ID_FLASH_MSG ) + { + statusbar ->clear(); + statusbar ->changeItem( text, id ); + } + else + { + statusbar->message( text, 2000 ); + } + +} + +void KVpncConfig::saveOptions(bool saveOneProfile, QString Profile) +{ + if (saveOneProfile && Profile.isEmpty()) + return; + KStandardDirs * dirs = KGlobal::dirs(); + QString filePath = dirs->findResource ( "config", "kvpncrc" ); + QFile::remove + ( filePath ); + + config->setGroup( "Notification Messages" ); + config->writeEntry( "hideOnCloseInfo" ,hideOnCloseInfo); + + if (!saveOneProfile) + { + + config->setGroup( "General Options" ); + + checkStandardPathValues(); + + config->writeEntry( "Minimize after connect", minimizeAfterConnect ); + config->writeEntry("Hide on startup", hideMainWindow ); + config->writeEntry( "Use silent quit", useSilentQuit ); + config->writeEntry( "Dont quit on CloseEvent", dontQuitOnCloseEvent ); + config->writeEntry( "Enable pppd debug", enableDebugPppd ); + config->writeEntry( "Enable pptpd debug", enableDebugPptpd ); + config->writeEntry( "Enable l2tpd debug", enableDebugL2tpd ); + config->writeEntry( "Enable xl2tpd debug", enableDebugXl2tpd ); + config->writeEntry( "Enable openl2tp debug", enableDebugOpenl2tp ); + config->writeEntry( "Enable FreeSWAN verbose", enableFreeswanVerbose ); + config->writeEntry( "Pluto Debug", PlutoDebug.join(" ")); + config->writeEntry( "Klips Debug", KlipsDebug.join(" ")); + config->writeEntry( "Show debugconsole", showDebugConsole ); + config->writeEntry( "Pid file for vpnc ", Vpnc_pid_file ); + config->writeEntry( "Vpnc debuglevel", VpncDebugLevel ); + config->writeEntry( "Racoon debuglevel", RacoonDebugLevel ); + config->writeEntry( "Kvpnc debuglevel", KvpncDebugLevel ); + config->writeEntry( "Pppd debuglevel", PppdDebugLevel ); + config->writeEntry( "Openvpn debuglevel", OpenvpnDebugLevel ); + config->writeEntry( "Pptp debuglevel", PptpLogLevel ); + config->writeEntry( "Ssh debuglevel", SshDebugLevel ); + config->writeEntry( "Pppd kernel log level", PppdKernelLogLevel ); + config->writeEntry( "Path to vpnc-bin", pathToVpnc ); + config->writeEntry( "Path to vpnclient", pathToCiscoVpnc ); + config->writeEntry( "Path to racoon", pathToRacoon ); + config->writeEntry( "Path to racoonctl", pathToRacoonctl ); + config->writeEntry( "Path to setkey", pathToSetkey ); + config->writeEntry( "Path to iptables", pathToIptables ); + config->writeEntry( "Path to openssl", pathToOpenssl ); + config->writeEntry( "Path to freeswan", pathToIpsec ); + config->writeEntry( "Path to pppd", pathToPppd ); + config->writeEntry( "Path to pptp", pathToPptp ); + config->writeEntry( "Path to l2tpd", pathToL2tpd ); + config->writeEntry( "Path to xl2tpd", pathToXl2tpd ); + config->writeEntry( "Path to openl2tp", pathToOpenl2tp ); + config->writeEntry( "Path to kill", pathToKill ); + config->writeEntry( "Path to kill-all", pathToKillall ); + config->writeEntry( "Path to ping", pathToPing ); + config->writeEntry( "Path to openvpn", pathToOpenvpn ); + config->writeEntry( "Path to iputility", pathToIp ); + config->writeEntry( "Path to ifconfig", pathToIfconfig ); + config->writeEntry( "Path to route", pathToRoute ); + config->writeEntry( "Path to netstat", pathToNetstat ); + config->writeEntry( "Path to pkcs11-tool", pathToPkcs11Tool ); + config->writeEntry( "Path to vtund", pathToVtund ); + config->writeEntry( "Path to cisco_cert_mgr",pathToCiscoCertMgr); + config->writeEntry( "Path to tail",pathToTail); + config->writeEntry( "Path to ssh",pathToSsh); + config->writeEntry( "Path to ksshaskpass",pathToKsshAskpass); + config->writeEntry( "Path to ssh-askpass-gnome",pathToGnomeSshAskpass); + config->writeEntry( "Show Statusbar", showStatusBar ); + config->writeEntry( "Try connect timeout", tryConnectTimeout ); + config->writeEntry( "Last Profile", lastProfile ); + config->writeEntry( "Write log file", writeLogFile ); + config->writeEntry( "Hold generated scripts", holdGeneratedScripts ); + config->writeEntry( "Programs in path", programsInPath ); + config->writeEntry( "Info logwindow color", InfoLogColor ); + config->writeEntry( "Remote logwindow color", RemoteLogColor ); + config->writeEntry( "Error logwindow color", ErrorLogColor ); + config->writeEntry( "Success logwindow color", SuccessLogColor ); + config->writeEntry( "Debug logwindow color", DebugLogColor ); + config->writeEntry("Debug background color", DebugBackgroundcolor ); + config->writeEntry( "Use colorized log output", useColorizedLogOutput ); + config->writeEntry( "Show interface IP in tooltip", showInterfaceIPinTooltip ); + config->writeEntry( "Auto connect profile", AutoConnectProfile ); + config->writeEntry( "Do auto connect at startup", doAutoConnectAtStartup ); + config->writeEntry( "Log viewer font size", LogViewerFontSize ); + config->writeEntry( "Mainwindow width", parent->width() ); + config->writeEntry( "Mainwindow height", parent->height() ); + config->writeEntry( "Mainwindow position x", parent->x() ); + config->writeEntry( "Mainwindow position y", parent->y() ); + config->writeEntry("Openvpn management port", OpenvpnManagementPort ); + //config->writeEntry( "ToolBar Settings" ,parent->toolBar( "mainToolBar" )); + config->writeEntry("Use KWallet",useKwallet); + config->writeEntry("FeedbackMailSent",feedbackMailSent); + config->writeEntry("Do kill l2tpd if still running",doKillL2tpdIfStillRunning); + config->writeEntry("Do kill racoon if still running",doKillRacoonIfStillRunning); + config->writeEntry("Do kill xl2tpd if still running",doKillXl2tpdIfStillRunning); + config->writeEntry("Show connection time in Tooltip",showConnectionTimeInTooltip); + config->writeEntry("Enable debug Openvpn",enableDebugOpenvpn); + + config->writeEntry("EnableDebugXl2tpdNetwork",enableDebugXl2tpdNetwork); + config->writeEntry("EnableDebugXl2tpdpacket",enableDebugXl2tpdpacket); + config->writeEntry("EnableDebugXl2tpdstate",enableDebugXl2tpdstate); + config->writeEntry("EnableDebugXl2tpdtunnel",enableDebugXl2tpdtunnel); + + //appPointer->processEvents(); + } + + if (useKwallet && KWallet::Wallet::isEnabled()) + config->writeEntry( "First use of Kwallet", false ); + /* = user data = */ + VpnAccountData *it; + if ( !AccountList->isEmpty() ) + { + /* passwords with kwallet */ + if ( useKwallet && KWallet::Wallet::isEnabled()) + { + if (!skipKwalletStoring ) + { + if (KvpncDebugLevel > 2) + appendLogEntry(i18n( "Wallet enabled and available, writing to wallet." ),debug); + // Open local wallet + wallet = KWallet::Wallet::openWallet(KWallet::Wallet::LocalWallet()); + //appPointer->processEvents(); + if (wallet != 0) + { + } + } + } + else + { + if (KvpncDebugLevel > 2) + appendLogEntry(i18n( "Wallet disabled or not available, writing to config file." ),debug); + } + + QPtrList *TmpAccountList; + + if (!saveOneProfile) + TmpAccountList = AccountList; + else + { + TmpAccountList = new QPtrList(); + TmpAccountList->setAutoDelete( TRUE ); // the list owns the objects + VpnAccountData *ProfileData; + + for ( ProfileData = AccountList->first(); it; it = AccountList->next() ) + { + if ( ProfileData->getName() == Profile ) + { + TmpAccountList->append(ProfileData); + break; + } + } + } + + for ( it = TmpAccountList->first(); it; it = TmpAccountList->next() ) + { +// appPointer->processEvents(); +// std::cout << "Save profile: " << it->getName().ascii() << std::endl; + + if ( !it->getName().isEmpty() ) + { + QString name = it->getName(); + QString ProfileName = "Profile_"; + ProfileName += name; + config->setGroup( ProfileName ); + + config->writeEntry("Description",it->getDescription()); + + /* passwords with kwallet */ + if ( useKwallet && KWallet::Wallet::isEnabled()) + { + if (!skipKwalletStoring ) + { + if (KvpncDebugLevel > 2) + appendLogEntry(i18n( "Wallet enabled and available, writing to wallet." ),debug); + if (wallet != 0) + { + QString walletname="kvpnc"; + // Check if folder exists, otherwise create it + bool walletOK=true; + if (!wallet->hasFolder(walletname)) + { + walletOK = wallet->createFolder(walletname); +// wallet->sync(); +// appPointer->processEvents(); + } + if (walletOK) + { + wallet->setFolder(walletname); +// appPointer->processEvents(); + //std::cout << "[set] account: " << ProfileName << ", loginname: " << loginname << ", password: " << pwd << std::endl; + bool UserPasswordOK=true; + if ( it->getSaveUserPassword() ) + UserPasswordOK = (wallet->writePassword (QString(name+"__user_pw"), it->getUserPassword()) == 0); + else + UserPasswordOK = (wallet->writePassword (QString(name+"__user_pw"), "") == 0); +// wallet->sync(); +// appPointer->processEvents(); + + bool PskOK=true; + if ( it->getSavePsk() ) + PskOK = (wallet->writePassword (QString(name+"__psk"), it->getPreSharedKey()) == 0); + else + PskOK = (wallet->writePassword (QString(name+"__psk"), "") == 0); +// wallet->sync(); + +// appPointer->processEvents(); + + bool PskKeyPassOK = (wallet->writePassword (QString(name+"__priv_key_pwd"), it->getPrivateKeyPass()) == 0); +// // wallet->sync(); + +// appPointer->processEvents(); + + if (KvpncDebugLevel > 2) + { + if (UserPasswordOK) + if (KvpncDebugLevel > 2) + appendLogEntry(i18n( "write of %1 was ok." ).arg(i18n("user password")), debug); + else + { + // if ( KMessageBox::warningContinueCancel( 0, + // i18n( "KVpnc is unable to save %1 password securely in your wallet.
" + // "Do you want to save the password in the unsafe configuration file instead?" ).arg(i18n("user password")), + // i18n( "Unable to store secure %1" ).arg(i18n("user password")), + // KGuiItem( i18n( "Store &Unsafe" ), QString::fromLatin1( "unlock" ),QString::fromLatin1( "KWalletFallbackToKConfig" ) ) ) == KMessageBox::Continue ) + // { + // config->writeEntry( "User password", it->getUserPassword() ); + // } + + appendLogEntry(i18n( "write of %1 has failed." ).arg(i18n("user password")), error); + } + + if (PskOK) + if (KvpncDebugLevel > 2) + appendLogEntry(i18n( "write of %1 was successful." ).arg(i18n("preshared key")), debug); + else + { + // if ( KMessageBox::warningContinueCancel( 0, + // i18n( "KVpnc is unable to save %1 password securely in your wallet.
" + // "Do you want to save the password in the unsafe configuration file instead?" ).arg(i18n("pre shared key")), + // i18n( "Unable to store secure %1" ).arg(i18n("pre shared key")), + // KGuiItem( i18n( "Store &Unsafe" ), QString::fromLatin1( "unlock" ),QString::fromLatin1( "KWalletFallbackToKConfig" ) ) ) == KMessageBox::Continue ) + // { + // config->writeEntry( "Pre shared key", it->getPreSharedKey() ); + // } + appendLogEntry(i18n( "write of %1 has failed." ).arg(i18n("preshared key")),error); + } + + if (PskOK) + if (KvpncDebugLevel > 2) + appendLogEntry(i18n( "write of %1 was successful." ).arg(i18n("preshared key")), debug); + else + { + // if ( KMessageBox::warningContinueCancel( 0, + // i18n( "KVpnc is unable to save %1 password securely in your wallet.
" + // "Do you want to save the password in the unsafe configuration file instead?" ).arg(i18n("preshared key password")), + // i18n( "Unable to store secure %1" ).arg(i18n("reshared key password")), + // KGuiItem( i18n( "Store &Unsafe" ), QString::fromLatin1( "unlock" ),QString::fromLatin1( "KWalletFallbackToKConfig" ) ) ) == KMessageBox::Continue ) + // { + // config->writeEntry( "Pre shared key", it->getPreSharedKey() ); + // } + appendLogEntry(i18n( "write of %1 has failed." ).arg(i18n("preshared key")),error); + } + if (PskKeyPassOK) + if (KvpncDebugLevel > 2) + appendLogEntry(i18n( "write of %1 was successful." ).arg(i18n("preshared key password")), debug); + else + { + // if ( KMessageBox::warningContinueCancel( 0, + // i18n( "KVpnc is unable to save %1 password securely in your wallet.
" + // "Do you want to save the password in the unsafe configuration file instead?" ).arg(i18n("preshared key password")), + // i18n( "Unable to store secure %1" ).arg(i18n("reshared key password")), + // KGuiItem( i18n( "Store &Unsafe" ), QString::fromLatin1( "unlock" ),QString::fromLatin1( "KWalletFallbackToKConfig" ) ) ) == KMessageBox::Continue ) + // { + // config->writeEntry( "Pre shared key", it->getPreSharedKey() ); + // } + appendLogEntry(i18n( "write of %1 has failed." ).arg(i18n("preshared key password")),error); + } + //std::cout << "success: " << pwdOK << std::endl; + } +// appPointer->processEvents(); +// wallet->sync(); + } + else + { + KMessageBox::error( 0, i18n( "Unable to create wallet folder for kvpnc!" ) ); + appendLogEntry(i18n( "Unable to create wallet folder for kvpnc!" ), error); + } + } + } + else //sessionSaving neither writing to wallet nor to config-file + { + if (KvpncDebugLevel > 2) + appendLogEntry(i18n( "Writing into Wallet is not possible at shutdown, skipping." ),debug); + } + } + else + { + //Wallet not available + //if (!useKwallet) + { + if (KvpncDebugLevel > 2) + appendLogEntry(i18n( "Wallet disabled or not available, writing to config file." ),debug); + // write passwords to config file :| + if ( it->getSaveUserPassword() ) + { + config->writeEntry( "User password", it->getUserPassword() ); + } + if ( it->getSavePsk() ) + { + config->writeEntry( "Pre shared key", it->getPreSharedKey() ); + } + config->writeEntry( "PrivateKey password", it->getPrivateKeyPass() ); + } + } + +// appPointer->processEvents(); + +// KMessageBox::information(0,"connection type changed: "+QString().setNum(it->getConnectionType())+QString(" ")+it->getName(),QString("type set")); + + // normal config + if ( it->getConnectionType() == VpnAccountData::cisco ) + config->writeEntry( "Connection type", "cisco" ); + else if ( it->getConnectionType() == VpnAccountData::ciscoorig ) + config->writeEntry( "Connection type", "ciscoorig" ); + else if ( it->getConnectionType() == VpnAccountData::racoon ) + config->writeEntry( "Connection type", "racoon" ); + else if ( it->getConnectionType() == VpnAccountData::l2tpd_racoon ) + config->writeEntry( "Connection type", "l2tpd (racoon)" ); + else if ( it->getConnectionType() == VpnAccountData::freeswan ) + config->writeEntry( "Connection type", "freeswan" ); + else if ( it->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + config->writeEntry( "Connection type", "l2tpd (openswan)" ); + else if ( it->getConnectionType() == VpnAccountData::pptp ) + config->writeEntry( "Connection type", "pptp" ); + else if ( it->getConnectionType() == VpnAccountData::openvpn ) + config->writeEntry( "Connection type", "openvpn" ); + else if ( it->getConnectionType() == VpnAccountData::vtun ) + config->writeEntry( "Connection type", "vtun" ); + else if ( it->getConnectionType() == VpnAccountData::ssh ) + config->writeEntry( "Connection type", "ssh" ); + else + config->writeEntry( "Connection type", "other" ); + config->writeEntry( "VPN Gateway", it->getGateway() ); + config->writeEntry( "VPN ID", it->getID() ); + config->writeEntry( "Username", it->getUserName() ); + + config->writeEntry( "Save user password", it->getSaveUserPassword() ); + config->writeEntry( "Save PSK", it->getSavePsk() ); + config->writeEntry( "Save private key password", it->getSavePrivateKeyPassword() ); + config->writeEntry( "Private key", it->getPrivateKey() ); + config->writeEntry( "Use advanced settings", it->getUseAdvancedSettings() ); + config->writeEntry( "Application version", it->getApplicationVersion() ); + config->writeEntry( "Local port", it->getLocalPort() ); + config->writeEntry( "Remote port", it->getRemotePort() ); + config->writeEntry( "NT domain name", it->getNtDomainName() ); + config->writeEntry( "Perfect forward secrety", it->getPerfectForwardSecrety() ); + config->writeEntry( "IKE group", it->getIkeGroup() ); + + config->writeEntry( "Use application version", it->getUseApplicationVersion() ); + config->writeEntry( "Use global IPSec secret", it->getUseGlobalIpsecSecret() ); + config->writeEntry( "Use IKE group", it->getUseIkeGroup() ); + config->writeEntry( "Use local port", it->getUseLocalPort() ); + config->writeEntry( "Use remote port", it->getUseRemotePort() ); + config->writeEntry( "Use NT domain name", it->getUseNtDomainName() ); + config->writeEntry( "Use single DES", it->getUseSingleDes() ); + config->writeEntry( "Use perfect Forward Secrety", it->getUsePerfectForwardSecrety() ); + config->writeEntry( "Remote net address", it->getRemoteNetAddr() ); + config->writeEntry( "Remote net mask", it->getRemoteNetMask() ); + + config->writeEntry( "x509 certificate", it->getX509Certificate() ); + config->writeEntry( "Ca certificate", it->getCaCertificate() ); + config->writeEntry( "Network device", it->getNetworkDevice() ); + config->writeEntry( "Cert path", it->getCertPath() ); + +// // fix bad type +// if ((it->getConnectionType() == VpnAccountData::pptp || it->getConnectionType() == VpnAccountData::openvpn || it->getConnectionType() == VpnAccountData::racoon || it->getConnectionType() == VpnAccountData::l2tpd_racoon || it->getConnectionType() == VpnAccountData::freeswan || it->getConnectionType() == VpnAccountData::l2tpd_freeswan || it->getConnectionType() == VpnAccountData::vtun) && ( it->getAuthType() != "cert" || it->getAuthType() != "psk")) +// { +// it->setAuthType( VpnAccountData::cert); +// } + + if ( it->getAuthType() == VpnAccountData::cert ) + config->writeEntry( "Auth type", "cert" ); + else if ( it->getAuthType() == VpnAccountData::psk ) + config->writeEntry( "Auth type", "psk" ); + else if ( it->getAuthType() == VpnAccountData::hybrid ) + config->writeEntry( "Auth type", "hybrid" ); + else + config->writeEntry( "Auth type", "unknownauth" ); + + config->writeEntry( "do ping ip", it->getDoPingIP() ); + config->writeEntry( "Ping host IP", it->getPingHostIP() ); + +// appPointer->processEvents(); + + config->writeEntry( "Use special remote ID", it->getUseSpecialRemoteID() ); + config->writeEntry( "Use special local ID", it->getUseSpecialLocalID() ); + config->writeEntry( "Special server certificate", it->getSpecialServerCertificate() ); + config->writeEntry( "Use special server certificate", it->getUseSpecialServerCertificate() ); + config->writeEntry( "Special remote ID", it->getSpecialRemoteID() ); + config->writeEntry( "Special local ID", it->getSpecialLocalID() ); + config->writeEntry( "Local ID type", it->getLocalIDType() ); + config->writeEntry( "Remote ID type", it->getRemoteIDType() ); + config->writeEntry( "Use UDP-protocol", it->getUseUdp() ); + config->writeEntry( "Use UDP-port", it->getUseUdpPort() ); + config->writeEntry( "local UDP port", it->getUdpPort() ); + config->writeEntry( "use DNS_UPDATE", it->getUseDnsUpdate() ); + config->writeEntry( "use DNS-server", it->getUseDnsServer() ); + config->writeEntry( "DNS server", it->getDnsServer() ); + config->writeEntry( "refuse 40 bit encryption", it->getRefuse40BitEncryption() ); + config->writeEntry( "refuse 128 bit encryption", it->getRefuse128BitEncryption() ); + config->writeEntry( "require stateless encryption", it->getAllowStatefulMode() ); + config->writeEntry( "require mppe", it->getRequireMppe() ); + config->writeEntry( "Disable MPPE compression", it->getDisableMPPEComp() ); + config->writeEntry( "Local virtual IP", it->getLocalVirtualIP() ); + config->writeEntry( "Remote virtual IP", it->getRemoteVirtualIP() ); + config->writeEntry( "Pre shared key file", it->getPreSharedKeyFile() ); + config->writeEntry( "Execute command before connect", it->getExecuteCmdBeforeConnect() ); + config->writeEntry( "Execute command after connect", it->getExecuteCmdAfterConnect() ); + config->writeEntry( "Execute command before disconnect", it->getExecuteCmdBeforeDisconnect() ); + config->writeEntry( "Execute command after disconnect", it->getExecuteCmdAfterDisconnect() ); + config->writeEntry( "Command before connect", it->getCommandBeforeConnect() ); + config->writeEntry( "Command after connect", it->getCommandAfterConnect() ); + config->writeEntry( "Command before disconnect", it->getCommandBeforeDisconnect() ); + config->writeEntry( "Command after disconnect", it->getCommandAfterDisconnect() ); + config->writeEntry( "Use no BSD compression", it->getUseNoBsdComp() ); + config->writeEntry( "Do not use no IP by default", it->getUseNoIpDefault()); + config->writeEntry( "Use no deflate", it->getUseNoDeflate() ); + config->writeEntry( "Replace default route", it->getReplaceDefaultRoute() ); + config->writeEntry( "Use own MTU", it->getUseMtu() ); + config->writeEntry( "Use own MRU", it->getUseMru() ); + config->writeEntry( "MTU for pppd", it->getMtu() ); + config->writeEntry( "MRU for pppd", it->getMru() ); + config->writeEntry( "Use virtual IP", it->getUseVirtualIP() ); + config->writeEntry( "Virtual IP", it->getVirtualIP() ); + config->writeEntry( "PSK is in file", it->getPskIsInFile() ); + config->writeEntry( "Use additional network routes", it->getUseAdditionalNetworkRoutes() ); + config->writeEntry( "Hash algorithm", it->getHashAlgo() ); + config->writeEntry( "Encryption algorithm", it->getEncryptionAlgorithm() ); + config->writeEntry( "Authentication algorithm", it->getAuthenticationAlgorithm() ); + config->writeEntry( "Tunnel device type", it->getTunnelDeviceType() ); + config->writeEntry( "Use userdefined port", it->getUseUserdefinedPort() ); + config->writeEntry( "Userdefined port", it->getUserdefinedPort() ); + config->writeEntry( "NS cert type", it->getNsCertType() ); + config->writeEntry( "Use NS cert type", it->getUseNsCertType() ); + config->writeEntry( "Use connection status check", it->getUseConnectionStatusCheck() ); + config->writeEntry( "Connection check success count", it->getConnectionStatusCheckSuccessCount() ); + config->writeEntry( "Connection check status interval", it->getConnectionStatusInterval() ); + config->writeEntry( "Do reconnect after connection lost", it->getDoReconnectAfterConnectionLost()); + config->writeEntry( "Disable LZO compression", it->getDisableLzoCompression()); + config->writeEntry( "AuthWithUsernameAndPassword", it->getAuthWithUsernameAndPassword() ); + config->writeEntry( "AllowEmptyGroupPassword", it->getAllowEmptyGroupPassword() ); + config->writeEntry( "Use userdefinied cipher", it->getUseUserdefiniedCipher() ); + config->writeEntry( "Userdefinied cipher", it->getUserdefiniedCipher() ); + config->writeEntry( "Use redirect gateway", it->getUseRedirectGateway() ); +// appPointer->processEvents(); + config->writeEntry( "Use TLS auth", it->getUseTlsAuth() ); + config->writeEntry( "TLS auth file", it->getTlsAuthFile() ); + config->writeEntry( "Use HTTP proxy", it->getUseHttpProxy() ); + config->writeEntry( "HTTP proxy host", it->getHttpProxy() ); + config->writeEntry( "HTTP proxy port", it->getHttpProxyPort() ); + config->writeEntry( "HTTP proxy timeout", it->getHttpProxyTimeout() ); + config->writeEntry( "Dont save username", it->getDontSaveUsername() ); + config->writeEntry( "Use mode config", it->getUseModeConfig() ); + config->writeEntry( "Exchange mode", it->getExchangeMode() ); + config->writeEntry( "Use delay at reconnect", it->getUseReconnectDelay() ); + config->writeEntry( "Reconnect delay", it->getReconnectDelay() ); + config->writeEntry( "Use TLS host", it->getUseTlsRemoteHost() ); + config->writeEntry( "TLS remote host", it->getTlsRemoteHost() ); + config->writeEntry( "Disable opportunistic encryption", it->getDisableOpportunisticEncryption() ); + config->writeEntry( "Right next hop", it->getRightNextHop() ); + config->writeEntry( "Left next hop", it->getLeftNextHop() ); + config->writeEntry( "Use userdefinied packet size for fragmentation", it->getUseFragment() ); + config->writeEntry( "Use userdef packet size", it->getUseMssfix() ); + config->writeEntry( "Fragment", it->getFragment() ); + config->writeEntry( "PeerTimeout", it->getPeerTimeout() ); + config->writeEntry("Disable CCP", it->getDisableCcp() ); + config->writeEntry("Use smartcard", it->getUseSmartcard() ); + config->writeEntry("Use Xauth interactive", it->getUseXauthInteractive() ); + config->writeEntry("Use HTTP Proxy Authentication", it->getUseHttpProxyAuth() ); + config->writeEntry("HTTP Proxy Authtype", it->getHttpProxyAuthType() ); + config->writeEntry("Use HTTP Proxy Auth user", it->getHttpProxyUser() ); + config->writeEntry("Use HTTP Proxy Auth pass", it->getHttpProxyPass() ); + config->writeEntry("Use only CA cert and user auth", it->getUseOnlyCaCertAndUserAuth() ); + config->writeEntry("Use mail address as identifier", it->getUseMailAddressAsIdentifier() ); + config->writeEntry("Use right next hop", it->getUseRightNextHop() ); + config->writeEntry("Use left next hop", it->getUseLeftNextHop() ); + config->writeEntry("Pkcs11 providers", it->getPkcs11Providers() ); + config->writeEntry("Pkcs11 slot type", it->getPkcs11SlotType() ); + config->writeEntry("Pkcs11 slot", it->getPkcs11Slot() ); + config->writeEntry("Pkcs11 id type", it->getPkcs11IdType() ); + config->writeEntry("Pkcs11 id", it->getPkcs11Id() ); + config->writeEntry("Pkcs11 sign mode", it->getPkcs11SignMode() ); + config->writeEntry("Use Pkcs11 providers", it->getUsePkcs11Providers() ); + config->writeEntry("Allow empty private key password", it->getAllowEmptyPrivateKeyPassword()); + config->writeEntry("Allow ip address change of peer", it->getAllowIpAddressChangeOfPeer()); + config->writeEntry("Auth method", it->getAuthMethod()); + config->writeEntry("Command after connect delay time", it->getCommandAfterConnectDelayTime()); + config->writeEntry("Use search domain in resolv conf",it->getUseSearchDomainInResolvConf()); + config->writeEntry("Use domain in resolv conf",it->getUseDomainInResolvConf()); + config->writeEntry("Search domain in resolv conf",it->getSearchDomainInResolvConf()); + config->writeEntry("Domain in resolv conf",it->getDomainInResolvConf()); + config->writeEntry("Authentication direction",it->getAuthenticationDirection()); + config->writeEntry("CiscoNatMode", it->getCiscoNatMode()); + config->writeEntry("IPSec ESP",it->getIpsecEsp()); + config->writeEntry("IPSec IKE",it->getIpsecIke()); + config->writeEntry("Vtun profile",it->getVtunProfile()); + config->writeEntry("Disable data encryption", it->getDisableDataEncryption()); + config->writeEntry("Use authentication algorithm", it->getUseAuthenticationAlgorithm()); + config->writeEntry("Fix path mtu discovery problem" , it ->getFixPathMtuDiscoveryProblem()); + config->writeEntry("Use remote network", it->getUseRemoteNetwork()); + config->writeEntry("Ipsec vpn mode", it->getIpsecVpnMode()); + config->writeEntry("DisableHeaderCompression",it->getDisableHeaderCompression()); + config->writeEntry("DisableMagicNumberNegotiation",it->getDisableMagicNumberNegotiation()); + config->writeEntry("DisableIpx",it->getDisableIpx()); + config->writeEntry("Disable protocol field compression",it->getDisableProtocolFieldCompression()); + config->writeEntry("Disable adress control compression",it->getDisableAdressControlCompression()); + config->writeEntry("Use custom ike",it->getUseCustomIke()); + config->writeEntry("Use custom esp",it->getUseCustomEsp()); + config->writeEntry("Verify ca cert",it->getVerifyCaCert()); + config->writeEntry("Use DPD idle timeout",it->getUseDpdIdleTimeout()); + config->writeEntry("DPD idle timeout",it->getDpdIdleTimeout()); + config->writeEntry("Hide group password in accountdata dialog",it->getHideGroupPasswordInAccountDataDialog()); + config->writeEntry("MaxConnectTries",it->getMaxConnectTries()); + config->writeEntry("L2tpDaemon",it->getL2tpDaemon()); + config->writeEntry("UseLeftSourceIp",it->getUseLeftSourceIp()); + config->writeEntry("UseRightSourceIp",it->getUseRightSourceIp()); + config->writeEntry("LeftSourceIp",it->getLeftSourceIp()); + config->writeEntry("RightSourceIp",it->getRightSourceIp()); + config->writeEntry("Use virtual subnets",it->getUseVirtualSubnetworks()); + config->writeEntry("Virtual subnets", it->getVirtualSubnetworks()); + config->writeEntry("DisablePushFromServer", it->getDisablePushFromServer()); + config->writeEntry("DisableBind", it->getDisableBind()); + config->writeEntry("UseRenegSec", it->getUseRenegSec()); + config->writeEntry("RenegSec", it->getRenegSec()); + config->writeEntry("UseTunnelPing", it->getUseTunnelPing()); + config->writeEntry("TunnelPing", it->getTunnelPing()); + config->writeEntry("UseTunnelPingRestart", it->getUseTunnelPingRestart()); + config->writeEntry("TunnelPingRestart", it->getTunnelPingRestart()); + config->writeEntry("RequireEap", it->getRequireEap()); + config->writeEntry("UseSshConfigRemoteScript", it->getUseSshConfigRemoteScript()); + config->writeEntry("SshConfigRemoteScript", it->getSshConfigRemoteScript()); + config->writeEntry("AskUserPasswordOnEachConnect", it->getAskUserPasswordOnEachConnect()); + config->writeEntry("UseCiscoCertStore", it->getUseCiscoCertStore()); + config->writeEntry("UseNat", it->getUseNat()); + +// appPointer->processEvents(); + + QString AdditionalNetworkRoutesString; + QStringList AdditionalNetworkRoutes = it->getAdditionalNetworkRoutes(); + + // Networks delimited by a ',' + for ( QStringList::Iterator it2 = AdditionalNetworkRoutes.begin(); it2 != AdditionalNetworkRoutes.end(); ++it2 ) + { + AdditionalNetworkRoutesString+=*it2; + AdditionalNetworkRoutesString+=","; + } + AdditionalNetworkRoutesString=AdditionalNetworkRoutesString.left(AdditionalNetworkRoutesString.length()-1); + config->writeEntry( "Additional network routes", AdditionalNetworkRoutesString ); + +// wallet->sync(); + /* give info */ +// slotStatusMsg ( i18n( "Profile \"%1\" saved." ).arg( ProfileName.remove("Profile_") ), ID_FLASH_MSG ); + + appendLogEntry ( i18n( "Profile \"%1\" saved." ).arg( ProfileName.remove("Profile_") ) , info); +// appPointer->processEvents(); + } + appPointer->processEvents(); + } + } + + +// if ( !skipKwalletStoring && wallet != 0) +// if (useKwallet && KWallet::Wallet::isEnabled()) +// if (wallet->isOpen()) +// wallet->sync(); + config->sync(); + doBackupConfig(); + + slotStatusMsg ( i18n( "Profiles saved." ) , ID_FLASH_MSG ); + appPointer->processEvents(); +} + +void KVpncConfig::loadOptions() +{ + config->setGroup( "Notification Messages" ); + hideOnCloseInfo = config->readBoolEntry( "hideOnCloseInfo" ,false); + + config->setGroup( "General Options" ); + minimizeAfterConnect = config->readBoolEntry( "Minimize after connect", true ); + hideMainWindow = config->readBoolEntry("Hide on startup", false ); + useSilentQuit = config->readBoolEntry( "Use silent quit", false ); + dontQuitOnCloseEvent = config->readBoolEntry( "Dont quit on CloseEvent", true ); + showDebugConsole = config->readBoolEntry( "Show debugconsole", true ); + enableDebugPppd = config->readBoolEntry( "Enable pppd debug", false ); + enableDebugPptpd = config->readBoolEntry( "Enable pptpd debug", false ); + enableFreeswanVerbose = config->readBoolEntry( "Enable FreeSWAN verbose", false ); + PlutoDebug = QStringList::split(" ", config->readEntry( "Pluto Debug", "")); + KlipsDebug = QStringList::split(" ", config->readEntry( "Klips Debug", "")); + Vpnc_pid_file = config->readEntry( "Pid file for vpnc ", "/var/run/vpnc/pid" ); + RacoonDebugLevel = config->readEntry( "Racoon debuglevel", "info" ); + // we need to correct old int value + if (RacoonDebugLevel == "0") + RacoonDebugLevel="info"; + if (RacoonDebugLevel != "info" && RacoonDebugLevel != "debug" && RacoonDebugLevel != "debug2" ) + RacoonDebugLevel = "info"; + + VpncDebugLevel = config->readNumEntry( "Vpnc debuglevel", 0 ); + KvpncDebugLevel = config->readNumEntry( "Kvpnc debuglevel", 0 ); + PppdDebugLevel = config->readBoolEntry( "Pppd debuglevel", false ); + PppdKernelLogLevel = config->readNumEntry( "Pppd kernel log level", 0 ); + OpenvpnDebugLevel = config->readNumEntry( "Openvpn debuglevel", 0 ); + PptpLogLevel = config->readNumEntry( "Pptp debuglevel", 1 ); + SshDebugLevel = config->readNumEntry( "ssh debuglevel", 1 ); + enableDebugL2tpd = config->readBoolEntry( "enable l2tpd debug", false ); + enableDebugXl2tpd = config->readBoolEntry( "Enable xl2tpd debug", false ); + enableDebugOpenl2tp = config->readBoolEntry( "Enable openl2tp debug", false ); + + enableDebugXl2tpdNetwork = config->readBoolEntry("EnableDebugXl2tpdNetwork",false); + enableDebugXl2tpdpacket = config->readBoolEntry("EnableDebugXl2tpdpacket",false); + enableDebugXl2tpdstate = config->readBoolEntry("EnableDebugXl2tpdstate",false); + enableDebugXl2tpdtunnel = config->readBoolEntry("EnableDebugXl2tpdtunnel",false); + + + pathToVpnc = config->readEntry( "Path to vpnc-bin", "/usr/sbin/vpnc" ); + pathToCiscoVpnc = config->readEntry( "Path to vpnclient", "/usr/local/bin/vpnclient" ); + pathToSetkey = config->readEntry( "Path to setkey", "/usr/sbin/setkey" ); + pathToRacoon = config->readEntry( "Path to racoon", "/usr/sbin/racoon" ); + pathToRacoonctl = config->readEntry( "Path to racoonctl", "/usr/sbin/racoonctl" ); + pathToIptables = config->readEntry( "Path to iptables", "/sbin/iptables" ); + pathToOpenssl = config->readEntry( "Path to openssl", "/usr/bin/openssl" ); + pathToIpsec = config->readEntry( "Path to freeswan", "/usr/sbin/ipsec" ); + pathToIp = config->readEntry( "Path to iputility", "/sbin/ip" ); + pathToIfconfig = config->readEntry( "Path to ifconfig", "/sbin/ifconfig" ); + pathToRoute = config->readEntry( "Path to route", "/sbin/route" ); + pathToNetstat = config->readEntry( "Path to netstat", "/bin/netstat" ); + pathToPppd = config->readEntry ("Path to pppd","/usr/sbin/pppd"); + pathToPptp = config->readEntry ("Path to pptp","/usr/sbin/pptp"); + pathToL2tpd = config->readEntry ("Path to l2tpd","/usr/sbin/l2tpd"); + pathToXl2tpd = config->readEntry ("Path to xl2tpd","/usr/sbin/xl2tpd"); + pathToOpenl2tp = config->readEntry ("Path to openl2tp","/usr/sbin/openl2tpd"); + pathToKill = config->readEntry ("Path to kill","/bin/kill"); + pathToKillall = config->readEntry ("Path to kill-all","/usr/bin/killall"); + pathToPing = config->readEntry ("Path to ping","/bin/ping"); + pathToOpenvpn = config->readEntry ("Path to openvpn","/usr/sbin/openvpn"); + pathToPkcs11Tool = config->readEntry( "Path to pkcs11-tool", "/usr/bin/pkcs11-tool" ); + pathToVtund = config->readEntry( "Path to vtund", "/usr/sbin/vtund" ); + pathToCiscoCertMgr = config->readEntry( "Path to cisco_cert_mgr","/usr/local/bin/cisco_cert_mgr"); + pathToTail = config->readEntry( "Path to tail","/usr/bin/tail"); + pathToSsh = config->readEntry( "Path to ssh","/usr/bin/ssh"); + pathToKsshAskpass = config->readEntry( "Path to ksshaskpass","/usr/bin/ksshaskpass"); + pathToGnomeSshAskpass = config->readEntry( "Path to ssh-askpass-gnome","/usr/lib/openssh/gnome-ssh-askpass"); + + checkStandardPathValues(); + + tryConnectTimeout = QString( config->readEntry( "Try connect timeout", "10" ) ).toInt(); + lastProfile = config->readEntry( "Last Profile", "" ); + writeLogFile = config->readBoolEntry( "Write log file", true ); + holdGeneratedScripts = config->readBoolEntry( "Hold generated scripts", true ); + showStatusBar = config->readBoolEntry( "Show Statusbar", true ); + programsInPath = config->readBoolEntry( "Programs in path", true ); + + if (programsInPath) + useDefaultPaths=true; + + InfoLogColor = config->readColorEntry ( "Info logwindow color", new QColor(Qt::black) ); + RemoteLogColor = config->readColorEntry ( "Remote logwindow color", new QColor(Qt::blue) ); + ErrorLogColor = config->readColorEntry( "Error logwindow color", new QColor(Qt::red )); + SuccessLogColor = config->readColorEntry( "Success logwindow color", new QColor(Qt::darkGreen) ); + DebugLogColor = config->readColorEntry( "Debug logwindow color", new QColor(255,175,0 )); + DebugBackgroundcolor = config->readColorEntry("Debug background color", new QColor (Qt::white) ); + useColorizedLogOutput = config->readBoolEntry("Use colorized log output", true); + showInterfaceIPinTooltip = config->readBoolEntry( "Show interface IP in tooltip", true ); + AutoConnectProfile= config->readEntry( "Auto connect profile", "" ); + doAutoConnectAtStartup = config->readBoolEntry( "Do auto connect at startup", false ); + LogViewerFontSize = config->readNumEntry( "Log viewer font size", 2 ); + + WindowSize = QSize( config->readNumEntry( "Mainwindow width", 50 ), this->config->readNumEntry( "Mainwindow height", 50 ) ); + WindowPos = QPoint ( config->readNumEntry( "Mainwindow position x", 10 ), this->config->readNumEntry( "Mainwindow position y", 50 ) ); + + OpenvpnManagementPort = config->readNumEntry("Openvpn management port", 2222 ); + + appPointer->processEvents(); + + if ( writeLogFile ) + if ( !logfile.isOpen() ) + { + KStandardDirs *dirs = KGlobal::dirs(); + + QDir AppFolder (QString(dirs->saveLocation( "data" )+"/kvpnc")); + if (!AppFolder.exists()) + { + // KMessageBox::error( this, i18n( "creating dir: %1" ).arg(dirs->saveLocation( "data" )+"/kvpnc" )); + QDir AppFolder2(dirs->saveLocation( "data" )); + if(!AppFolder2.mkdir("kvpnc",true)) + { + KMessageBox::error( 0, i18n( "The appdir for kvpnc could not be created. Be sure that you have write permission of \"%1\"." ).arg(dirs->saveLocation( "data" )) ); + appendLogEntry( i18n( "The appdir for kvpnc could not be created. Be sure that you have write permission of \"%1\"." ).arg(dirs->saveLocation( "data" )),error); + } + } + + logfileName = dirs->saveLocation( "data" ); + logfileName += "/kvpnc/kvpnc.log"; + //KMessageBox::information( this, logfileName, "info" ); + logfile.setName( logfileName ); + if ( !logfile.open( IO_WriteOnly | IO_Append ) ) + { + KMessageBox::error( 0, i18n( "Log file cant be opened!" ) ); + appendLogEntry(i18n( "Unable to find \"%1\"!" ).arg("pppd"),error); + } + else + { + QTextStream s( &logfile ); + s << i18n( "Log session started at: " ) << QDateTime::currentDateTime().toString( Qt::TextDate ) << endl; + } + } + + useKwallet = config->readBoolEntry("Use KWallet", true); + firstUseOfKwallet = config->readBoolEntry( "First use of Kwallet", true ); + feedbackMailSent = config->readBoolEntry("FeedbackMailSent",false); + doKillL2tpdIfStillRunning = config->readBoolEntry("Do kill l2tpd if still running",true); + doKillXl2tpdIfStillRunning = config->readBoolEntry("Do kill xl2tpd if still running",true); + doKillRacoonIfStillRunning = config->readBoolEntry("Do kill racoon if still running",true); + showConnectionTimeInTooltip = config->readBoolEntry("Show connection time in Tooltip",true); + enableDebugOpenvpn = config->readBoolEntry("Enable debug Openvpn",false); + + + + if ( KvpncDebugLevel > 2 ) + appendLogEntry( i18n( "Global configuration loaded." ) ,info); + + + /* = user data = */ + /* old style: one profile: will be removed in future */ + /* + config->setGroup( "Client Options" ); + this->mw->gatewayLineEdit->setText( config->readEntry( "VPN Gateway", "" ) ); + this->mw->IDLineEdit->setText( config->readEntry( "VPN ID", "" ) ); + this->mw->PSKLineEdit->setText( config->readEntry( "Group password", "" ) ); + this->mw->UsernameLineEdit->setText( config->readEntry( "Username", "" ) ); + this->mw->PasswordEdit->setText( config->readEntry( "Password", "" ) ); + + this->mw->CheckUserPass->setChecked( config->readBoolEntry( "Save user password", false ) ); + this->mw->CheckGroupPass->setChecked( config->readBoolEntry( "Save group password", false ) ); + */ + + /* profiles are stored in a group which is named to the following scheme: + Profile_XXXXX + XXXXX is the account name (important: unique!) + */ + QStringList configGroups = config->groupList(); + bool oldConfigurationFound = false; + + bool sessionFound = false; + + for ( QStringList::Iterator it = configGroups.begin(); it != configGroups.end(); ++it ) + { + QString name = *it; + name.stripWhiteSpace(); + if ( name.left( 7 ) == "Profile" && name.length() > 8 ) + { + // Profile found + + sessionFound = true; + + if ( KvpncDebugLevel > 2 ) + { + QString tmp = i18n( "Profile found: " ); + tmp += name.right( ( name.length() ) - 8 ); + appendLogEntry ( tmp, debug ); + } + config->setGroup( name ); + QString UserPassword=""; + QString PrivateKeyPass=""; + QString PreSharedKey =""; + + /* passwords with kwallet */ + if (useKwallet && KWallet::Wallet::isEnabled()) + { + if (KvpncDebugLevel > 2) + appendLogEntry(i18n( "Wallet enabled and available, reading passwords from wallet." ),debug); + // Open local wallet + wallet = KWallet::Wallet::openWallet(KWallet::Wallet::LocalWallet()); + if (wallet != 0) + { + QString walletname="kvpnc"; + + if (!wallet->hasFolder(walletname)) + { + wallet->createFolder(walletname); + wallet->sync(); + } + + if (wallet->setFolder(walletname)) + { + if (KvpncDebugLevel > 2) + appendLogEntry(i18n( "Folder for kvpnc has been set." ),debug); + + QString profilename = name.right( ( name.length() ) - 8 ); + + if (wallet->readPassword(QString(profilename+"__user_pw"), UserPassword) != 0) + appendLogEntry(i18n( "read of %1 has failed." ).arg(i18n("user password")),error); + else + if (KvpncDebugLevel > 2) + appendLogEntry(i18n( "read of %1 was successful." ).arg(i18n("user password")),debug); + + if (wallet->readPassword(QString(profilename+"__psk"), PreSharedKey) != 0) + appendLogEntry(i18n( "read of %1 has failed." ).arg(i18n("preshared key")),error); + else + if (KvpncDebugLevel > 2) + appendLogEntry(i18n( "read of %1 was successful." ).arg(i18n("preshared key")),debug); + + if (wallet->readPassword(QString(profilename+"__priv_key_pwd"), PrivateKeyPass) != 0) + appendLogEntry(i18n( "read of %1 has failed." ).arg(i18n("preshared key password")),error); + else + if (KvpncDebugLevel > 2) + appendLogEntry(i18n( "read of %1 was successful." ).arg(i18n("preshared key password")),debug); + } + else + { + KMessageBox::error( 0, i18n( "Unable to set wallet folder for kvpnc!" ) ); + appendLogEntry(i18n( "Unable to set wallet folder for kvpnc!" ), error); + } + appPointer->processEvents(); + } + else + { + KMessageBox::error( 0, i18n( "Unable to open wallet folder for kvpnc!" ) ); + appendLogEntry(i18n( "Unable to open wallet folder for kvpnc!" ), error); + } + + + } + else + { + if (KvpncDebugLevel > 2) + { + if (useKwallet && KWallet::Wallet::isEnabled() && firstUseOfKwallet) + appendLogEntry(i18n( "Wallet enabled, available but first time, reading passwords from config file." ),debug); + else + appendLogEntry(i18n( "Wallet disabled or not available, reading passwords from config file." ),debug); + } + // read from config file + UserPassword = config->readEntry( "User password", "" ); + PrivateKeyPass = config->readEntry( "PrivateKey password", "" ); + PreSharedKey = config->readEntry( "Pre shared key", "" ); + } + + VpnAccountData::ConnectionType ConnType = VpnAccountData::ConnectionType( VpnAccountData::cisco ); + QString type_string = config->readEntry( "Connection type", "cisco" ); + + if ( type_string == "cisco" ) + ConnType = VpnAccountData::cisco; + else if ( type_string == "ciscoorig" ) + ConnType = VpnAccountData::ciscoorig; + else if ( type_string == "racoon" ) + ConnType = VpnAccountData::racoon; + else if ( type_string == "l2tpd (racoon)" ) + ConnType = VpnAccountData::l2tpd_racoon; + else if ( type_string == "freeswan" ) + ConnType = VpnAccountData::freeswan; + else if ( type_string == "l2tpd (openswan)" ) + ConnType = VpnAccountData::l2tpd_freeswan; + else if ( type_string == "pptp" ) + ConnType = VpnAccountData::pptp; + else if ( type_string == "openvpn" ) + ConnType = VpnAccountData::openvpn; + else if ( type_string == "vtun" ) + ConnType = VpnAccountData::vtun; + else if ( type_string == "ssh" ) + ConnType = VpnAccountData::ssh; + else + ConnType = VpnAccountData::other; + + QString Name = name.right( name.length() - 8 ); + VpnAccountData *data = new VpnAccountData( ConnType, Name ); + data->setGateway( config->readEntry( "VPN Gateway", "" )); + data->setID( config->readEntry( "VPN ID", "" ) ); + data->setDescription( config->readEntry("Description","")); + data->setUserName( config->readEntry( "Username", "" )); + data->setSaveUserPassword( config->readBoolEntry( "Save user password", false )); + data->setSavePsk( config->readBoolEntry( "Save PSK", false )); + data->setSavePrivateKeyPassword( config->readBoolEntry( "Save private key password", true ) ); + data->setUseAdvancedSettings( config->readBoolEntry( "Use advanced settings", false )); + data->setApplicationVersion( config->readEntry( "Application version", "Cisco Systems VPN Client 0.3-rm+zomb.1:Linux" )); + data->setLocalPort( config->readNumEntry( "Local port", 500 )); + data->setRemotePort( config->readNumEntry( "Remote port", 500 )); + data->setNtDomainName( config->readEntry( "NT domain name", "" )); + data->setPerfectForwardSecrety( config->readEntry( "Perfect forward secrety", "server" )); + data->setIkeGroup( config->readEntry( "IKE group", "dh1" )); + data->setUseApplicationVersion( config->readBoolEntry( "Use application version", false )); + data->setUseGlobalIpsecSecret( config->readBoolEntry( "Use global IPSec secret", false )); + data->setUseIkeGroup( config->readBoolEntry( "Use IKE group", false )); + data->setUseLocalPort( config->readBoolEntry( "Use local port", false )); + data->setUseRemotePort( config->readBoolEntry( "Use remote port", false )); + data->setUseNtDomainName( config->readBoolEntry( "Use NT domain name", false )); + data->setUseSingleDes( config->readBoolEntry( "Use single DES", false )); + data->setUsePerfectForwardSecrety( config->readBoolEntry( "Use perfect Forward Secrety", false )); + data->setX509Certificate( config->readEntry( "x509 certificate", "" )); + data->setCaCertificate( config->readEntry( "Ca certificate", "" )); + data->setNetworkDevice( config->readEntry( "Network device", "default" )); + data->setCertPath( config->readEntry( "Cert path", "/etc/racoon/certs" )); + data->setPrivateKey( config->readEntry( "Private key", "" )); + VpnAccountData::AuthenticationType authtype; + if ( config->readEntry( "Auth type", "cert" ) == "cert" ) + authtype = VpnAccountData::cert; + else if ( config->readEntry( "Auth type", "psk" ) == "psk" ) + authtype = VpnAccountData::psk; + else if ( config->readEntry( "Auth type", "cert" ) == "hybrid" ) + authtype = VpnAccountData::hybrid; + else + authtype = VpnAccountData::unknownauth; + data->setAuthType(authtype); + + appPointer->processEvents(); + + data->setDoPingIP( config->readBoolEntry( "do ping ip", false )); + data->setPingHostIP( config->readEntry( "Ping host IP", "" )); + data->setUseSpecialRemoteID( config->readBoolEntry( "Use special remote ID", false )); + data->setUseSpecialLocalID( config->readBoolEntry( "Use special local ID", false )); + data->setSpecialRemoteID( config->readEntry( "Special remote ID", "" )); + data->setSpecialLocalID( config->readEntry( "Special local ID", "" )); + data->setLocalIDType(config->readEntry( "Local ID type", "asn1dn") ); + data->setRemoteIDType(config->readEntry( "Remote ID type", "none") ); + data->setUseSpecialServerCertificate( config->readBoolEntry( "Use special server certificate", false )); + data->setSpecialServerCertificate( config->readEntry( "Special server certificate", "" )); + data->setUseUdp( config->readBoolEntry( "Use UDP-protocol", false )); + data->setUseUdpPort( config->readBoolEntry( "Use UDP-port", false )); + data->setUdpPort( config->readNumEntry( "local UDP port", 4500 )); + data->setUseDnsUpdate( config->readBoolEntry( "use DNS_UPDATE", true)); + data->setUseDnsServer( config->readBoolEntry( "use DNS-server", false)); + data->setDnsServer( config->readEntry( "DNS server", "" )); + data->setRefuse40BitEncryption( config->readBoolEntry( "refuse 40 bit encryption", true )); + data->setRefuse128BitEncryption( config->readBoolEntry( "refuse 128 bit encryption", false )); + data->setAllowStatefulMode( config->readBoolEntry( "require stateless encryption",false )); + data->setRequireMppe( config->readBoolEntry( "require mppe", true )); + data->setUseNoBsdComp( config->readBoolEntry( "Use no BSD compression", true )); + data->setUseNoIpDefault(config->readBoolEntry( "Do not use no IP by default", false)); + data->setUseNoDeflate( config->readBoolEntry( "Use no deflate", true )); + data->setDisableMPPEComp( config->readBoolEntry( "Disable MPPE compression", false )); + data->setLocalVirtualIP( config->readEntry( "Local virtual IP", "" )); + data->setRemoteVirtualIP( config->readEntry( "Remote virtual IP", "" )); + data->setPreSharedKeyFile( config->readEntry( "Pre shared key file", "" )); + data->setExecuteCmdBeforeConnect( config->readBoolEntry( "Execute command before connect",false)); + data->setExecuteCmdAfterConnect( config->readBoolEntry( "Execute command after connect",false)); + data->setExecuteCmdBeforeDisconnect( config->readBoolEntry( "Execute command before disconnect", false)); + data->setExecuteCmdAfterDisconnect( config->readBoolEntry( "Execute command after disconnect", false)); + data->setCommandBeforeConnect( config->readEntry( "Command before connect", "" )); + data->setCommandAfterConnect( config->readEntry( "Command after connect", "" )); + data->setCommandBeforeDisconnect( config->readEntry( "Command before disconnect", "" )); + data->setCommandAfterDisconnect( config->readEntry( "Command after disconnect", "" )); + data->setReplaceDefaultRoute( config->readBoolEntry( "Replace default route", false )); + data->setUseMtu( config->readBoolEntry( "Use own MTU", false )); + data->setUseMru( config->readBoolEntry( "Use own MRU", false )); + data->setMtu( config->readNumEntry( "MTU for pppd", 1492 )); + data->setMru( config->readNumEntry( "MRU for pppd", 1492 )); + data->setUseVirtualIP( config->readBoolEntry( "Use virtual IP", false )); + data->setVirtualIP( config->readEntry( "Virtual IP", "" )); + data->setPskIsInFile( config->readBoolEntry( "PSK is in file", false )); + data->setUseAdditionalNetworkRoutes( config->readBoolEntry( "Use additional network routes", false )); + appPointer->processEvents(); + QString AdditionalNetworkRoutesString = config->readEntry( "Additional network routes", "" ); + // Networks delimited by a ',' + QStringList AdditionalNetworkRoutes(QStringList::split( ",", AdditionalNetworkRoutesString )); + data->setAdditionalNetworkRoutes(AdditionalNetworkRoutes); + data->setHashAlgo( config->readEntry( "Hash algorithm", "md5" )); + data->setEncryptionAlgorithm( config->readEntry( "Encryption algorithm", "3des" )); + data->setAuthenticationAlgorithm( config->readEntry( "Authentication algorithm", "hmac_sha1" )); + data->setTunnelDeviceType( config->readEntry( "Tunnel device type", "tun" )); + data->setUseUserdefinedPort( config->readBoolEntry( "Use userdefined port", false )); + data->setUserdefinedPort( config->readNumEntry( "Userdefined port", 1194 )); + data->setNsCertType( config->readEntry( "NS cert type", "client" )); + data->setUseNsCertType( config->readBoolEntry( "Use NS cert type", false )); + data->setUseConnectionStatusCheck ( config->readBoolEntry( "Use connection status check", true )); + data->setConnectionStatusCheckSuccessCount ( config->readNumEntry( "Connection check success count", 4 )); + data->setConnectionStatusInterval ( config->readNumEntry( "Connection check status interval", 1 )); + data->setDoReconnectAfterConnectionLost(config->readBoolEntry("Do reconnect after connection lost", false)); + data->setDisableLzoCompression(config->readBoolEntry("Disable LZO compression", true)); + data->setUserPassword( UserPassword ); + data->setRemoteNetAddr( config->readEntry("Remote net address","") ); + data->setRemoteNetMask( QString().setNum(config->readNumEntry("Remote net mask",24 ))); + data->setPreSharedKey( PreSharedKey ); + data->setPrivateKeyPass( PrivateKeyPass ); + data->setAuthWithUsernameAndPassword( config->readBoolEntry( "AuthWithUsernameAndPassword",false ) ); + data->setAllowEmptyGroupPassword( config->readBoolEntry( "AllowEmptyGroupPassword", false ) ); + data->setUseUserdefiniedCipher( config->readBoolEntry( "Use userdefinied cipher", false ) ); + data->setUserdefiniedCipher( config->readEntry( "Userdefinied cipher", "" ) ); + appPointer->processEvents(); + data->setUseRedirectGateway( config->readBoolEntry( "Use redirect gateway", false ) ); + data->setUseTlsAuth( config->readBoolEntry( "Use TLS auth", false ) ); + data->setTlsAuthFile( config->readEntry( "TLS auth file", "" ) ); + data->setUseHttpProxy( config->readBoolEntry( "Use HTTP proxy", false ) ); + data->setHttpProxy( config->readEntry( "HTTP proxy host", "" ) ); + data->setHttpProxyPort( config->readNumEntry( "HTTP proxy port", 8080 ) ); + data->setHttpProxyTimeout( config->readNumEntry( "HTTP proxy timeout", 5 ) ); + data->setDontSaveUsername( config->readBoolEntry( "Dont save username", false ) ); + data->setUseModeConfig( config->readBoolEntry( "Use mode config", false ) ); + data->setExchangeMode( config->readEntry( "Exchange mode", "main" ) ); + data->setUseReconnectDelay( config->readBoolEntry( "Use delay at reconnect", false ) ); + data->setReconnectDelay( config->readNumEntry( "Reconnect delay", 5 ) ); + data->setUseTlsRemoteHost( config->readBoolEntry( "Use TLS host", false) ); + data->setTlsRemoteHost( config->readEntry( "TLS remote host", "") ); + data->setDisableOpportunisticEncryption( config->readBoolEntry( "Disable opportunistic encryption", false ) ); + data->setRightNextHop( config->readEntry( "Right next hop", "" ) ); + data->setLeftNextHop( config->readEntry( "Left next hop", "" ) ); + data->setUseMssfix(config->readBoolEntry( "Use userdef packet size", false) ); + data->setUseFragment(config->readBoolEntry( "Use userdefinied packet size for fragmentation" , false) ); + data->setMssfix(config->readNumEntry( "Mssfix", 1300) ); + data->setFragment( config->readNumEntry( "Fragment", 1300) ); + data->setPeerTimeout( config->readNumEntry( "PeerTimeout",0) ); + data->setDisableCcp( config->readBoolEntry("Disable CCP",false) ); + data->setUseSmartcard( config->readBoolEntry("Use smartcard", false) ); + data->setUseXauthInteractive(config->readBoolEntry("Use Xauth interactive", false) ); + data->setUseHttpProxyAuth( config->readBoolEntry("Use HTTP Proxy Authentication", false ) ); + data->setHttpProxyAuthType( config->readEntry("HTTP Proxy Authtype", "basic") ); + data->setHttpProxyUser( config->readEntry("Use HTTP Proxy Auth user", "") ); + data->setHttpProxyPass( config->readEntry("Use HTTP Proxy Auth pass", "") ); + data->setUseOnlyCaCertAndUserAuth(config->readBoolEntry("Use only CA cert and user auth", false) ); + data->setUseMailAddressAsIdentifier(config->readBoolEntry("Use mail address as identifier", false) ); + data->setUseRightNextHop(config->readBoolEntry("Use right next hop", false) ); + data->setUseLeftNextHop(config->readBoolEntry("Use left next hop", false) ); + data->setPkcs11Providers(config->readEntry("Pkcs11 providers", "/usr/local/lib/libetpkcs11.so" ) ); + data->setPkcs11SlotType(config->readEntry("Pkcs11 slot type", "id") ); + data->setPkcs11Slot(config->readEntry("Pkcs11 slot", "0") ); + data->setPkcs11IdType(config->readEntry("Pkcs11 id type", "id") ); + data->setPkcs11Id(config->readEntry("Pkcs11 id","" ) ); + data->setPkcs11SignMode(config->readEntry("Pkcs11 sign mode", "auto") ); + data->setUsePkcs11Providers(config->readBoolEntry("Use Pkcs11 providers", false) ); + data->setAllowEmptyPrivateKeyPassword( config->readBoolEntry("Allow empty private key password", false )); + data->setAllowIpAddressChangeOfPeer(config->readBoolEntry("Allow ip address change of peer", false)); + data->setAuthMethod(config->readEntry("Auth method", "mschap-v2")); + data->setCommandAfterConnectDelayTime(config->readNumEntry("Command after connect delay time", 5)); + data->setUseSearchDomainInResolvConf(config->readBoolEntry("Use search domain in resolv conf",false)); + data->setUseDomainInResolvConf(config->readBoolEntry("Use domain in resolv conf",false)); + data->setSearchDomainInResolvConf(config->readEntry("Search domain in resolv conf","")); + data->setDomainInResolvConf(config->readEntry("Domain in resolv conf","")); + data->setAuthenticationDirection(config->readEntry("Authentication direction","none")); + data->setCiscoNatMode(config->readEntry("CiscoNatMode", "natt")); + data->setIpsecEsp(config->readEntry("IPSec ESP","3des-md5,3des-sha1,aes128-sha1,aes256-sha1")); + data->setIpsecIke(config->readEntry("IPSec IKE","aes256-sha1,aes128-sha1,3des-sha1-modp2048,3des-md5,3des-sha1")); + data->setVtunProfile(config->readEntry("Vtun profile","")); + data->setDisableDataEncryption(config->readBoolEntry("Disable data encryption", false)); + data->setUseAuthenticationAlgorithm(config->readBoolEntry("Use authentication algorithm", false)); + data->setFixPathMtuDiscoveryProblem(config->readBoolEntry("Fix path mtu discovery problem" , false)); + data->setUseRemoteNetwork(config->readBoolEntry("Use remote network",false)); + data->setIpsecVpnMode(config->readEntry("Ipsec vpn mode", "tunnel")); + data->setDisableHeaderCompression(config->readBoolEntry("DisableHeaderCompression",false)); + data->setDisableMagicNumberNegotiation(config->readBoolEntry("DisableMagicNumberNegotiation",false)); + data->setDisableIpx(config->readBoolEntry("DisableIpx",false)); + data->setDisableProtocolFieldCompression(config->readBoolEntry("Disable protocol field compression",false)); + data->setDisableAdressControlCompression(config->readBoolEntry("Disable adress control compression",false)); + data->setUseCustomIke(config->readBoolEntry("Use custom ike",false)); + data->setUseCustomEsp(config->readBoolEntry("Use custom esp",false)); + data->setVerifyCaCert(config->readBoolEntry("Verify ca cert",true)); + data->setUseDpdIdleTimeout(config->readBoolEntry("Use DPD idle timeout",false)); + data->setDpdIdleTimeout(config->readNumEntry("DPD idle timeout",300)); + data->setHideGroupPasswordInAccountDataDialog(config->readBoolEntry("Hide group password in accountdata dialog",false)); + data->setMaxConnectTries(config->readNumEntry("MaxConnectTries",300)); + data->setL2tpDaemon((VpnAccountData::L2tpDaemonType)config->readNumEntry("L2tpDaemon",0)); + data->setUseLeftSourceIp(config->readBoolEntry("UseLeftSourceIp",false)); + data->setUseRightSourceIp(config->readBoolEntry("UseRightSourceIp",false)); + data->setLeftSourceIp(config->readEntry("LeftSourceIp","")); + data->setRightSourceIp(config->readEntry("RightSourceIp","")); + data->setUseVirtualSubnetworks(config->readBoolEntry("Use virtual subnets",false)); + data->setVirtualSubnetworks(config->readEntry("Virtual subnets", "")); + data->setDisablePushFromServer(config->readBoolEntry("DisablePushFromServer",false)); + data->setDisableBind(config->readBoolEntry("DisableBind",false)); + data->setUseRenegSec( config->readBoolEntry("UseRenegSec", false)); + data->setRenegSec(config->readNumEntry("RenegSec", 3600)); + data->setUseTunnelPing(config->readBoolEntry("UseTunnelPing", false)); + data->setTunnelPing(config->readNumEntry("TunnelPing",10)); + data->setUseTunnelPingRestart(config->readBoolEntry("UseTunnelPingRestart", false)); + data->setTunnelPingRestart(config->readNumEntry("TunnelPingRestart", 120)); + data->setRequireEap(config->readBoolEntry("RequireEap", false)); + data->setUseSshConfigRemoteScript(config->readBoolEntry("UseSshConfigRemoteScript", false)); + data->setSshConfigRemoteScript(config->readEntry("SshConfigRemoteScript", "")); + data->setAskUserPasswordOnEachConnect(config->readBoolEntry("AskUserPasswordOnEachConnect", false)); + data->setUseCiscoCertStore( config->readBoolEntry("UseCiscoCertStore", false)); + data->setUseNat(config->readBoolEntry("UseNat", true)); + + appPointer->processEvents(); + AccountList->append( data ); + } + + if ( name == "Client Options" ) + { + // old style configuration found + config->setGroup( "Client Options" ); + QString Name = "Default"; + VpnAccountData::ConnectionType ConnType = VpnAccountData::cisco; + QString Gateway = config->readEntry( "VPN Gateway", "" ); + QString ID = config->readEntry( "VPN ID", "" ); + QString Psk = config->readEntry( "Group password", "" ); + QString Username = config->readEntry( "Username", "" ); + QString UserPassword = config->readEntry( "Password", "" ); + bool saveUserPassword = config->readBoolEntry( "Save user password", false ); + bool savePsk = config->readBoolEntry( "Save group password", false ); + + VpnAccountData *AccData = new VpnAccountData( ConnType, Name); + AccData->setGateway ( Gateway ); + AccData->setID( ID ); + AccData->setPreSharedKey( Psk); + AccData->setUserName( Username ); + AccData->setUserPassword( UserPassword ); + AccData->setSaveUserPassword( saveUserPassword ); + AccData->setSavePsk( savePsk ); + AccData->setLocalPort( 500 ); + AccData->setPerfectForwardSecrety ( "server" ); + AccData->setIkeGroup( "dh1" ); + AccountList->append( AccData ); + + lastProfile = "Default"; + + // now mark for deleting old configuration + oldConfigurationFound = true; + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n( "Old configuration found, converted." ),info ); + + if ( KvpncDebugLevel > 2 ) + appendLogEntry( i18n( "Configuration for profile \"%1\" loaded." ).arg( Name ),info ); + + appPointer->processEvents(); + } + + + } + if ( oldConfigurationFound ) + { + // delete configuration file + KStandardDirs * dirs = KGlobal::dirs(); + QString filePath = dirs->findResource ( "config", "kvpncrc" ); + QFile::remove + ( filePath ); + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n( "Old configuration deleted." ), debug ); + } +} + +void KVpncConfig::checkStandardPathValues() +{ + if (pathToVpnc.isEmpty()) + pathToVpnc = "/usr/sbin/vpnc"; + + if (pathToCiscoVpnc.isEmpty()) + pathToCiscoVpnc = "/usr/local/bin/vpnclient"; + + if (pathToSetkey.isEmpty()) + pathToSetkey = "/usr/sbin/setkey"; + + if (pathToRacoon.isEmpty()) + pathToRacoon = "/usr/sbin/racoon"; + + if (pathToRacoonctl.isEmpty()) + pathToRacoonctl = "/usr/sbin/racoonctl"; + + if (pathToIptables.isEmpty()) + pathToIptables = "/sbin/iptables"; + + if (pathToOpenssl.isEmpty()) + pathToOpenssl = "/usr/bin/openssl"; + + if (pathToIpsec.isEmpty()) + pathToIpsec = "/usr/sbin/ipsec"; + + if (pathToIp.isEmpty()) + pathToIp = "/sbin/ip"; + + if (pathToIfconfig.isEmpty()) + pathToIfconfig = "/sbin/ifconfig"; + + if (pathToRoute.isEmpty()) + pathToRoute = "/sbin/route"; + + if (pathToNetstat.isEmpty()) + pathToNetstat = "/bin/netstat"; + + if (pathToPppd.isEmpty()) + pathToPppd = "/usr/sbin/pppd"; + + if (pathToPptp.isEmpty()) + pathToPptp = "/usr/sbin/pptp"; + + if (pathToL2tpd.isEmpty()) + pathToL2tpd = "/usr/sbin/l2tpd"; + + if (pathToXl2tpd.isEmpty()) + pathToXl2tpd = "/usr/sbin/xl2tpd"; + + if (pathToOpenl2tp.isEmpty()) + pathToOpenl2tp = "/usr/sbin/openl2tpd"; + + if (pathToKill.isEmpty()) + pathToKill = "/bin/kill"; + + if (pathToKillall.isEmpty()) + pathToKillall = "/usr/bin/killall"; + + if (pathToPing.isEmpty()) + pathToPing = "/bin/ping"; + + if (pathToOpenvpn.isEmpty()) + pathToOpenvpn = "/usr/sbin/openvpn"; + + if (pathToPkcs11Tool.isEmpty()) + pathToPkcs11Tool = "/usr/bin/pkcs11-tool"; + + if (pathToVtund.isEmpty()) + pathToVtund = "/usr/sbin/vtund"; + + if (pathToCiscoCertMgr.isEmpty()) + pathToCiscoCertMgr = "/usr/local/bin/cisco_cert_mgr"; + + if (pathToTail.isEmpty()) + pathToTail = "/usr/bin/tail"; + + if (pathToSsh.isEmpty()) + pathToSsh = "/usr/bin/ssh"; + + if (pathToKsshAskpass.isEmpty()) + pathToKsshAskpass = "/usr/bin/ksshaskpass"; + + if (pathToGnomeSshAskpass.isEmpty()) + pathToGnomeSshAskpass = "/usr/lib/openssh/gnome-ssh-askpass"; +} + +bool KVpncConfig::exportKvpncConfig(QString filename) +{ + bool ok=true; + int exportCount=0; + bool exportGlobal=false; + QFile exportfile (filename); + if (exportfile.exists()) + { + int res = KMessageBox::questionYesNo ( 0, i18n ( "\"%1\" still exists. Do you really want to overwrite it?" ).arg ( filename ), i18n ( "Overwrite?" ), i18n("&Overwrite") , KStdGuiItem::cancel() ); + + if (res == 4) + ok=false; + } + if (ok==true) + { + if( exportfile.open(IO_WriteOnly)) + { + QPtrList *exportAccountList = new QPtrList(); + exportAccountList->setAutoDelete( TRUE ); // the list owns the objects + KvpncImportProfileSelectionBase selectdlg; + VpnAccountData *it=NULL; + selectdlg.OpenProfileManagerCheckBox->hide(); + selectdlg.textLabel->setText(i18n("Select profiles for export:")); + selectdlg.ImportPushButton->setText(i18n("&Export selected profiles...")); + selectdlg.ImportGlobalSettingsCheckBox->setText(i18n("export &global settings")); + + if ( !AccountList->isEmpty() ) + { + selectdlg.ImportProfileListView->takeItem(selectdlg.ImportProfileListView->currentItem()); + selectdlg.ImportProfileListView->addColumn(i18n("Name")); + selectdlg.ImportProfileListView->addColumn(i18n("Type")); + selectdlg.ImportProfileListView->addColumn(i18n("Gateway")); + QCheckListItem *item; + for ( it = AccountList->first(); it; it = AccountList->next() ) + { + QString name = it->getName(); + QString type; + if ( it->getConnectionType() == VpnAccountData::cisco ) + type = "cisco" ; + else if ( it->getConnectionType() == VpnAccountData::ciscoorig ) + type = "ciscoorig" ; + else if ( it->getConnectionType() == VpnAccountData::racoon ) + type = "racoon" ; + else if ( it->getConnectionType() == VpnAccountData::l2tpd_racoon ) + type = "l2tpd (racoon)" ; + else if ( it->getConnectionType() == VpnAccountData::freeswan ) + type = "freeswan" ; + else if ( it->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + type = "l2tpd (openswan)" ; + else if ( it->getConnectionType() == VpnAccountData::pptp ) + type = "pptp" ; + else if ( it->getConnectionType() == VpnAccountData::openvpn ) + type = "openvpn" ; + else if ( it->getConnectionType() == VpnAccountData::vtun ) + type = "vtun" ; + else if ( it->getConnectionType() == VpnAccountData::ssh ) + type = "ssh" ; + + else + type = i18n("other"); + + +// litem->setSelectable(true); + item = new QCheckListItem(selectdlg.ImportProfileListView,it->getName(),QCheckListItem::CheckBox); + item->setText(1,type); + item->setText(2,it->getGateway()); + selectdlg.ImportProfileListView->insertItem(item); + +// std::cout << "insert profile into listview: " << name << std::endl; + } + } + bool ret = selectdlg.exec(); + if (ret == true) + { + QListViewItemIterator it2( selectdlg.ImportProfileListView ); + for ( ; it2.current(); ++it2 ) + { + if ( ( (QCheckListItem*)it2.current() )->isOn() ) + { + VpnAccountData *data=NULL; + it = 0; + for ( it = AccountList->first(); it; it = AccountList->next() ) + if ( it->getName() == ( (QCheckListItem*)it2.current() )->text() && ( (QCheckListItem*)it2.current() )->isOn() ) + data = it; + exportAccountList->append(data); + } + } + exportGlobal = selectdlg.ImportGlobalSettingsCheckBox->isChecked(); + if (exportAccountList->count() == 0 && exportGlobal==false) + { + KMessageBox::sorry ( 0, i18n ( "No profiles for export, export canceled." ) ); + exportfile.close(); + exportfile.remove(); + return false; + } + } + else + { + KMessageBox::sorry ( 0, i18n ( "Export canceled." ) ); + exportfile.close(); + exportfile.remove(); + return false; + } + + + + QString date (__DATE__); + QString day= date.section(' ',0,0); + QString month= QString().setNum(QDate::fromString(date.section(' ',0,0),Qt::ISODate).month()); + QString year= date.section(' ',2,2); + + QString currentdate ( date+" "+ QTime().currentTime().toString( "hh:mm" ) ); + + QTextStream ExportStream ( &exportfile ); + ExportStream << "" << "\n"; + ExportStream << "" << "\n"; + ExportStream << "" << "\n"; + ExportStream << "\t" << "\n"; + ExportStream << "\t\t" << "0.9.2" << "" << "\n"; + ExportStream << "\t\t" << "1" << "" << "\n"; + ExportStream << "\t" << "\n"; + + if (exportGlobal == true) + { + ExportStream << "\t" << "\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + // ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t\n"; + ExportStream << "\t\t" << "\n"; + } + + + ExportStream << "\t" << "\n"; +// VpnAccountData *it; + if ( !exportAccountList->isEmpty() ) + { + for ( it = exportAccountList->first(); it; it = exportAccountList->next() ) + { + // std::cout << "export profile: " << it->getName().ascii() << std::endl; + ExportStream << "\t\tgetName() << "\">" << "\n"; + + // normal config + if ( it->getConnectionType() == VpnAccountData::cisco ) + ExportStream << "\t\t\t" << "\n"; + else if ( it->getConnectionType() == VpnAccountData::ciscoorig ) + ExportStream << "\t\t\t" << "\n"; + else if ( it->getConnectionType() == VpnAccountData::racoon ) + ExportStream << "\t\t\t" << "\n"; + else if ( it->getConnectionType() == VpnAccountData::l2tpd_racoon ) + ExportStream << "\t\t\t" << "\n"; + else if ( it->getConnectionType() == VpnAccountData::freeswan ) + ExportStream << "\t\t\t" << "\n"; + else if ( it->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + ExportStream << "\t\t\t" << "\n"; + else if ( it->getConnectionType() == VpnAccountData::pptp ) + ExportStream << "\t\t\t" << "\n"; + else if ( it->getConnectionType() == VpnAccountData::openvpn ) + ExportStream << "\t\t\t" << "\n"; + else + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + if ( it->getAuthType() == VpnAccountData::cert ) + ExportStream << "\t\t\t" << "\n"; + if ( it->getAuthType() == VpnAccountData::psk ) + ExportStream << "\t\t\t" << "\n"; + if ( it->getAuthType() == VpnAccountData::hybrid ) + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + ExportStream << "\t\t\t" << "\n"; + + ExportStream << "\t\t" << "\n"; + exportCount++; + } + + } + ExportStream << "\t" << "\n"; + ExportStream << "" << "\n"; + exportfile.close(); + } + else + { + KMessageBox::error ( 0, i18n ( "Creating of \"%1\" has been failed!" ).arg ( filename ) ); + return false; + } + } + else + { + KMessageBox::information ( 0, i18n ( "Export canceled." ) ); + return false; + } + QString msg=""; + if (exportCount > 0 && exportGlobal==true) + msg = i18n("Export was successful. %1 profiles and global settings are exported.").arg(QString::number(exportCount)); + if (exportCount > 0 && exportGlobal==false) + msg = i18n("Export was successful. %1 profiles are exported.").arg(QString::number(exportCount)); + if (exportCount < 1 && exportGlobal==true) + msg = i18n("Export was successful. Global settings are exported."); + KMessageBox::information ( 0, msg,i18n("Export success") ); + return true; +} + +bool KVpncConfig::importKvpncConfig(QString filename, QString& RetName, bool& openProfileManager) +{ + QFile importfile (filename); + if (!importfile.exists()) + { + KMessageBox::error ( 0, i18n ( "Reading of \"%1\" has been failed!" ).arg ( filename ) ); + return false; + } + QString kvpncexportversion=""; + + QString pathToVpnc; + QString pathToCiscoVpnc; + QString pathToRacoon; + QString pathToRacoonctl; + QString pathToSetkey; + QString pathToIptables; + QString pathToOpenssl; + QString pathToIpsec; + QString pathToPppd; + QString pathToPptp; + QString pathToL2tpd; + QString pathToXl2tpd; + QString pathToOpenl2tp; + QString pathToKill; + QString pathToKillall; + QString pathToPing; + QString pathToOpenvpn; + QString pathToIp; + QString pathToIfconfig; + QString pathToRoute; + QString pathToNetstat; + QString pathToPkcs11Tool; + QString pathToVtund; + QString pathToCiscoCertMgr; + QString pathToTail; + QString pathToSsh; + QString pathToKsshAskpass; + QString pathToGnomeSshAskpass; + QString AutoConnectProfile; + QString RacoonDebugLevel; + QString Vpnc_pid_file; + QString Pppd_pid_file; + QString lastProfile; + QString logfileName; + + QString TmpPassword; //< from enter password dialog + QString TmpGroupPassword; //< from enter password dialog + QString TmpUsername; //< from enter password dialog + QString TmpPrivKeyPassStr; + QString TmpGatewayIP; + QString TmpXauthInterPasscode; //< from Xauth interactive passcode dialog + QString TmpPrivateKeyPass; + QString TmpHttpProxyPassword; + + bool minimizeAfterConnect=true; + bool showDebugConsole=true; + bool writeLogFile=true; + bool useDefaultPaths=true; + bool useSilentQuit=false; + bool holdGeneratedScripts=true; + bool programsInPath=true; + bool enableDebugPppd=false; + bool enableDebugPptpd=false; + bool enableDebugL2tpd=false; + bool enableDebugXl2tpd=false; + bool enableDebugOpenl2tp=false; + bool enableFreeswanVerbose=false; + bool enableDebugOpenvpn=false; + bool useColorizedLogOutput=true; + bool showInterfaceIPinTooltip=true; + bool dontQuitOnCloseEvent=true; + bool doAutoConnectAtStartup=false; + bool useKwallet=true; + bool showStatusBar=true; + bool showToolBar=true; + bool hideMainWindow=false; + bool PppdDebugLevel=false; + bool firstUseOfKwallet=false; + bool shutdownIsCalled=false; + bool skipKwalletStoring=false; + bool hideOnCloseInfo=false; + bool feedbackMailSent=false; + bool doKillL2tpdIfStillRunning=false; + bool doKillXl2tpdIfStillRunning=false; + bool doKillRacoonIfStillRunning=false; + bool showConnectionTimeInTooltip=false; + + int VpncDebugLevel=0; + int KvpncDebugLevel=1; + int OpenvpnDebugLevel=0; + int PptpLogLevel=0; + int SshDebugLevel=0; + int PppdKernelLogLevel=0; + int LogViewerFontSize=10; + int mainwindow_pos_x=10; + int mainwindow_pos_y=10; + int mainwindow_height=600; + int mainwindow_width=800; + int connectSleepDelay=10; + int connectSleepRetry=3; + int tryConnectTimeout=30; + int connectionStartTime=0; + int runningCheckCounter=0; + int runningCheckTimeout=0; + int OpenvpnManagementPort=2222; + QPtrList *ImportedAccountList; + + QColor InfoLogColor; + QColor RemoteLogColor; + QColor ErrorLogColor; + QColor SuccessLogColor; + QColor DebugLogColor; + QColor DebugBackgroundcolor; + + QPoint pos; + QPoint WindowPos; + QSize WindowSize; + + bool importGlobal=false; + int importCount=0; + + QDomDocument doc( "kvpncsettingsdoc" ); + if( importfile.open(IO_ReadOnly)) + { + QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) ); + + if ( !doc.setContent( &importfile ) ) { + importfile.close(); + KMessageBox::error ( 0, i18n ( "Reading of \"%1\" has been failed!" ).arg ( filename ) ); + appendLogEntry (i18n ( "Reading of \"%1\" has been failed!" ).arg ( filename ), error); + QApplication::restoreOverrideCursor(); + return false; + } + importfile.close(); + + // print out the element names of all elements that are direct children + // of the outermost element. + QDomElement docElem = doc.documentElement(); + + QDomNode n = docElem.firstChild(); + if (KvpncDebugLevel > 5) + std::cout << "dom doc:" << std::endl; + while( !n.isNull() ) + { + if (n.toElement().tagName() == "version") + { + if (KvpncDebugLevel > 5) + std::cout << "version tag found." << std::endl; + QDomNodeList vsubnodes = n.toElement().childNodes(); + for (int i=0;i<=(int)vsubnodes.count();i++) + { + QDomNode n1 = vsubnodes.item(i); + if (n1.toElement().tagName() == "app") + { + if (KvpncDebugLevel > 5) + std::cout << " doc was created from kvpnc ver " << n1.toElement().text() << std::endl; + } + if (n1.toElement().tagName() == "exportversion") + { + kvpncexportversion = n1.toElement().text(); + if (KvpncDebugLevel > 5) + std::cout << " doc was created from kvpnc with exportver " << n1.toElement().text() << std::endl; + } + } + } + + if (n.toElement().tagName() == "global") + { + if (KvpncDebugLevel > 5) + std::cout << "gobal tag found." << std::endl; + QDomNodeList vsubnodes = n.toElement().childNodes(); + for (int i=0;i<=(int)vsubnodes.count();i++) + { + QDomNode n1 = vsubnodes.item(i); + if (n1.toElement().tagName() != "") + { + if (KvpncDebugLevel > 5) + std::cout << " => option: " << ", value: " << n1.toElement().text() << std::endl; + } + if ( n1.toElement().tagName() == "Minimize after connect" ) { minimizeAfterConnect = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Hide on startup" ) { hideMainWindow = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Use silent quit" ) { useSilentQuit = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Dont quit on CloseEvent" ) { dontQuitOnCloseEvent = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Enable pppd debug" ) { enableDebugPppd = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Enable pptpd debug" ) { enableDebugPptpd = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Enable l2tpd debug" ) { enableDebugL2tpd = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Enable xl2tpd debug" ) { enableDebugXl2tpd = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Enable openl2tp debug" ) { enableDebugOpenl2tp = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Enable FreeSWAN verbose" ) { enableFreeswanVerbose = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Pluto Debug" ) { PlutoDebug = QStringList::split(' ', n1.toElement().text()); } + else if ( n1.toElement().tagName() == "Klips Debug" ) { KlipsDebug = QStringList::split(' ', n1.toElement().text()); } + else if ( n1.toElement().tagName() == "Show debugconsole" ) { showDebugConsole = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Pid file for vpnc " ) { Vpnc_pid_file = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Vpnc debuglevel" ) { VpncDebugLevel = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Racoon debuglevel" ) { RacoonDebugLevel = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Kvpnc debuglevel" ) { KvpncDebugLevel = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Pppd debuglevel" ) { PppdDebugLevel = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Pppd kernel log level" ) { PppdKernelLogLevel = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Openvpn debuglevel" ) { OpenvpnDebugLevel = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Pptp debuglevel" ) { PptpLogLevel = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Ssh debuglevel" ) { SshDebugLevel = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Path to vpnc-bin" ) { pathToVpnc = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Path to vpnclient" ) { pathToCiscoVpnc = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Path to racoon" ) { pathToRacoon = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Path to racoonctl" ) { pathToRacoonctl = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Path to setkey" ) { pathToSetkey = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Path to iptables" ) { pathToIptables = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Path to openssl" ) { pathToOpenssl = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Path to freeswan" ) { pathToIpsec = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Path to pppd" ) { pathToPppd = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Path to pptp" ) { pathToPptp = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Path to l2tpd" ) { pathToL2tpd = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Path to xl2tpd" ) { pathToXl2tpd = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Path to openl2tp" ) { pathToOpenl2tp = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Path to kill" ) { pathToKill = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Path to kill-all" ) { pathToKillall = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Path to ping" ) { pathToPing = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Path to openvpn" ) { pathToOpenvpn = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Path to iputility" ) { pathToIp = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Path to ifconfig" ) { pathToIfconfig = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Path to route" ) { pathToRoute = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Path to netstat" ) { pathToNetstat = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Path to pkcs11-tool" ) { pathToPkcs11Tool = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Path to vtund" ) { pathToVtund = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Path to cisco_cert_mgr" ) { pathToCiscoCertMgr = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Path to tail" ) { pathToTail = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Path to ssh" ) { pathToSsh = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Path to ksshaskpass" ) { pathToKsshAskpass = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Path to ssh-askpass-gnome" ) { pathToGnomeSshAskpass = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Show Statusbar" ) { showStatusBar = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Try connect timeout" ) { tryConnectTimeout = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Last Profile" ) { lastProfile = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Write log file" ) { writeLogFile = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Hold generated scripts" ) { holdGeneratedScripts = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Programs in path" ) { programsInPath = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Info logwindow color" ) { InfoLogColor.name() = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Remote logwindow color" ) { RemoteLogColor.name() = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Error logwindow color" ) { ErrorLogColor.name() = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Success logwindow color" ) { SuccessLogColor.name() = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Debug logwindow color" ) { DebugLogColor.name() = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Debug background color" ) { DebugBackgroundcolor.name() = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Use colorized log output" ) { useColorizedLogOutput = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Show interface IP in tooltip" ) { showInterfaceIPinTooltip = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Auto connect profile" ) { AutoConnectProfile = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Do auto connect at startup" ) { doAutoConnectAtStartup = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Log viewer font size" ) { LogViewerFontSize = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Mainwindow width" ) { mainwindow_width = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Mainwindow height" ) { mainwindow_height = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Mainwindow position x" ) { mainwindow_pos_x = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Mainwindow position y" ) { mainwindow_pos_y = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Openvpn management port" ) { OpenvpnManagementPort = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "hideOnCloseInfo" ) { hideOnCloseInfo = n1.toElement().text().toInt(); } + // else if (n1.toElement().tagName() == "ToolBar Settings") { parent->toolBar( "mainToolBar" ) = n1.toElement().text(); } + else if ( n1.toElement().tagName() == "Use KWallet" ) { useKwallet = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "FeedbackMailSent" ) { feedbackMailSent = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Do kill l2tpd if still running" ) { doKillL2tpdIfStillRunning = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Do kill xl2tpd if still running" ) { doKillXl2tpdIfStillRunning = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Do kill racoon if still running" ) { doKillRacoonIfStillRunning = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Show connection time in Tooltip" ) { showConnectionTimeInTooltip = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "Enable debug Openvpn" ) { enableDebugOpenvpn = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "EnableDebugXl2tpdNetwork") { enableDebugXl2tpdNetwork = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "EnableDebugXl2tpdpacket" ) { enableDebugXl2tpdpacket = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "EnableDebugXl2tpdstate" ) { enableDebugXl2tpdstate = n1.toElement().text().toInt(); } + else if ( n1.toElement().tagName() == "EnableDebugXl2tpdtunnel") { enableDebugXl2tpdtunnel = n1.toElement().text().toInt(); } + } + } + + if (n.toElement().tagName() == "profiles") + { + if (KvpncDebugLevel > 5) + std::cout << "profiles tag found." << std::endl; + + ImportedAccountList = new QPtrList(); + ImportedAccountList->setAutoDelete( TRUE ); // the list owns the objects + + QDomNodeList profiles_subnodes = n.toElement().childNodes(); + for (int i=0;i<=(int)profiles_subnodes.count();i++) + { + QDomNode n1 = profiles_subnodes.item(i); + if (n1.toElement().attribute("name") != "") + { + if (KvpncDebugLevel > 5) + std::cout << "profile: " << n1.toElement().attribute("name") << std::endl; + QString name = n1.toElement().attribute("name"); + VpnAccountData *data = new VpnAccountData( VpnAccountData::cisco, name); // cisco is a dummy here, it will be set later + data->setDescription(i18n("import from ")+filename); + + QDomNodeList profile_subnodes = n1.toElement().childNodes(); + for (int j=0;j<=(int)profile_subnodes.count();j++) + { + QDomNode n2 = profile_subnodes.item(j); + if (n2.toElement().attribute("name") != "") + { + QString elementname= n2.toElement().attribute("name"); + QString elementvalue = n2.toElement().text(); + if (KvpncDebugLevel > 5) + std::cout << " => option: " << elementname << ", value: " << elementvalue << std::endl; + // normal config + if (elementname == "Connection type") + { + QString type = elementvalue; + VpnAccountData::ConnectionType ConnType = VpnAccountData::ConnectionType( VpnAccountData::cisco ); + if ( type == "cisco" ) + ConnType = VpnAccountData::cisco; + else if ( type == "ciscoorig" ) + ConnType = VpnAccountData::ciscoorig; + else if ( type == "racoon" ) + ConnType = VpnAccountData::racoon; + else if ( type == "l2tpd (racoon)" ) + ConnType = VpnAccountData::l2tpd_racoon; + else if ( type == "freeswan" ) + ConnType = VpnAccountData::freeswan; + else if ( type == "l2tpd (openswan)" ) + ConnType = VpnAccountData::l2tpd_freeswan; + else if ( type == "pptp" ) + ConnType = VpnAccountData::pptp; + else if ( type == "openvpn" ) + ConnType = VpnAccountData::openvpn; + else if ( type == "vtun" ) + ConnType = VpnAccountData::vtun; + else if ( type == "ssh" ) + ConnType = VpnAccountData::ssh; + + else + ConnType = VpnAccountData::other; + data->setConnectionType(ConnType); +// std::cout << " ==> type: " << type << std::endl; + } + + else if (elementname == "VPN Gateway") { data->setGateway(elementvalue); } + else if (elementname == "VPN ID") { data->setID(elementvalue); } + else if (elementname == "Username") { data->setUserName(elementvalue); } + + else if (elementname == "Save user password") { data->setSaveUserPassword(elementvalue.toInt()); } + else if (elementname == "Save PSK") { data->setSavePsk(elementvalue.toInt()); } + else if (elementname == "Save private key password") { data->setSavePrivateKeyPassword(elementvalue.toInt()); } + else if (elementname == "Private key") { data->setPrivateKey(elementvalue); } + else if (elementname == "Use advanced settings") { data->setUseAdvancedSettings(elementvalue.toInt()); } + else if (elementname == "Application version") { data->setApplicationVersion(elementvalue); } + else if (elementname == "Local port") { data->setLocalPort(elementvalue.toInt()); } + else if (elementname == "Remote port") { data->setRemotePort(elementvalue.toInt()); } + else if (elementname == "NT domain name") { data->setNtDomainName(elementvalue); } + else if (elementname == "Perfect forward secrety") { data->setPerfectForwardSecrety(elementvalue); } + else if (elementname == "IKE group") { data->setIkeGroup(elementvalue); } + + else if (elementname == "Use application version") { data->setUseApplicationVersion(elementvalue.toInt()); } + else if (elementname == "Use global IPSec secret") { data->setUseGlobalIpsecSecret(elementvalue.toInt()); } + else if (elementname == "Use IKE group") { data->setUseIkeGroup(elementvalue.toInt()); } + else if (elementname == "Use local port") { data->setUseLocalPort(elementvalue.toInt()); } + else if (elementname == "Use remote port") { data->setUseRemotePort(elementvalue.toInt()); } + else if (elementname == "Use NT domain name") { data->setUseNtDomainName(elementvalue.toInt()); } + else if (elementname == "Use single DES") { data->setUseSingleDes(elementvalue.toInt()); } + else if (elementname == "Use perfect Forward Secrety") { data->setUsePerfectForwardSecrety(elementvalue.toInt()); } + else if (elementname == "Remote net address") { data->setRemoteNetAddr(elementvalue); } + else if (elementname == "Remote net mask") { data->setRemoteNetMask(elementvalue); } + + else if (elementname == "x509 certificate") { data->setX509Certificate(elementvalue); } + else if (elementname == "Ca certificate") { data->setCaCertificate(elementvalue); } + else if (elementname == "Network device") { data->setNetworkDevice(elementvalue); } + else if (elementname == "Cert path") { data->setCertPath(elementvalue); } + + else if (elementname == "Auth type") + { + QString Authtype = elementvalue; + if (Authtype == "cert") + data->setAuthType(VpnAccountData::cert); + else if (Authtype == "psk") + data->setAuthType(VpnAccountData::psk); + else if (Authtype == "hybrid") + data->setAuthType(VpnAccountData::hybrid); + else + data->setAuthType( VpnAccountData::unknownauth); + + if ((data->getConnectionType() == VpnAccountData::pptp || data->getConnectionType() == VpnAccountData::openvpn ) && (Authtype != "cert" && Authtype == "psk")) + data->setAuthType(VpnAccountData::cert); + + } + else if (elementname == "do ping ip") { data->setDoPingIP(elementvalue.toInt()); } + else if (elementname == "Ping host IP") { data->setPingHostIP(elementvalue); } + + else if (elementname == "Special server certificate") { data->setSpecialServerCertificate(elementvalue); } + else if (elementname == "Use special server certificate") { data->setUseSpecialServerCertificate(elementvalue.toInt()); } + else if (elementname == "Special remote ID") { data->setSpecialRemoteID(elementvalue); } + else if (elementname == "Special local ID") { data->setSpecialLocalID(elementvalue); } + else if (elementname == "Local ID type") { data->setLocalIDType(elementvalue); } + else if (elementname == "Remote ID type") { data->setRemoteIDType(elementvalue); } + else if (elementname == "Use UDP-protocol") { data->setUseUdp(elementvalue.toInt()); } + else if (elementname == "Use UDP-port") { data->setUseUdpPort(elementvalue.toInt()); } + else if (elementname == "local UDP port") { data->setUdpPort(elementvalue.toInt()); } + else if (elementname == "use DNS_UPDATE") { data->setUseDnsUpdate(elementvalue.toInt()); } + else if (elementname == "use DNS-server") { data->setUseDnsServer(elementvalue.toInt()); } + else if (elementname == "DNS server") { data->setDnsServer(elementvalue); } + else if (elementname == "refuse 40 bit encryption") { data->setRefuse40BitEncryption(elementvalue.toInt()); } + else if (elementname == "refuse 128 bit encryption") { data->setRefuse128BitEncryption(elementvalue.toInt()); } + else if (elementname == "require stateless encryption") { data->setAllowStatefulMode(elementvalue.toInt()); } + else if (elementname == "require mppe") { data->setRequireMppe(elementvalue.toInt()); } + else if (elementname == "Disable MPPE compression") { data->setDisableMPPEComp(elementvalue.toInt()); } + else if (elementname == "Local virtual IP") { data->setLocalVirtualIP(elementvalue); } + else if (elementname == "Remote virtual IP") { data->setRemoteVirtualIP(elementvalue); } + else if (elementname == "Pre shared key file") { data->setPreSharedKeyFile(elementvalue); } + else if (elementname == "Execute command before connect") { data->setExecuteCmdBeforeConnect(elementvalue.toInt()); } + else if (elementname == "Execute command after connect") { data->setExecuteCmdAfterConnect(elementvalue.toInt()); } + else if (elementname == "Execute command before disconnect") { data->setExecuteCmdBeforeDisconnect(elementvalue.toInt()); } + else if (elementname == "Execute command after disconnect") { data->setExecuteCmdAfterDisconnect(elementvalue.toInt()); } + else if (elementname == "Command before connect") { data->setCommandBeforeConnect(elementvalue); } + else if (elementname == "Command after connect") { data->setCommandAfterConnect(elementvalue); } + else if (elementname == "Command before disconnect") { data->setCommandBeforeDisconnect(elementvalue); } + else if (elementname == "Command after disconnect") { data->setCommandAfterDisconnect(elementvalue); } + else if (elementname == "Use no BSD compression") { data->setUseNoBsdComp(elementvalue.toInt()); } + else if (elementname == "Do not use no IP by default") { data->setUseNoIpDefault(elementvalue.toInt()); } + else if (elementname == "Use no deflate") { data->setUseNoDeflate(elementvalue.toInt()); } + else if (elementname == "Replace default route") { data->setReplaceDefaultRoute(elementvalue.toInt()); } + else if (elementname == "Use own MTU") { data->setUseMtu(elementvalue.toInt()); } + else if (elementname == "Use own MRU") { data->setUseMru(elementvalue.toInt()); } + else if (elementname == "MTU for pppd") { data->setMtu(elementvalue.toInt()); } + else if (elementname == "MRU for pppd") { data->setMru(elementvalue.toInt()); } + else if (elementname == "Use virtual IP") { data->setUseVirtualIP(elementvalue.toInt()); } + else if (elementname == "Virtual IP") { data->setVirtualIP(elementvalue); } + else if (elementname == "PSK is in file") { data->setPskIsInFile(elementvalue.toInt()); } + else if (elementname == "Use additional network routes") { data->setUseAdditionalNetworkRoutes(elementvalue.toInt()); } + else if (elementname == "Hash algorithm") { data->setHashAlgo(elementvalue); } + else if (elementname == "Encryption algorithm") { data->setEncryptionAlgorithm(elementvalue); } + else if (elementname == "Authentication algorithm") { data->setAuthenticationAlgorithm(elementvalue); } + else if (elementname == "Tunnel device type") { data->setTunnelDeviceType(elementvalue); } + else if (elementname == "Use userdefined port") { data->setUseUserdefinedPort(elementvalue.toInt()); } + else if (elementname == "Userdefined port") { data->setUserdefinedPort(elementvalue.toInt()); } + else if (elementname == "NS cert type") { data->setNsCertType(elementvalue); } + else if (elementname == "Use NS cert type") { data->setUseNsCertType(elementvalue.toInt()); } + else if (elementname == "Use connection status check") { data->setUseConnectionStatusCheck(elementvalue.toInt()); } + else if (elementname == "Connection check success count") { data->setConnectionStatusCheckSuccessCount(elementvalue.toInt()); } + else if (elementname == "Connection check status interval") { data->setConnectionStatusInterval(elementvalue.toInt()); } + else if (elementname == "Do reconnect after connection lost") { data->setDoReconnectAfterConnectionLost(elementvalue.toInt()); } + else if (elementname == "Disable LZO compression") { data->setDisableLzoCompression(elementvalue.toInt()); } + else if (elementname == "AuthWithUsernameAndPassword") { data->setAuthWithUsernameAndPassword(elementvalue.toInt()); } + else if (elementname == "AllowEmptyGroupPassword") { data->setAllowEmptyGroupPassword(elementvalue.toInt()); } + else if (elementname == "Use userdefinied cipher") { data->setUseUserdefiniedCipher(elementvalue.toInt()); } + else if (elementname == "Userdefinied cipher") { data->setUserdefiniedCipher(elementvalue); } + else if (elementname == "Use redirect gateway") { data->setUseRedirectGateway(elementvalue.toInt()); } + // appPointer->processEvents(<< "") { "\n"; + else if (elementname == "Use TLS auth") { data->setUseTlsAuth(elementvalue.toInt()); } + else if (elementname == "TLS auth file") { data->setTlsAuthFile(elementvalue); } + else if (elementname == "Use HTTP proxy") { data->setUseHttpProxy(elementvalue.toInt()); } + else if (elementname == "HTTP proxy host") { data->setHttpProxy(elementvalue); } + else if (elementname == "HTTP proxy port") { data->setHttpProxyPort(elementvalue.toInt()); } + else if (elementname == "HTTP proxy timeout") { data->setHttpProxyTimeout(elementvalue.toInt()); } + else if (elementname == "Dont save username") { data->setDontSaveUsername(elementvalue.toInt()); } + else if (elementname == "Use mode config") { data->setUseModeConfig(elementvalue.toInt()); } + else if (elementname == "Exchange mode") { data->setExchangeMode(elementvalue); } + else if (elementname == "Use delay at reconnect") { data->setUseReconnectDelay(elementvalue.toInt()); } + else if (elementname == "Reconnect delay") { data->setReconnectDelay(elementvalue.toInt()); } + else if (elementname == "Use TLS host") { data->setUseTlsRemoteHost(elementvalue.toInt()); } + else if (elementname == "TLS remote host") { data->setTlsRemoteHost(elementvalue); } + else if (elementname == "Disable opportunistic encryption") { data->setDisableOpportunisticEncryption(elementvalue.toInt()); } + else if (elementname == "Right next hop") { data->setRightNextHop(elementvalue); } + else if (elementname == "Left next hop") { data->setLeftNextHop(elementvalue); } + else if (elementname == "Use userdefinied packet size for fragmentation") { data->setUseFragment(elementvalue.toInt()); } + else if (elementname == "Use userdef packet size") { data->setUseMssfix(elementvalue.toInt()); } + else if (elementname == "Fragment") { data->setFragment(elementvalue.toInt()); } + else if (elementname == "PeerTimeout") { data->setPeerTimeout(elementvalue.toInt()); } + else if (elementname == "Disable CCP") { data->setDisableCcp(elementvalue.toInt()); } + else if (elementname == "Use smartcard") { data->setUseSmartcard(elementvalue.toInt()); } + else if (elementname == "Use Xauth interactive") { data->setUseXauthInteractive(elementvalue.toInt()); } + else if (elementname == "Use HTTP Proxy Authentication") { data->setUseHttpProxyAuth(elementvalue.toInt()); } + else if (elementname == "HTTP Proxy Authtype") { data->setHttpProxyAuthType(elementvalue); } + else if (elementname == "HTTP Proxy Auth user") { data->setHttpProxyUser(elementvalue); } + else if (elementname == "HTTP Proxy Auth pass") { data->setHttpProxyPass(elementvalue); } + else if (elementname == "Use only CA cert and user auth") { data->setUseOnlyCaCertAndUserAuth(elementvalue.toInt()); } + else if (elementname == "Use mail address as identifier") { data->setUseMailAddressAsIdentifier(elementvalue.toInt()); } + else if (elementname == "Use right next hop") { data->setUseRightNextHop(elementvalue.toInt()); } + else if (elementname == "Use left next hop") { data->setUseLeftNextHop(elementvalue.toInt()); } + else if (elementname == "Pkcs11 providers") { data->setPkcs11Providers(elementvalue); } + else if (elementname == "Pkcs11 slot type") { data->setPkcs11SlotType(elementvalue); } + else if (elementname == "Pkcs11 slot") { data->setPkcs11Slot(elementvalue); } + else if (elementname == "Pkcs11 id type") { data->setPkcs11IdType(elementvalue); } + else if (elementname == "Pkcs11 id") { data->setPkcs11Id(elementvalue); } + else if (elementname == "Pkcs11 sign mode") { data->setPkcs11SignMode(elementvalue); } + else if (elementname == "Use Pkcs11 providers") { data->setUsePkcs11Providers(elementvalue.toInt()); } + else if (elementname == "Allow empty private key password") { data->setAllowEmptyPrivateKeyPassword(elementvalue.toInt()); } + else if (elementname == "Allow ip address change of peer") { data->setAllowIpAddressChangeOfPeer(elementvalue.toInt()); } + else if (elementname == "Auth method") { data->setAuthMethod(elementvalue); } + else if (elementname == "Command after connect delay time") { data->setCommandAfterConnectDelayTime(elementvalue.toInt()); } + else if (elementname == "Use search domain in resolv conf") { data->setUseSearchDomainInResolvConf(elementvalue.toInt()); } + else if (elementname == "Use domain in resolv conf") { data->setUseDomainInResolvConf(elementvalue.toInt()); } + else if (elementname == "Search domain in resolv conf") { data->setSearchDomainInResolvConf(elementvalue); } + else if (elementname == "Domain in resolv conf") { data->setDomainInResolvConf(elementvalue); } + else if (elementname == "Authentication direction") { data->setAuthenticationDirection(elementvalue); } + else if (elementname == "CiscoNatMode") { data->setCiscoNatMode(elementvalue); } + else if (elementname == "IPSec ESP") { data->setIpsecEsp(elementvalue); } + else if (elementname == "IPSec IKE") { data->setIpsecIke(elementvalue); } + else if (elementname == "Vtun profile") { data->setVtunProfile(elementvalue); } + else if (elementname == "Disable data encryption") { data->setDisableDataEncryption(elementvalue.toInt()); } + else if (elementname == "Use authentication algorithm") { data->setUseAuthenticationAlgorithm(elementvalue.toInt()); } + else if (elementname == "Fix path mtu discovery problem") { data->setFixPathMtuDiscoveryProblem(elementvalue.toInt()); } + else if (elementname == "Use remote network") { data->setUseRemoteNetwork(elementvalue.toInt()); } + else if (elementname == "Ipsec vpn mode") { data->setIpsecVpnMode(elementvalue); } + else if (elementname == "DisableHeaderCompression") { data->setDisableHeaderCompression(elementvalue.toInt()); } + else if (elementname == "DisableMagicNumberNegotiation") { data->setDisableMagicNumberNegotiation(elementvalue.toInt()); } + else if (elementname == "DisableIpx") { data->setDisableIpx(elementvalue.toInt()); } + else if (elementname == "Disable protocol field compression") { data->setDisableProtocolFieldCompression(elementvalue.toInt()); } + else if (elementname == "Disable adress control compression") { data->setDisableAdressControlCompression(elementvalue.toInt()); } + else if (elementname == "Use custom ike") { data->setUseCustomIke(elementvalue.toInt()); } + else if (elementname == "Use custom esp") { data->setUseCustomEsp(elementvalue.toInt()); } + else if (elementname == "Verify ca cert") { data->setVerifyCaCert(elementvalue.toInt()); } + else if (elementname == "Use DPD idle timeout") { data->setUseDpdIdleTimeout(elementvalue.toInt()); } + else if (elementname == "DPD idle timeout") { data->setDpdIdleTimeout(elementvalue.toInt()); } + else if (elementname == "Hide group password in accountdata dialog") { data->setHideGroupPasswordInAccountDataDialog(elementvalue.toInt()); } + else if (elementname == "MaxConnectTries") { data->setMaxConnectTries(elementvalue.toInt()); } + else if (elementname == "L2tpDaemon") { data->setL2tpDaemon((VpnAccountData::L2tpDaemonType)elementvalue.toInt()); } + else if (elementname == "UseLeftSourceIp") { data->setUseLeftSourceIp(elementvalue.toInt()); } + else if (elementname == "UseRightSourceIp") { data->setUseRightSourceIp(elementvalue.toInt()); } + else if (elementname == "LeftSourceIp") { data->setLeftSourceIp(elementvalue); } + else if (elementname == "RightSourceIp") { data->setRightSourceIp(elementvalue); } + else if (elementname == "Use virtual subnets") { data->setUseVirtualSubnetworks(elementvalue.toInt()); } + else if (elementname == "Virtual subnets") { data->setVirtualSubnetworks(elementvalue); } + else if (elementname == "DisablePushFromServer") { data->setDisablePushFromServer(elementvalue.toInt()); } + else if (elementname == "DisableBind") { data->setDisableBind(elementvalue.toInt()); } + else if (elementname == "UseRenegSec") { data->setUseRenegSec(elementvalue.toInt()); } + else if (elementname == "RenegSec") { data->setRenegSec(elementvalue.toInt()); } + else if (elementname == "UseTunnelPing") { data->setUseTunnelPing(elementvalue.toInt()); } + else if (elementname == "TunnelPing") { data->setTunnelPing(elementvalue.toInt()); } + else if (elementname == "UseTunnelPingRestart") { data->setUseTunnelPingRestart(elementvalue.toInt()); } + else if (elementname == "TunnelPingRestart") { data->setTunnelPingRestart(elementvalue.toInt()); } + else if (elementname == "RequireEap") { data->setRequireEap(elementvalue.toInt()); } + else if (elementname == "UseSshConfigRemoteScript") { data->setUseSshConfigRemoteScript(elementvalue.toInt()); } + else if (elementname == "SshConfigRemoteScript") { data->setSshConfigRemoteScript(elementvalue); } + else if (elementname == "AskUserPasswordOnEachConnect") { data->setAskUserPasswordOnEachConnect(elementvalue.toInt()); } + else if (elementname == "UseCiscoCertStore") { data->setUseCiscoCertStore(elementvalue.toInt()); } + else if (elementname == "UseNat") { data->setUseNat(elementvalue.toInt()); } + } + } + if (KvpncDebugLevel > 5) + std::cout << "profile end " << std::endl; + ImportedAccountList->append(data); + } + appPointer->processEvents(); + } + QApplication::restoreOverrideCursor(); + KvpncImportProfileSelectionDialog selectdlg; + VpnAccountData *it=NULL; + + if ( !ImportedAccountList->isEmpty() ) + { + selectdlg.ImportProfileListView->takeItem(selectdlg.ImportProfileListView->currentItem()); + selectdlg.ImportProfileListView->addColumn(i18n("Name")); + selectdlg.ImportProfileListView->addColumn(i18n("Type")); + selectdlg.ImportProfileListView->addColumn(i18n("Gateway")); + selectdlg.ImportNamePrefixLineEdit->setText( "kvpnc_import_"); + + QCheckListItem *item; + for ( it = ImportedAccountList->first(); it; it = ImportedAccountList->next() ) + { + QString name = it->getName(); + QString type; + if ( it->getConnectionType() == VpnAccountData::cisco ) + type = "cisco" ; + else if ( it->getConnectionType() == VpnAccountData::ciscoorig ) + type = "ciscoorig" ; + else if ( it->getConnectionType() == VpnAccountData::racoon ) + type = "racoon" ; + else if ( it->getConnectionType() == VpnAccountData::l2tpd_racoon ) + type = "l2tpd (racoon)" ; + else if ( it->getConnectionType() == VpnAccountData::freeswan ) + type = "freeswan" ; + else if ( it->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + type = "l2tpd (openswan)" ; + else if ( it->getConnectionType() == VpnAccountData::pptp ) + type = "pptp" ; + else if ( it->getConnectionType() == VpnAccountData::openvpn ) + type = "openvpn" ; + else + type = i18n("other"); + + +// litem->setSelectable(true); + item = new QCheckListItem(selectdlg.ImportProfileListView,it->getName(),QCheckListItem::CheckBox); + item->setText(1,type); + item->setText(2,it->getGateway()); + selectdlg.ImportProfileListView->insertItem(item); + +// std::cout << "insert profile into listview: " << name << std::endl; + } + } + bool ret = selectdlg.exec(); + + if (ret == true) + { + importGlobal=selectdlg.ImportGlobalSettingsCheckBox->isChecked(); + QListViewItemIterator it2( selectdlg.ImportProfileListView ); + for ( ; it2.current(); ++it2 ) + { + if ( ( (QCheckListItem*)it2.current() )->isOn() ) + { + VpnAccountData *data=NULL; + it = 0; + for ( it = ImportedAccountList->first(); it; it = ImportedAccountList->next() ) + { + if ( it->getName() == ( (QCheckListItem*)it2.current() )->text() && ( (QCheckListItem*)it2.current() )->isOn() ) + { + data = it; + importCount++; + + // FIXME last profilename here + RetName=it->getName(); + + data->setName(selectdlg.ImportNamePrefixLineEdit->text()+data->getName()); + + bool ok = false; + VpnAccountData * it; + bool nameOk = false; + while ( nameOk == false ) + { + for ( it = AccountList->first(); it; it = AccountList->next() ) + { + if ( it->getName() == data->getName() ) + { + //account->setName( QString( account->getName() + "_2" ) ); + // KMessageBox::information ( this, i18n( "Profile name exists!\n It will be renamed to \"%1\"." ).arg( account->getName() ), i18n( "Name exist, renamed" ) ); + KMessageBox::error ( 0, i18n ( "Profile name exists!" ), i18n ( "Name Exists" ) ); + nameOk = false; + QString newName = KInputDialog::getText ( i18n ( "New Name" ), i18n ( "New name for profile:" ), QString ( data->getName() + "_2" ), &ok ); + if (newName.isEmpty()) + { + KMessageBox::information ( 0, i18n ( "Import was canceled." ) ); + appendLogEntry ( i18n ( "Import was canceled." ), info ); + return false; + } + if (newName != it->getName() ) + { + data->setName ( newName ); + nameOk = true; + } + } + else + { + nameOk = true; + } + } + } + + if ( nameOk == true ) + { + AccountList->append(data); + } + } + } + } + } + if (selectdlg.OpenProfileManagerCheckBox->isChecked()) + openProfileManager=true; + } + else + { + KMessageBox::sorry ( 0, i18n ( "Import canceled." ) ); + return false; + } + } + + QDomElement e = n.toElement(); // try to convert the node to an element. + if( !e.isNull() ) { + std::cout << e.tagName() << std::endl; // the node really is an element. + } + n = n.nextSibling(); + } + if (KvpncDebugLevel > 5) + std::cout << "dom doc end" << std::endl; + + if (importGlobal == true) + { + this-> pathToVpnc= pathToVpnc; + this-> pathToCiscoVpnc= pathToCiscoVpnc; + this-> pathToRacoon= pathToRacoon; + this-> pathToSetkey= pathToSetkey; + this-> pathToIptables= pathToIptables; + this-> pathToIptables= pathToIptables; + this-> pathToIpsec= pathToIpsec; + this-> pathToPppd= pathToPppd; + this-> pathToPptp= pathToPptp; + this-> pathToL2tpd= pathToL2tpd; + this-> pathToXl2tpd= pathToXl2tpd; + this-> pathToSsh= pathToSsh; + this-> pathToKill= pathToKill; + this-> pathToKillall= pathToKillall; + this-> pathToPing= pathToPing; + this-> pathToOpenvpn= pathToOpenvpn; + this-> pathToIp= pathToIp; + this-> pathToIfconfig= pathToIfconfig; + this-> pathToRoute= pathToRoute; + this-> pathToNetstat= pathToNetstat; + this-> pathToPkcs11Tool= pathToPkcs11Tool; + this-> AutoConnectProfile= AutoConnectProfile; + this-> RacoonDebugLevel= RacoonDebugLevel; + this-> Vpnc_pid_file= Vpnc_pid_file; + this-> Pppd_pid_file= Pppd_pid_file; + this-> lastProfile= lastProfile; + this-> logfileName= logfileName; + this->minimizeAfterConnect= minimizeAfterConnect; + this->showDebugConsole= showDebugConsole; + this-> writeLogFile= writeLogFile; + this-> useDefaultPaths= useDefaultPaths; + this-> useSilentQuit= useSilentQuit; + this-> holdGeneratedScripts= holdGeneratedScripts; + this-> programsInPath= programsInPath; + this-> enableDebugPppd= enableDebugPppd; + this-> enableDebugPptpd= enableDebugPptpd; + this-> enableDebugL2tpd= enableDebugL2tpd; + this-> enableDebugXl2tpd= enableDebugXl2tpd; + this-> enableFreeswanVerbose= enableFreeswanVerbose; + this-> enableDebugOpenvpn= enableDebugOpenvpn; + this-> useColorizedLogOutput= useColorizedLogOutput; + this-> showInterfaceIPinTooltip= showInterfaceIPinTooltip; + this-> dontQuitOnCloseEvent= dontQuitOnCloseEvent; + this-> doAutoConnectAtStartup= doAutoConnectAtStartup; + this-> useKwallet= useKwallet; + this-> showStatusBar= showStatusBar; + this-> showToolBar= showToolBar; + this-> hideMainWindow= hideMainWindow; + this-> PppdDebugLevel= PppdDebugLevel; + this-> firstUseOfKwallet= firstUseOfKwallet; + this-> shutdownIsCalled= shutdownIsCalled; + this-> skipKwalletStoring= skipKwalletStoring; + this-> hideOnCloseInfo= hideOnCloseInfo; + this-> feedbackMailSent= feedbackMailSent; + this-> doKillL2tpdIfStillRunning= doKillL2tpdIfStillRunning; + this-> doKillXl2tpdIfStillRunning= doKillXl2tpdIfStillRunning; + this-> doKillRacoonIfStillRunning= doKillRacoonIfStillRunning; + this-> showConnectionTimeInTooltip= showConnectionTimeInTooltip; + this-> VpncDebugLevel= VpncDebugLevel; + this-> KvpncDebugLevel= KvpncDebugLevel; + this-> OpenvpnDebugLevel= OpenvpnDebugLevel; + this-> PptpLogLevel= PptpLogLevel; + this-> SshDebugLevel= SshDebugLevel; + this-> LogViewerFontSize= LogViewerFontSize; + this-> mainwindow_pos_x= mainwindow_pos_x; + this-> mainwindow_pos_y= mainwindow_pos_y; + this-> mainwindow_height= mainwindow_height; + this-> mainwindow_width= mainwindow_width; + this-> connectSleepDelay= connectSleepDelay; + this-> connectSleepRetry= connectSleepRetry; + this-> tryConnectTimeout= tryConnectTimeout; + this-> connectionStartTime= connectionStartTime; + this-> runningCheckCounter= runningCheckCounter; + this-> runningCheckTimeout= runningCheckTimeout; + this-> OpenvpnManagementPort= OpenvpnManagementPort; + this->InfoLogColor= InfoLogColor; + this->RemoteLogColor= RemoteLogColor; + this->ErrorLogColor= ErrorLogColor; + this->SuccessLogColor= SuccessLogColor; + this->DebugLogColor= DebugLogColor; + this->DebugBackgroundcolor= DebugBackgroundcolor; + this->pos= pos; + this->WindowPos= WindowPos; + this->WindowSize= WindowSize; + + } + saveOptions(); + + QString msg=""; + if (importCount > 0 && importGlobal==true) + msg = i18n("Import was successful. %1 profiles and global settings are imported.").arg(QString::number(importCount)); + if (importCount > 0 && importGlobal==false) + msg = i18n("Import was successful. %1 profiles are imported.").arg(QString::number(importCount)); + if (importCount < 1 && importGlobal==false) + msg = i18n("Import was successful. Global settings are imported."); + KMessageBox::information ( 0, msg,i18n("Import success") ); + } + else + { + KMessageBox::error ( 0, i18n ( "Reading of \"%1\" has been failed!" ).arg ( filename ) ); + appendLogEntry (i18n ( "Reading of \"%1\" has been failed!" ).arg ( filename ), error); + QApplication::restoreOverrideCursor(); + return false; + } + return true; +} + +bool KVpncConfig::importIpsecConfig(QString filename, QString& RetName, bool& openProfileManager) +{ + QFile importfile (filename); + if (!importfile.exists()) + { + KMessageBox::error ( 0, i18n ( "Reading of \"%1\" has been failed!" ).arg ( filename ) ); + return false; + } + QPtrList *ImportedAccountList = new QPtrList(); + ImportedAccountList->setAutoDelete( TRUE ); // the list owns the objects + QPtrList *IpsecImportSectionList = new QPtrList(); + + bool isIpsecGlobalSection=false; + bool firstSectionFound=false; + bool defaultSectionFound=false; + bool useNat=false; + bool disableOpportunisticEncryption=true; + QStringList InterfaceList; + int IpsecVersion=1; +// bool pskIsInFile=true; + QString PskFile="/etc/ipsec.secrets"; + QString CertPath="/etc/ipsec.d/certs"; + + QString IpsecConfigSection=""; + bool validLineFound=false; + if ( importfile.open(IO_ReadOnly)) + { + QString line = NULL; + QString IpsecConfigSectionName=""; + QString IpsecConfigData=""; + bool sectionEndFound=false; + +// std::cout << "pass1: collecting sections" << std::endl; + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import ipsec config: pass1: collecting sections"),debug); + QTextStream stream(&importfile); + while ( !stream.atEnd() ) + { + line = stream.readLine().replace("\"",""); + +// std::cout << "line: \"" << line << "\"" << std::endl; + + if ( IpsecConfigSectionName!="" && ( line=="\n" || removeWhiteSpaceAtBegin(line) =="\n" || line == NULL || line.startsWith("include") || line.startsWith("conn") )) + { + // end of section found +// std::cout << "end of section " << IpsecConfigSectionName << " found." << std::endl; + if (KvpncDebugLevel > 2) + appendLogEntry(i18n("import ipsec config: end of section %1 found.").arg(IpsecConfigSectionName), debug); + sectionEndFound=true; + + IpsecImportSection *section = new IpsecImportSection(); + section->SectionName = IpsecConfigSectionName; + section->SectionData = IpsecConfigData; + IpsecImportSectionList->append(section); + IpsecConfigData=""; + IpsecConfigSectionName=""; + +// std::cout << "Section:"<< std::endl; +// std::cout << section->SectionName << std::endl; +// std::cout << section->SectionData.join("\n"); +// std::cout << "-------------------"<< std::endl; + + if (KvpncDebugLevel > 2) + { + appendLogEntry( "import ipsec config: Section:", debug); + appendLogEntry( section->SectionName , debug); + appendLogEntry( section->SectionData.join("\n"), debug); + appendLogEntry( "-------------------", debug); + } + } + + if (line.startsWith("conn")) + { + // section found + IpsecConfigSectionName=line.simplifyWhiteSpace().section('#',0,0).section(" ",1,1); +// std::cout << "normal section found: " << IpsecConfigSectionName << std::endl; + + isIpsecGlobalSection=false; + + if (IpsecConfigSectionName == "%default") + { + defaultSectionFound=true; + sectionEndFound=false; + firstSectionFound=true; + if (KvpncDebugLevel > 2) + appendLogEntry( i18n ("import ipsec config: default section found."), debug); + } + else + { + if (KvpncDebugLevel > 2) + appendLogEntry( i18n ("import ipsec config: normal section found: ") + IpsecConfigSectionName , debug); + sectionEndFound=false; + firstSectionFound=true; + } + } + if (line.startsWith("version")) + { + IpsecVersion=int(QString(line.simplifyWhiteSpace().section('#',0,0).section(" ",1,1).stripWhiteSpace()).toFloat()); + validLineFound=true; +// std::cout << "ipsec version found: " << IpsecVersion << std::endl; + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import ipsec config: ipsec version found: ")+ QString().setNum(IpsecVersion) ,debug); + } + if (line.startsWith("config setup")) + { + // config section found + isIpsecGlobalSection=true; + validLineFound=true; +// std::cout << "global section found." << std::endl; + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import ipsec config: global section found."),debug); + } + + if (isIpsecGlobalSection==true) + { + QString line2 = removeWhiteSpaceAtBegin( line); +// std::cout << "global section line: " << line2 << std::endl; + if (line2.startsWith("plutodebug")) + { + validLineFound=true; + // FIXME not implemented yet + } + if (line2.startsWith("nat_traversal=")) + { + validLineFound=true; + useNat=false; + if (line2.section('=',1,1) == "yes") + { + useNat=true; + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import ipsec config: use NAT."),debug); + } + else + { + useNat=false; + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import ipsec config: use no NAT."),debug); + } + } + + if (line2.startsWith("interfaces=")) + { + validLineFound=true; + if (line2.section('=',1,1) == "%defaultroute") + { + InterfaceList.append("default"); + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import ipsec config: use interface where default route points"),debug); + } + else + { + InterfaceList = QStringList::split(' ',line2.replace("interfaces=","").replace(QRegExp("ipsec[0-9]="),"")); +// std::cout << "interface list: " << InterfaceList << std::endl; + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import ipsec config: use interface from list:")+ " "+InterfaceList.join(", "),debug); + } + } + } + + if (line.startsWith("include /etc/ipsec.d/examples/no_oe.conf")) + { + validLineFound=true; + isIpsecGlobalSection=false; +// std::cout << "opportunistic enncrytion disabled found." << std::endl; + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import ipsec config: opportunistic encrytion disabled found"),debug); + + disableOpportunisticEncryption=true; + } + + if (!sectionEndFound && firstSectionFound==true) + { + // collecting data + QString cleanLine = removeWhiteSpaceAtBegin(line)+"\n"; +// std:: cout << "clean line: \"" << cleanLine << "\"" << std::endl; + if (!cleanLine.startsWith("#") && !cleanLine.startsWith("include") && cleanLine != "" && !line.startsWith("conn") && cleanLine != "\n") + { +// std:: cout << "appending line: \"" << line << "\"" << std::endl; + IpsecConfigData.append(line+"\n"); + } + else + { +// std:: cout << "skipping line: \"" << line << "\"" << std::endl; + } + } + } + importfile.close(); + if (IpsecConfigSectionName!="") + { + // end of section found +// std::cout << "end of section " << IpsecConfigSectionName << " found." << std::endl; + if (KvpncDebugLevel > 2) + appendLogEntry("end of section " + IpsecConfigSectionName +" found.",debug); + sectionEndFound=true; + + IpsecImportSection *section = new IpsecImportSection(); + section->SectionName = IpsecConfigSectionName; + section->SectionData = IpsecConfigData; + IpsecImportSectionList->append(section); + IpsecConfigData=""; + IpsecConfigSectionName=""; + } + + + + +// std::cout << "pass2: modifiy sections" << std::endl; + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import ipsec config: pass2: modifiy sections"),debug); + +// std::cout << "sections: IpsecImportSectionList: " << IpsecImportSectionList->count() << std::endl; + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import ipsec config: sections: ") + QString().setNum(IpsecImportSectionList->count()),debug); + + if (!IpsecImportSectionList->isEmpty()) + { + for ( int i=0; i< (int)IpsecImportSectionList->count();i++ ) + { + IpsecImportSection *section = IpsecImportSectionList->at(i); + QString Name= section->SectionName; + QStringList data = QStringList::split('\n',section->SectionData.join("\n")); + +// std::cout << " => processing section: \"" << Name << "\"" << std::endl; + + if (Name != "%default") + { + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import ipsec config: => processing section: ")+"\"" + Name + "\"",debug); + + for ( QStringList::Iterator it2 = data.begin(); it2 != data.end(); ++it2 ) + { + QString dataline = *it2; + // std::cout << "dataline found: \"" << dataline.remove("\n") << "\"" << std::endl; + if (removeWhiteSpaceAtBegin( dataline).startsWith("also=")) + { + // std::cout << "also= found, looking for other section..." << std::endl; + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import ipsec config: also= found, looking for other section..."),debug); + + QString newdata = QString(section->SectionData.join("\n")); + newdata.replace(QRegExp("^.*also=.*$"),""); + section->SectionData= newdata; + + QString OtherSection=dataline.simplifyWhiteSpace().section('#',0,0).section("=",1,1); + // we have to find the other section and replace this line by the config data of the other section (after the =) + bool section_found=false; + for (IpsecImportSection * it3 = IpsecImportSectionList->first(); it3; it3 = IpsecImportSectionList->next() ) + { + if (it3->SectionName == OtherSection) + { + // std::cout << "section " << OtherSection << " found, appending:" << std::endl; + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import ipsec config: section %1 found, appending:").arg(OtherSection),debug); + // std::cout << "other data:" << std::endl << it3->SectionData.join("\n") << "--------" << std::endl; + // std::cout << "section data:" << std::endl << section->SectionData.join("\n") << "--------" << std::endl; + section_found=true; + // data.remove(dataline); + dataline=""; + // QStringList otherdata = QStringList::split("\n",QString(it3->SectionData.join("\n"))); + QString OtherData = QString(it3->SectionData.join("\n")); + + QStringList newdata; + + for ( QStringList::Iterator it6 = data.begin(); it6 != data.end(); ++it6 ) + { + // std::cout << " also line: " << *it6 << std::endl; + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import ipsec config: also line: ") + QString(*it6),debug); + + if (QString(*it6).find("also=") < 0) + { + // std::cout << " also= found." << std::endl; + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import ipsec config: also= found."),debug); + newdata.append(QString(*it6)); + } + else + { + // std::cout << " also= not found." << std::cout; + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import ipsec config: also= not found.") ,debug); + } + } + // newdata.append(data.join("\n")); + newdata.append(OtherData); + section->SectionData= newdata; + + } + } + if (!section_found) + { + // std::cout << "section " << OtherSection << " not found, skipping" << std::endl; + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import ipsec config: section %1 not found, skipping").arg(OtherSection) ,debug); + } + + } + } + + if (defaultSectionFound==true) + { + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import ipsec config: => default section is set... "),debug); + + for ( int i=0; i< (int)IpsecImportSectionList->count();i++ ) + { + IpsecImportSection *section2 = IpsecImportSectionList->at(i); + QString Name= section2->SectionName; + if (Name == "%default") + { + + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import ipsec config: => appending %default section: ")+"\"" + section2->SectionData.join("\n") ,debug); + + QStringList defaultdata = QStringList::split('\n',section2->SectionData.join("\n")); + + + for ( QStringList::Iterator defaultit = defaultdata.begin(); defaultit != defaultdata.end(); ++defaultit ) + { + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import ipsec config: => appending %default line: ")+"\"" + *defaultit,debug); + section->SectionData.append(*defaultit); + } + break; + } + } + } + } + } + } + +// std::cout << "modified config" << std::endl << "---------------------" << std::endl; +// IpsecImportSection *it5=NULL; +// for ( it5 = IpsecImportSectionList->first(); it5; it5 = IpsecImportSectionList->next() ) +// { +// QString SectionName= it5->SectionName; +// QStringList data = it5->SectionData; +// +// std::cout << SectionName << std::endl; +// std::cout << data.join("\n") << std::endl; +// } + + // remove default section + for ( int i=0; i< (int)IpsecImportSectionList->count();i++ ) + { + IpsecImportSection *section = IpsecImportSectionList->at(i); + QString Name= section->SectionName; + if (Name == "%default") + { + IpsecImportSectionList->remove(IpsecImportSectionList->at(i)); + break; + } + } + + if (KvpncDebugLevel > 2) + { + appendLogEntry(i18n ("modified config") ,debug); + appendLogEntry( "---------------------" ,debug); + IpsecImportSection *it5=NULL; + for ( it5 = IpsecImportSectionList->first(); it5; it5 = IpsecImportSectionList->next() ) + { + QString SectionName= it5->SectionName; + QStringList data = it5->SectionData; + + appendLogEntry(SectionName ,debug); + appendLogEntry(data.join("\n") ,debug); + } + } + + +// std::cout << "pass3: parse sections" << std::endl; + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import ipsec config: pass3: parse sections") ,debug); + + + if (!IpsecImportSectionList->isEmpty()) + { + for ( int i=0; i< (int)IpsecImportSectionList->count();i++ ) + { + IpsecImportSection *section = IpsecImportSectionList->at(i); + + QStringList sectiondata = QStringList::split('\n',section->SectionData.join("\n")); + +// std::cout << " => processing section: \"" << section->SectionName << "\"" << std::endl; +// std::cout << " => data: \"" << section->SectionData.join("\n") << "\"" << std::endl; + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import ipsec config: => processing section: ")+"\"" + section->SectionName + "\"" ,debug); + + VpnAccountData *profiledata = new VpnAccountData(VpnAccountData::freeswan,QString(section->SectionName)) ; + + + for ( QStringList::Iterator it2 = sectiondata.begin(); it2!= sectiondata.end() ; it2++ ) + { + QString dataline = *it2; + + + + + + QString line2 = removeWhiteSpaceAtBegin ( dataline ); // line of text excluding '\n' and replace all white chars with one blank +// std::cout << "dataline: \"" << line2 << "\""; + if ( line2.startsWith ( "rightsubnet=" ) ) + { + validLineFound=true; + QString RightSubnet=line2.section ( "rightsubnet=",1,-1 ); +// std::cout << "right subnet (remote) found: " << RightSubnet << std::endl; + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n ( "import ipsec config: right subnet (remote) found: " ) + RightSubnet ,debug ); + profiledata->setRemoteNetAddr ( RightSubnet.section ( '/',0,0 ) ); + profiledata->setRemoteNetMask ( RightSubnet.section ( '/',1,1 ) ); + + profiledata->setUseRemoteNetwork ( true ); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (KvpncDebugLevel > 2) +// appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,debug); + } + if ( line2.startsWith ( "leftsubnet=" ) ) + { + validLineFound=true; + QString LeftSubnet=line2.section ( "leftsubnet=",1,-1 ); +// std::cout << "left subnet (local) found: " << LeftSubnet << std::endl; + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n ( "import ipsec config: left subnet (local) found: " ) + LeftSubnet ,debug ); + // local subnet cant be set yet. + // profiledata->setLocalNetAddr(RightSubnet.section('/',0,0)); + // profiledata->setLocalNetMask(RightSubnet.section('/',1,1)); + // std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; + + } + if ( line2.startsWith ( "rightnexthop=" ) ) + { + validLineFound=true; + QString RightNextHop=line2.section ( "rightnexthop=",1,-1 ); +// std::cout << "right next hop (remote) found: " << RightNextHop << std::endl; + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n ( "import ipsec config: right next hop (remote) found: " ) +RightNextHop ,debug ); + profiledata->setRightNextHop ( RightNextHop ); + profiledata->setUseRightNextHop(true); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (KvpncDebugLevel > 2) +// appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,debug); + } + if ( line2.startsWith ( "leftnexthop=" ) ) + { + validLineFound=true; + QString LeftNextHop=line2.section ( "leftnexthop=",1,-1 ); + std::cout << "left next hop (local) found: " << LeftNextHop << std::endl; + if (KvpncDebugLevel > 2) + appendLogEntry("import ipsec config: left next hop (local) found: " +LeftNextHop ,debug); + profiledata->setLeftNextHop(LeftNextHop); + profiledata->setUseLeftNextHop(true); + std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; + if (KvpncDebugLevel > 2) + appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,debug); + } + if ( line2.startsWith ( "left=" ) ) + { + validLineFound=true; + QString left=line2.section ( "left=",1,-1 ); + // local ip cant be set yet. + // std::cout << "left found: " << left << std::endl; +// if (KvpncDebugLevel > 2) +// appendLogEntry("import ipsec config: left found: " + left ,debug); + // profiledata->setLocal (left); + // std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (KvpncDebugLevel > 2) +// appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,debug); + } + if ( line2.startsWith ( "right=" ) ) + { + validLineFound=true; + QString right=line2.section ( "right=",1,-1 ); +// std::cout << "right (remote gateway) found: " << right << std::endl; + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n ( "import ipsec config: right (remote gateway) found: " ) + right ,debug ); + profiledata->setGateway ( right ); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (KvpncDebugLevel > 2) +// appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,debug); + } + if ( line2.startsWith ( "leftcert=" ) ) + { + validLineFound=true; + QString LeftCert=line2.section ( "leftcert=",1,-1 ); +// std::cout << "left cert (local) found: " << LeftCert << std::endl; + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n ( "import ipsec config: left cert (local) found: " ) + LeftCert ,debug ); + profiledata->setX509Certificate ( LeftCert ); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (KvpncDebugLevel > 2) +// appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,debug); + } + if ( line2.startsWith ( "rightcert=" ) ) + { + validLineFound=true; + QString RightCert=line2.section("rightcert=",1,-1); +// std::cout << "right cert (remote) found: " << RightCert << std::endl; + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import ipsec config: right cert (remote) found: ") + RightCert ,debug); + profiledata->setUseSpecialServerCertificate(true); + profiledata->setSpecialServerCertificate(RightCert); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (KvpncDebugLevel > 2) +// appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,debug); + } + if ( line2.startsWith ( "rightca=" ) ) + { + validLineFound=true; + QString RightCA=line2.section ( "rightca=",1,-1 ); +// std::cout << "right CA (remote) found: " << RightCA << std::endl; + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n ( "import ipsec config: right CA (remote) found: " ) +RightCA ,debug ); + profiledata->setCaCertificate ( RightCA ); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (KvpncDebugLevel > 2) +// appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,debug); + } + if ( line2.startsWith ( "rightid=" ) ) + { + validLineFound=true; + QString RightID=line2.section ( "rightid=",1,-1 ); +// std::cout << "right ID (remote) found: " << RightID << std::endl; + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n ( "import ipsec config: right ID (remote) found: " ) + RightID ,debug ); + profiledata->setUseSpecialRemoteID ( true ); + profiledata->setSpecialRemoteID ( RightID ); + profiledata->setRemoteIDType("keyid"); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (KvpncDebugLevel > 2) +// appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,debug); + } + if ( line2.startsWith ( "leftid=" ) ) + { + validLineFound=true; + QString LeftID=line2.section ( "leftid=",1,-1 ); +// std::cout << "local ID (local) found: " << LeftID << std::endl; + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n ( "import ipsec config: local ID (local) found: " ) + LeftID ,debug ); + profiledata->setUseSpecialLocalID ( true ); + profiledata->setSpecialLocalID ( LeftID ); + profiledata->setLocalIDType("keyid"); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (KvpncDebugLevel > 2) +// appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,debug); + } + if ( line2.startsWith ( "rightrsasigkey=" ) ) + { + validLineFound=true; + QString RightRsaSigKey=line2.section ( "rightrsasigkey=",1,-1 ); +// std::cout << "right uses (remote) " << RightRsaSigKey << std::endl; + if (RightRsaSigKey=="%cert") + { + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n ( "import ipsec config: right (remote) uses cert" ),debug ); + profiledata->setAuthType ( VpnAccountData::cert ); + } + else + { + + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n ( "import ipsec config: right (remote) uses " ) + RightRsaSigKey ,debug ); + profiledata->setAuthType ( VpnAccountData::psk ); + + // ok, we use special server cert here because at psk its unused + profiledata->setSpecialServerCertificate( RightRsaSigKey ); + profiledata->setUseSpecialServerCertificate(true); + + } +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (KvpncDebugLevel > 2) +// appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,debug); + } + if ( line2.startsWith ( "leftrsasigkey=" ) ) + { + validLineFound=true; + QString LeftRsaSigKey=line2.section ( "leftrsasigkey=",1,-1 ); +// std::cout << "right uses (remote) " << LeftRsaSigKey << std::endl; + if (LeftRsaSigKey=="%cert") + { + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n ( "import ipsec config: left (local) uses cert" ),debug ); + profiledata->setAuthType ( VpnAccountData::cert ); + + } + else + { + + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n ( "import ipsec config: left (local) uses " ) + LeftRsaSigKey ,debug ); + profiledata->setAuthType ( VpnAccountData::psk ); + + profiledata->setPreSharedKeyFile( LeftRsaSigKey ); + profiledata->setPskIsInFile( true ); + } +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (KvpncDebugLevel > 2) +// appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,debug); + } + if ( line2.startsWith ( "authby=" ) ) + { + validLineFound=true; + QString Authby=line2.simplifyWhiteSpace().section ( "authby=",1,1 ); +// std::cout << "left and right use certs " << std::endl; + if ( Authby.find ( "rsasig", 0 , FALSE ) > -1 ) + { + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n ( "import ipsec config: left and right use certs." ) ,debug ); + profiledata->setAuthType ( VpnAccountData::cert ); + profiledata->setCertPath ( "/etc/ipsec.d/certs" ); + //profiledata->setPskIsInFile ( true ); + //profiledata->setPrivateKey ( "/etc/ipsec.secrets" ); + } + else if ( Authby.find ( "secret", 0 , FALSE ) > -1 ) + { + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n ( "import ipsec config: left and right use psk." ) ,debug ); + profiledata->setAuthType ( VpnAccountData::psk ); + //profiledata->setPskIsInFile ( true ); + //profiledata->setPreSharedKeyFile ( "/etc/ipsec.secrets" ); + } + else + { + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n ( "import ipsec config: left and right use unknown auth, guess psk" ) ,debug ); + profiledata->setAuthType ( VpnAccountData::psk ); + } + + +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (KvpncDebugLevel > 2) +// appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,debug); + } + if ( line2.startsWith ( "auto=start" ) ) + { + // validLineFound=true; + // QString Authby=line2.simplifyWhiteSpace().section('#',0,0).section("=",1,1); + // std::cout << "profile should be started" << std::endl; +// if (KvpncDebugLevel > 2) +// appendLogEntry("import ipsec config: profile should be started" ,debug); + // profiledata->setAuthType(VpnAccountData::cert); + // std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (KvpncDebugLevel > 2) +// appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,debug); + } + if ( line2.startsWith ( "leftsourceip=" ) ) + { + validLineFound=true; + QString leftsourceip=line2.section ( "leftsourceip=",1,-1 ); + std::cout << "left (local) have to use IP address " << leftsourceip << std::endl; + if (KvpncDebugLevel > 2) + appendLogEntry("import ipsec config: left (local) have to use IP address " + leftsourceip ,debug); + profiledata->setLocalVirtualIP(leftsourceip); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; + if (KvpncDebugLevel > 2) + appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,debug); + } + if ( line2.startsWith ( "virtual_private=" ) ) + { + validLineFound=true; + QString virtualprivate=line2.section ( "virtual_private=",1,-1 ); + std::cout << "virtual private networks " << virtualprivate << std::endl; + if (KvpncDebugLevel > 2) + appendLogEntry("import ipsec config: virtual private networks " +virtualprivate ,debug); + profiledata->setLocalVirtualIP(virtualprivate); + profiledata->setUseVirtualIP(true); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; + if (KvpncDebugLevel > 2) + appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,debug); + } + if ( line2.startsWith ( "rightsourceip=" ) ) + { + validLineFound=true; + QString rightsourceip=line2.section ( "rightsourceip=",1,-1 ); + std::cout << "right (remote) have to use IP address " << rightsourceip << std::endl; + if (KvpncDebugLevel > 2) + appendLogEntry("import ipsec config: right (remote) have to use IP address " + rightsourceip ,debug); + profiledata->setRightSourceIp(rightsourceip); + profiledata->setUseRightSourceIp(true); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; + if (KvpncDebugLevel > 2) + appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,debug); + } + if ( line2.startsWith ( "esp=" ) ) + { + validLineFound=true; + QString IpsecEsp=line2.section ( "esp=",1,-1 ); +// std::cout << "esp settings found: " << IpsecEsp << std::endl; + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n ( "import ipsec config: esp settings found: " ) + IpsecEsp ,debug ); + profiledata->setIpsecEsp ( IpsecEsp ); + profiledata->setUseCustomEsp(true); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (KvpncDebugLevel > 2) +// appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,debug); + } + if ( line2.startsWith ( "ike=" ) ) + { + validLineFound=true; + QString IpsecIke=line2.section ( "ike=",1,-1 ); +// std::cout << "ike settings found: " << IpsecIke << std::endl; + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n ( "import ipsec config: ike settings found: " ) + IpsecIke ,debug ); + profiledata->setIpsecIke ( IpsecIke ); + profiledata->setUseCustomIke(true); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (KvpncDebugLevel > 2) +// appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,debug); + } + if ( line2.startsWith ( "type=" ) ) + { + validLineFound=true; + QString IpsecVpnMode=line2.section ( "type=",1,1 ); +// std::cout << "IpsecType found: " << IpsecType << std::endl; + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n ( "import ipsec config: IPsec vpn mode found: " ) + IpsecVpnMode ,debug ); + if ( IpsecVpnMode == "tunnel" ) + profiledata->setIpsecVpnMode ( "tunnel" ); + else + profiledata->setIpsecVpnMode ( "transport" ); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (KvpncDebugLevel > 2) +// appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,debug); + } + if ( line2.startsWith ( "leftxauthclient=" ) ) + { + validLineFound=true; + QString useXauth=line2.section ( "leftxauthclient=",1,1 ); + if (useXauth=="yes") + { + //std::cout << "Use XAUTH: " << i18n("yes") << std::endl; + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n ( "Use XAUTH (leftxauthclient found):" )+" " + i18n("yes") ,debug ); + profiledata->setAuthWithUsernameAndPassword( true ); + } + else + { + //std::cout << "Use XAUTH: " << i18n("no") << std::endl; + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n ( "Use XAUTH (leftxauthclient found):" )+" " + i18n("no") ,debug ); + profiledata->setAuthWithUsernameAndPassword( false ); + } +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (KvpncDebugLevel > 2) +// appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,debug); + } + if ( line2.startsWith ( "rightxauthserver=" ) ) + { + validLineFound=true; + QString useXauth=line2.section ( "rightxauthserver=",1,-1 ); + if (useXauth == "yes") + { + //std::cout << "Use XAUTH: " << i18n("yes") << std::endl; + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n ( "Use XAUTH (rightxauthserver found):" )+" " + i18n("yes") ,debug ); + profiledata->setAuthWithUsernameAndPassword( true ); + } + else + { + //std::cout << "Use XAUTH: " << i18n("no") << std::endl; + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n ( "Use XAUTH (rightxauthserver found):" )+" " + i18n("no") ,debug ); + profiledata->setAuthWithUsernameAndPassword( false ); + } +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (KvpncDebugLevel > 2) +// appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,debug); + } + if ( line2.startsWith ( "keyingtries=" ) ) + { + validLineFound=true; + int MaxConnectTries=QString(line2.section ( "keyingtries=",1,1 )).toInt(); +// std::cout << "keyingtries found: " << MaxConnectTries << std::endl; + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n ( "import ipsec config: keyingtries found: " ) + QString().setNum(MaxConnectTries) ,debug ); + profiledata->setMaxConnectTries ( MaxConnectTries ); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (KvpncDebugLevel > 2) +// appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,debug); + } + if ( line2.startsWith ( "pfs=" ) ) + { + validLineFound=true; + QString UsePerfectForwardSecrety=line2.section ( "pfs=",1,1 ).remove ( '"' ); + if (UsePerfectForwardSecrety =="yes") + { + //std::cout << "Use PFS: " << i18n("yes") << std::endl; + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n ( "Use PFS:" )+" " + i18n("yes") ,debug ); + profiledata->setUsePerfectForwardSecrety( true ); + } + else + { + //std::cout << "Use PFS: " << i18n("no") << std::endl; + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n ( "Use PFS:" )+" " + i18n("no") ,debug ); + profiledata->setUsePerfectForwardSecrety( false ); + } +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (KvpncDebugLevel > 2) +// appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,debug); + } + if ( line2.startsWith ( "pfsgroup=" ) ) + { + validLineFound=true; + QString PerfectForwardSecrety=line2.section ( "pfsgroup=",1,1 ); +// std::cout << "keyingtries found: " << MaxConnectTries << std::endl; + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n ( "import ipsec config: PFS group found: " ) + PerfectForwardSecrety ,debug ); + profiledata->setPerfectForwardSecrety ( PerfectForwardSecrety ); +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (KvpncDebugLevel > 2) +// appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,debug); + } + if ( line2.startsWith ( "aggrmode=" ) ) + { + validLineFound=true; + QString UseAgressiveMode=line2.section ( "aggrmode=",1,1 ).remove ( '"' ); + if (UseAgressiveMode == "yes") + { + //std::cout << "Exchange mode: " << i18n("aggressive") << std::endl; + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n ( "Exchange mode:" )+" " + "aggressive" ,debug ); + profiledata->setExchangeMode( "aggressive" ); + } + else + { + //std::cout << "Exchange mode: " << i18n("main") << std::endl; + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n ( "Exchange mode:" )+" " + "main" ,debug ); + profiledata->setExchangeMode( "main" ); + } +// std::cout << " => set it for profile " << IpsecConfigSection << " ." << std::endl; +// if (KvpncDebugLevel > 2) +// appendLogEntry("import ipsec config: => set it for profile " + IpsecConfigSection + " ." ,debug); + } + + else + { + // std::cout << "comment found." << std::endl; + } + } + + if ( useNat ) + { + profiledata->setUseNat ( true ); +// std::cout << "nat_traversal=yes found, enabling nat." << std::endl; + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n ( "import ipsec config: nat_traversal=yes found, enabling nat." ) ,debug ); + } + else + { + profiledata->setUseNat ( false ); +// std::cout << "nat_traversal=no found, disabling nat." << std::endl; + if ( KvpncDebugLevel > 2 ) + appendLogEntry ( i18n ( "import ipsec config: nat_traversal=no found, disabling nat." ) ,debug ); + } + if ( disableOpportunisticEncryption== true ) + { + profiledata->setDisableOpportunisticEncryption ( true ); + } + else + { + profiledata->setDisableOpportunisticEncryption ( false ); + } + + + + // FIXME we only use the first in list + QString Interface = InterfaceList.first(); + profiledata->setNetworkDevice(Interface); + + profiledata->setName("kvpnc_import_"+profiledata->getName()); + profiledata->setDescription(QString(i18n("import from ")+filename)); + ImportedAccountList->append(profiledata); + } + } + + + KvpncImportProfileSelectionBase selectdlg; + selectdlg.ImportGlobalSettingsCheckBox->hide(); + VpnAccountData *it=NULL; + int importCount=0; + + if ( !ImportedAccountList->isEmpty() ) + { + selectdlg.ImportProfileListView->takeItem(selectdlg.ImportProfileListView->currentItem()); + selectdlg.ImportProfileListView->addColumn(i18n("Name")); + selectdlg.ImportProfileListView->addColumn(i18n("Type")); + selectdlg.ImportProfileListView->addColumn(i18n("Gateway")); + selectdlg.ImportProfileListView->addColumn(i18n("Authentication")); + selectdlg.ImportProfileListView->addColumn(i18n("Remote network")); + QCheckListItem *item; + for ( it = ImportedAccountList->first(); it; it = ImportedAccountList->next() ) + { + QString name = it->getName(); + QString type=""; + if ( it->getConnectionType() == VpnAccountData::cisco ) + type = "cisco" ; + else if ( it->getConnectionType() == VpnAccountData::ciscoorig ) + type = "ciscoorig" ; + else if ( it->getConnectionType() == VpnAccountData::racoon ) + type = "racoon" ; + else if ( it->getConnectionType() == VpnAccountData::l2tpd_racoon ) + type = "l2tpd (racoon)" ; + else if ( it->getConnectionType() == VpnAccountData::freeswan ) + type = "ipsec" ; + else if ( it->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + type = "l2tpd (ipsec)" ; + else if ( it->getConnectionType() == VpnAccountData::pptp ) + type = "pptp" ; + else if ( it->getConnectionType() == VpnAccountData::openvpn ) + type = "openvpn" ; + else + type = i18n("other"); + +// litem->setSelectable(true); + item = new QCheckListItem(selectdlg.ImportProfileListView,it->getName(),QCheckListItem::CheckBox); + item->setText(1,type); + item->setText(2,it->getGateway()); + if (it->getAuthType() == VpnAccountData::cert) + item->setText(3,i18n("certificate")); + else if (it->getAuthType() == VpnAccountData::psk) + item->setText(3,i18n("preshared key")); + else if (it->getAuthType() == VpnAccountData::hybrid) + item->setText(3,i18n("hybrid")); + else + item->setText(3,i18n("unknown")); + selectdlg.ImportProfileListView->insertItem(item); + QString RemoteNetDiv="/"; + if (it->getRemoteNetAddr() == "") + { + it->setRemoteNetMask(""); + RemoteNetDiv=""; + } + item->setText(4,QString(it->getRemoteNetAddr()+RemoteNetDiv+it->getRemoteNetMask())); + +// std::cout << "insert profile into listview: " << name << std::endl; + } + } + bool ret = selectdlg.exec(); + + if (ret == true) + { + QListViewItemIterator it2( selectdlg.ImportProfileListView ); + for ( ; it2.current(); ++it2 ) + { + if ( ( (QCheckListItem*)it2.current() )->isOn() ) + { + VpnAccountData *data=NULL; + it = 0; + for ( it = ImportedAccountList->first(); it; it = ImportedAccountList->next() ) + { + if ( it->getName() == ( (QCheckListItem*)it2.current() )->text() && ( (QCheckListItem*)it2.current() )->isOn() ) + { + data = it; + importCount++; + RetName=it->getName(); + break; + } + } + AccountList->append(data); + saveOptions(true, data->getName()); + } + } + if (selectdlg.OpenProfileManagerCheckBox->isChecked() && !ImportedAccountList->isEmpty()) + openProfileManager=true; + } + else + { + KMessageBox::sorry ( 0, i18n ( "Import canceled." ) ); + return false; + } + + + + QString msg=""; + if (importCount > 0 ) + msg = i18n("Import was successful. %1 profiles are imported.").arg(QString::number(importCount)); + else + msg = i18n("Import was canceled because no profiles are selected.").arg(QString::number(importCount)); + + KMessageBox::information ( 0, msg,i18n("Import success") ); + + } + else + { + KMessageBox::error ( 0, i18n ( "Reading of \"%1\" has been failed!" ).arg ( filename ) ); + return false; + } + + + return true; + +} + +bool KVpncConfig::importFritzboxConfig(QString filename, QString& RetName, bool& openProfileManager) +{ + /* + // example of vpn config fritzbox user + version = { + revision = "$Revision: 1.30 $"; + creatversion = "1.1"; + } + + + pwcheck = { + } + + + datapipecfg = { + security = dpsec_quiet; + icmp = { + ignore_echo_requests = no; + destunreach_rate = { + burstfactor = 6; + timeout = 1; + } + timeexceeded_rate = { + burstfactor = 6; + timeout = 1; + } + echoreply_rate = { + burstfactor = 6; + timeout = 1; + } + } + masqtimeouts = { + tcp = 15m; + tcp_fin = 2m; + tcp_rst = 3s; + udp = 5m; + icmp = 30s; + got_icmp_error = 15s; + any = 5m; + tcp_connect = 6m; + tcp_listen = 2m; + } + ipfwlow = { + input = { + } + output = { + } + } + ipfwhigh = { + input = { + } + output = { + } + } + NAT_T_keepalive_interval = 20; + } + + + targets = { + policies = { + name = "My Fritzbox"; + connect_on_channelup = no; + always_renew = no; + reject_not_encrypted = no; + dont_filter_netbios = yes; + localip = 0.0.0.0; + virtualip = 192.168.178.201; + remoteip = 0.0.0.0; + remotehostname = "dnyn.myfb.com"; + localid = { + user_fqdn = "user@domain.com"; + } + mode = mode_aggressive; + phase1ss = "all/all/all"; + keytype = keytype_pre_shared; + key = "geheim"; + cert_do_server_auth = no; + use_nat_t = yes; + use_xauth = no; + use_cfgmode = no; + phase2localid = { + ipaddr = 192.168.178.201; + } + phase2remoteid = { + ipnet = { + ipaddr = 192.168.178.0; + mask = 255.255.255.0; + } + } + phase2ss = "esp-all-all/ah-none/comp-all/pfs"; + accesslist = "permit ip any 192.168.178.0 255.255.255.0"; + wakeupremote = no; + } + } + + + policybindings = { + } + + */ + QFile importfile (filename); + if (!importfile.exists()) + { + KMessageBox::error ( 0, i18n ( "Reading of \"%1\" has been failed!" ).arg ( filename ) ); + return false; + } + if ( importfile.open(IO_ReadOnly)) + { + QString line = NULL; + VpnAccountData *profiledata = new VpnAccountData(VpnAccountData::freeswan,"fritzbox") ; + QTextStream stream(&importfile); + bool datapipecfgFound = false; + bool policiesFound = false; + bool targetsFound = false; + bool localidFound = false; + bool phase2localidFound = false; + bool phase2remoteidFound = false; + bool ipnetFound = false; + bool nameFound = false; + + profiledata->setDescription(QString(i18n("import from ")+filename)); + profiledata->setConnectionType( VpnAccountData::racoon); + profiledata->setUsePerfectForwardSecrety(true); + profiledata->setPerfectForwardSecrety("modp1024"); + profiledata->setUseIkeGroup(true); + profiledata->setIkeGroup("modp1024"); + profiledata->setIpsecIke("aes"); + profiledata->setHashAlgo( "sha1"); + profiledata->setUseAuthenticationAlgorithm(true); + profiledata->setEncryptionAlgorithm( "aes"); + profiledata->setAuthenticationAlgorithm( "hmac_sha1" ); + profiledata->setLocalIDType("user_fqdn"); + profiledata->setReplaceDefaultRoute(false); + profiledata->setNetworkDevice("default"); + profiledata->setUseDnsUpdate(false); + + + while ( !stream.atEnd() ) + { + line = removeWhiteSpaceAtBegin(stream.readLine()).simplifyWhiteSpace(); + if (KvpncDebugLevel > 6) + appendLogEntry(i18n ("import fritzbox config: line: %1").arg(line), debug); + + if (line.startsWith("datapipecfg")) + { + datapipecfgFound = true; + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import fritzbox config: %1 found").arg("datapipecfg"), debug); + } + if (line.startsWith("policies")) + { + policiesFound = true; + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import fritzbox config: %1 found").arg("policies"), debug); + } + if (line.startsWith("targets")) + { + targetsFound = true; + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import fritzbox config: %1 found").arg("targets"), debug); + } + if (line.startsWith("localid")) + { + localidFound = true; + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import fritzbox config: %1 found").arg("localid"), debug); + } + if (line.startsWith("phase2localid")) + { + phase2localidFound = true; + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import fritzbox config: %1 found").arg("phase2localid"), debug); + } + if (line.startsWith("phase2remoteid")) + { + phase2remoteidFound = true; + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import fritzbox config: %1 found").arg("phase2remoteid"), debug); + } + if (line.startsWith("ipnet")) + { + ipnetFound = true; + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import fritzbox config: ipnetFound found"), debug); + } + if ( datapipecfgFound ) + { + // here we can read masq timeouts, and so on. + } + if (targetsFound && policiesFound ) + { + if (line.startsWith("name = ")) + { + QString ProfileName=line.section("= ",1,1).replace("\"","").replace(";","").replace(" ","_"); + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import fritzbox config: %1 found: %2").arg("name").arg(ProfileName) ,debug); + profiledata->setName(ProfileName); + nameFound = true; + } + if (line.startsWith(" always_renew = ")) + { + bool reconnectAfterConnectionLost=false; + if (line.section("= ",1,1).replace(";","") == "yes") + reconnectAfterConnectionLost = true; + if (KvpncDebugLevel > 2) + if (reconnectAfterConnectionLost) + appendLogEntry(i18n ("import fritzbox config: %1 found: %2").arg("always_renew").arg(i18n("yes")) ,debug); + else + appendLogEntry(i18n ("import fritzbox config: %1 found: %2").arg("always_renew").arg(i18n("no")) ,debug); + profiledata->setDoReconnectAfterConnectionLost(reconnectAfterConnectionLost); + } + if (line.startsWith("dont_filter_netbios = ")) + { + bool dont_filter_netbios=false; + if (line.section("= ",1,1).replace(";","") == "yes") + dont_filter_netbios = true; + if (KvpncDebugLevel > 2) + if (dont_filter_netbios) + appendLogEntry(i18n ("import fritzbox config: %1 found: %2").arg("dont_filter_netbios").arg(i18n("yes")) ,debug); + else + appendLogEntry(i18n ("import fritzbox config: %1 found: %2").arg("dont_filter_netbios").arg(i18n("no")) ,debug); + // nothing to yet + } + if (line.startsWith("localip = ")) + { + QString LocalIp=line.section("= ",1,1).replace("\"","").replace(";",""); + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import fritzbox config: %1 found: %2").arg("localip").arg(LocalIp) ,debug); + // nothing to do yet + } + if (line.startsWith("virtualip = ")) + { + QString LocalVirtualIp=line.section("= ",1,1).replace("\"","").replace(";",""); + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import fritzbox config: %1 found: %2").arg("virtualip").arg(LocalVirtualIp) ,debug); + profiledata->setUseLeftSourceIp(true); + profiledata->setLeftSourceIp(LocalVirtualIp); + } + if (line.startsWith("remoteip = ")) + { + QString RemoteIp=line.section("= ",1,1).replace("\"","").replace(";",""); + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import fritzbox config: %1 found: %2").arg("remoteip").arg(RemoteIp) ,debug); + // nothing to do yet + } + if (line.startsWith("remotehostname = ")) + { + QString Gateway=line.section("= ",1,1).replace("\"","").replace(";",""); + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import fritzbox config: %1 found: %2").arg("remotehostname").arg(Gateway) ,debug); + profiledata->setGateway(Gateway); + } + if (localidFound) + { + if (line.startsWith("user_fqdn = ")) + { + QString LocalId=line.section("= ",1,1).replace("\"","").replace(";",""); + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import fritzbox config: %1 found: %2").arg(QString("user_fqdn")+" ("+i18n("local id")+")").arg(LocalId) ,debug); + profiledata->setSpecialLocalID(LocalId); + profiledata->setUseSpecialLocalID(true); + profiledata->setLocalIDType("user_fqdn"); + localidFound = false; + } + } + if (line.startsWith("mode = ")) + { + QString IpsecExchangeMode=line.section("= ",1,1).replace(";",""); + + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import fritzbox config: %1 found: %2").arg(i18n("exchange mode")).arg(IpsecExchangeMode) ,debug); + + if (IpsecExchangeMode == "mode_aggressive") + profiledata->setExchangeMode("aggressive"); + else + profiledata->setExchangeMode("main"); + } + if (line.startsWith("keytype = ")) + { + QString AuthType=line.section("= ",1,1).replace(";",""); + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import fritzbox config: %1 found: %2").arg("keytype").arg(AuthType) ,debug); + + if (AuthType == "keytype_pre_shared") + profiledata->setAuthType(VpnAccountData::psk); + else + profiledata->setAuthType(VpnAccountData::cert); + } + if (line.startsWith("key = ")) + { + QString PreshardKey=line.section("= ",1,1).replace("\"","").replace(";",""); + if (KvpncDebugLevel > 2 && KvpncDebugLevel < 5) + appendLogEntry(i18n ("import fritzbox config: %1 found: %2").arg("key").arg("******") ,debug); + if (KvpncDebugLevel > 5) + appendLogEntry(i18n ("import fritzbox config: %1 found: %2").arg("key").arg(PreshardKey) ,debug); + profiledata->setPreSharedKey(PreshardKey); + profiledata->setPskIsInFile(false); + } + if (line.startsWith("cert_do_server_auth = ")) + { + bool cert_do_server_auth=false; + if (line.section("= ",1,1).replace(";","") == "yes") + cert_do_server_auth = true; + if (KvpncDebugLevel > 2) + if (cert_do_server_auth) + appendLogEntry(i18n ("import fritzbox config: %1 found: %2").arg("cert_do_server_auth").arg(i18n("yes")) ,debug); + else + appendLogEntry(i18n ("import fritzbox config: %1 found: %2").arg("cert_do_server_auth").arg(i18n("no")) ,debug); + // nothing to to yet + } + if (line.startsWith("use_nat_t = ")) + { + bool UseNat=false; + if (line.section("= ",1,1).replace(";","") == "yes") + UseNat = true; + if (KvpncDebugLevel > 2) + if (UseNat) + appendLogEntry(i18n ("import fritzbox config: %1 found: %2").arg("use_nat_t").arg(i18n("yes")) ,debug); + else + appendLogEntry(i18n ("import fritzbox config: %1 found: %2").arg("use_nat_t").arg(i18n("no")) ,debug); + profiledata->setUseNat(UseNat); + profiledata->setUseUdp(true); + } + if (line.startsWith("use_xauth = ")) + { + bool UseXauth=false; + if (line.section("= ",1,1).replace(";","") == "yes") + UseXauth = true; + if (KvpncDebugLevel > 2) + if (UseXauth) + appendLogEntry(i18n ("import fritzbox config: %1 found: %2").arg("use_xauth").arg(i18n("yes")) ,debug); + else + appendLogEntry(i18n ("import fritzbox config: %1 found: %2").arg("use_xauth").arg(i18n("no")) ,debug); + profiledata->setAuthWithUsernameAndPassword(UseXauth); + } + if (line.startsWith("use_cfgmode = ")) + { + bool ModeConfig=false; + if (line.section("= ",1,1).replace(";","") == "yes") + ModeConfig = true; + if (KvpncDebugLevel > 2) + if (ModeConfig) + appendLogEntry(i18n ("import fritzbox config: %1 found: %2").arg("use_cfgmode").arg(i18n("yes")) ,debug); + else + appendLogEntry(i18n ("import fritzbox config: %1 found: %2").arg("use_cfgmode").arg(i18n("no")) ,debug); + profiledata->setUseModeConfig(ModeConfig); + } + if (phase2localidFound) + { + if (line.startsWith("ipaddr = ")) + { + QString Phase2LocalId=line.section("= ",1,1).replace("\"","").replace(";",""); + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import fritzbox config: %1 found: %2").arg(i18n("ip addr for phase 2")).arg(Phase2LocalId) ,debug); + // nothing to do yet + } + } + if (phase2remoteidFound && ipnetFound) + { + profiledata->setUseRemoteNetwork(true); + if (line.startsWith("ipaddr = ")) + { + QString RemoteNetWorkAddr=line.section("= ",1,1).replace(";",""); + if (KvpncDebugLevel > 2) + appendLogEntry(i18n ("import fritzbox config: %1 found: %2").arg(i18n("remote network ip")).arg(RemoteNetWorkAddr) ,debug); + profiledata->setRemoteNetAddr(RemoteNetWorkAddr); + } + if (line.startsWith("mask = ")) + { + QString RemoteNetWorkMask=line.section("= ",1,1).replace(";",""); + QString RemoteNetWorkMaskNumeric = QString().setNum(Utils(this).dottedIpv4Netmask2NetmaskBytes(RemoteNetWorkMask)); + if (KvpncDebugLevel > 2) + { + appendLogEntry(i18n ("import fritzbox config: %1 found: %2").arg(i18n("remote network netmask")).arg(RemoteNetWorkMask) ,debug); + + appendLogEntry(i18n("Netmask (dotted): %1, numeric value: %2").arg(RemoteNetWorkMask).arg(RemoteNetWorkMaskNumeric), debug); + } + profiledata->setRemoteNetMask(RemoteNetWorkMaskNumeric); + } + } + } + } + if (policiesFound && nameFound) + { + + bool ok = false; + VpnAccountData * it; + bool nameOk = false; + while ( nameOk == false ) + { + for ( it = AccountList->first(); it; it = AccountList->next() ) + { + if ( it->getName() == profiledata->getName() ) + { + //account->setName( QString( account->getName() + "_2" ) ); + // KMessageBox::information ( this, i18n( "Profile name exists!\n It will be renamed to \"%1\"." ).arg( account->getName() ), i18n( "Name exist, renamed" ) ); + KMessageBox::error ( 0, i18n ( "Profile name exists!" ), i18n ( "Name Exists" ) ); + nameOk = false; + QString newName = KInputDialog::getText ( i18n ( "New Name" ), i18n ( "New name for profile:" ), QString ( profiledata->getName() + "_2" ), &ok ); + if (newName.isEmpty()) + { + KMessageBox::information ( 0, i18n ( "Import was canceled." ) ); + appendLogEntry ( i18n ( "Import was canceled." ), info ); + return false; + } + if (newName != it->getName() ) + { + profiledata->setName ( newName ); + nameOk = true; + } + } + else + { + nameOk = true; + } + } + } + + if ( nameOk == true ) + { + AccountList->append(profiledata); + RetName = profiledata->getName(); + saveOptions(true, RetName); + appendLogEntry ( i18n ( "Import of \"%1\" (%2) was successful." ).arg ( profiledata->getName() ).arg ( "Fritzbox" ), info ); + + QString bin = "racoon"; + ToolInfo *tool; + //std::cout << "Tool (bin): " << bin << std::endl; + if ( !ToolList->isEmpty() ) + { + for ( tool = ToolList->first(); tool; tool = ToolList->next() ) + { + if ( bin == tool->Name ) + { + if ( tool->PathToExec.section ( '/', -1 ) != bin ) + { + // program is NOT installed + KMessageBox::information ( 0, i18n ( "The required tool (%1) is not installed, please install it before you are connecting and restart kvpnc." ).arg ( bin ), i18n ( "Tool Missing" ) ); + } + break; + } + } + } + } + else + { + KMessageBox::information ( 0, i18n ( "Import was canceled." ) ); + appendLogEntry ( i18n ( "Import was canceled." ), info ); + return false; + } + + } + QString msg=""; + if (policiesFound && nameFound) + msg = i18n("Import was successful. 1 profile was imported."); + else + msg = i18n("Import was canceled because no profile was found."); + + KMessageBox::information ( 0, msg,i18n("Import success") ); + return policiesFound && nameFound; + } + else + { + KMessageBox::error ( 0, i18n ( "Reading of \"%1\" has been failed!" ).arg ( filename ) ); + return false; + } + return true; + +} + +VpnAccountData* KVpncConfig::findProfile(QPtrList *list,const QString& Name) +{ + VpnAccountData *it=NULL; + bool found=false; + if ( !list->isEmpty() ) + { + for ( it = list->first(); it; it = list->next() ) + { +// std::cout << "findProfile(): it: " << it->getName() << " Name: " << Name << std::endl; + if (Name == it->getName()) + { + found=true; +// std::cout << "findProfile(): profile found." << std::endl; + break; + } + } + } + if (found) + return it; + else + { +// std::cout << "findProfile(): profile not found." << std::endl; + return NULL; + } +} + +QString KVpncConfig::removeWhiteSpaceAtBegin(const QString str) +{ + QString newstr=""; + int i=0; + for (i=0;i<(int)str.length();i++) + { + if (!QChar(str.at(i)).isSpace()) + break; + } + newstr = str.right(str.length()-i); + return newstr; +} + +void KVpncConfig::doBackupConfig() +{ + KStandardDirs * dirs = KGlobal::dirs(); + QString config = QString(dirs->saveLocation( "config" )+"/kvpncrc"); + QFile OriginalConfFile( config ); + QFile backupOriginalConfFile( config+".backup" ); + QTextStream writestream( &backupOriginalConfFile ); + QTextStream readstream( &OriginalConfFile ); + if ( OriginalConfFile.open( IO_ReadOnly ) ) + { + if (backupOriginalConfFile.open(IO_WriteOnly)) + { + QString OriginalConfFileContent = QString( OriginalConfFile.readAll() ) ; + writestream << OriginalConfFileContent; + OriginalConfFile.close(); + backupOriginalConfFile.close(); + } + } +} + +void KVpncConfig::restoreBackupConfig() +{ + KStandardDirs * dirs = KGlobal::dirs(); + QString config = QString(dirs->saveLocation( "config" )+"/kvpncrc"); + QFile OriginalConfFile( config+".backup" ); + QFile backupOriginalConfFile( config ); + QTextStream writestream( &backupOriginalConfFile ); + QTextStream readstream( &OriginalConfFile ); + if ( OriginalConfFile.open( IO_ReadOnly ) ) + { + if (backupOriginalConfFile.open(IO_WriteOnly)) + { + QString OriginalConfFileContent = QString( OriginalConfFile.readAll() ) ; + writestream << OriginalConfFileContent; + OriginalConfFile.close(); + backupOriginalConfFile.close(); + } + } +} + +void KVpncConfig::getToolsInfo() +{ + ToolInfo *it; + //std::cout << "Tool (bin): " << bin << std::endl; + if (!ToolList->isEmpty()) + { + for ( it = ToolList->first(); it; it = ToolList->next() ) + { + it->collectToolInfo(); + } + } +} + +void KVpncConfig::removeEntry(QString Name) +{ + KStandardDirs * dirs = KGlobal::dirs(); + QString filePath = dirs->findResource ( "config", "kvpncrc" ); + + appPointer->processEvents(); + + if (useKwallet && KWallet::Wallet::isEnabled()) + config->deleteEntry( "First use of Kwallet", false ); + /* = user data = */ + VpnAccountData *it; + if ( !AccountList->isEmpty() ) + { + for ( it = AccountList->first(); it; it = AccountList->next() ) + { + if ( !it->getName().isEmpty() ) + { + QString name = it->getName(); + if (it->getName() == Name) + { + //std::cout << "Remove profile: " << it->getName() << std::endl; + QString ProfileName = "Profile_"; + ProfileName += name; + config->setGroup( ProfileName ); + + /* passwords with kwallet */ + if ( useKwallet && KWallet::Wallet::isEnabled()) + { + // if (KvpncDebugLevel > 0) + // appendLogEntry(i18n( "Wallet enabled and available, writing to wallet." ),debug); + // // Open local wallet + wallet = KWallet::Wallet::openWallet(KWallet::Wallet::LocalWallet()); + if (wallet != 0) + { + QString walletname="kvpnc"; + // Check if folder exists, otherwise create it + bool walletOK=true; + if (!wallet->hasFolder(walletname)) + { + walletOK = wallet->createFolder(walletname); + wallet->sync(); + } + if (walletOK) + { + wallet->setFolder(walletname); + //std::cout << "[set] account: " << ProfileName << ", loginname: " << loginname << ", password: " << pwd << std::endl; + bool UserPasswordOK = (wallet->removeEntry (QString(name+"__user_pw")) == 0); + bool PskOK= (wallet->removeEntry (QString(name+"__psk")) == 0); + bool PskKeyPassOK = (wallet->removeEntry (QString(name+"__priv_key_pwd")) == 0); +// wallet->sync(); + + if (KvpncDebugLevel > 2) + { + if (UserPasswordOK) + appendLogEntry(i18n( "delete of %1 was ok." ).arg(i18n("user password")), debug); + else + appendLogEntry(i18n( "delete of %1 has failed." ).arg(i18n("user password")), debug); + // + if (PskOK) + appendLogEntry(i18n( "delete of %1 was successful." ).arg(i18n("preshared key")), debug); + else + appendLogEntry(i18n( "delete of %1 has failed." ).arg(i18n("preshared key")),debug); + + if (PskKeyPassOK) + appendLogEntry(i18n( "delete of %1 was successful." ).arg(i18n("private key password")), debug); + else + appendLogEntry(i18n( "delete of %1 has failed." ).arg(i18n("private key password")),debug); + + + // //std::cout << "success: " << pwdOK << std::endl; + } + } + else + { + KMessageBox::error( 0, i18n( "Unable to create wallet folder for kvpnc!" ) ); + appendLogEntry(i18n( "Unable to create wallet folder for kvpnc!" ), error); + } + } + } + if (KvpncDebugLevel > 0) + appendLogEntry(i18n( "Wallet disabled or not available, writing to config file." ),debug); + // write passwords to config file :| + config->deleteEntry( "User password" ); + config->deleteEntry( "Pre shared key" ); + config->deleteEntry( "PrivateKey password" ); + // } + + config->deleteEntry( "Connection type" ); + config->deleteEntry( "VPN Gateway" ); + config->deleteEntry( "VPN ID" ); + config->deleteEntry( "Username" ); + config->deleteEntry( "Save user password" ); + config->deleteEntry( "Save PSK" ); + config->deleteEntry( "Private key" ); + config->deleteEntry( "Use advanced settings" ); + config->deleteEntry( "Application version" ); + config->deleteEntry( "Local port" ); + config->deleteEntry( "NT domain name" ); + config->deleteEntry( "Perfect forward secrety" ); + config->deleteEntry( "IKE group" ); + config->deleteEntry( "Use application version" ); + config->deleteEntry( "Use global IPSec secret" ); + config->deleteEntry( "Use IKE group" ); + config->deleteEntry( "Use local port" ); + config->deleteEntry( "Use NT domain name" ); + config->deleteEntry( "Use single DES" ); + config->deleteEntry( "Use perfect Forward Secrety" ); + config->deleteEntry( "Remote net address" ); + config->deleteEntry( "Remote net mask" ); + config->deleteEntry( "x509 certificate" ); + config->deleteEntry( "Ca certificate" ); + config->deleteEntry( "Network device" ); + config->deleteEntry( "Cert path" ); + config->deleteEntry( "Auth type"); + config->deleteEntry( "do ping ip" ); + config->deleteEntry( "Ping host IP" ); + config->deleteEntry( "Use special remote ID" ); + config->deleteEntry( "Special server certificate" ); + config->deleteEntry( "Use special server certificate" ); + config->deleteEntry( "Special remote ID" ); + config->deleteEntry( "Use UDP-protocol" ); + config->deleteEntry( "Use UDP-port" ); + config->deleteEntry( "local UDP port" ); + config->deleteEntry( "use DNS_UPDATE" ); + config->deleteEntry( "use DNS-server" ); + config->deleteEntry( "DNS server" ); + config->deleteEntry( "get dns server from peer" ); + config->deleteEntry( "refuse 40 bit encryption" ); + + appPointer->processEvents(); + + config->deleteEntry( "refuse 128 bit encryption" ); + config->deleteEntry( "require stateless encryption" ); + config->deleteEntry( "require mppe" ); + config->deleteEntry( "Disable MPPE compression" ); + config->deleteEntry( "Local virtual IP" ); + config->deleteEntry( "Remote virtual IP" ); + config->deleteEntry( "Pre shared key file" ); + config->deleteEntry( "Execute command before connect" ); + config->deleteEntry( "Execute command after connect" ); + config->deleteEntry( "Execute command before disconnect" ); + config->deleteEntry( "Execute command after disconnect" ); + config->deleteEntry( "Command before connect" ); + config->deleteEntry( "Command after connect" ); + config->deleteEntry( "Command before disconnect" ); + config->deleteEntry( "Command after disconnect" ); + config->deleteEntry( "Use no BSD compression" ); + config->deleteEntry( "Use no deflate" ); + config->deleteEntry( "Set default route" ); + config->deleteEntry( "Replace default route" ); + config->deleteEntry( "Use own MTU" ); + config->deleteEntry( "Use own MRU" ); + config->deleteEntry( "MTU for pppd" ); + config->deleteEntry( "MRU for pppd" ); + config->deleteEntry( "Use Virtual IP" ); + config->deleteEntry( "Virtual IP" ); + config->deleteEntry( "PSK is in file" ); + config->deleteEntry( "Use additional network routes" ); + config->deleteEntry( "Hash algorithm" ); + config->deleteEntry( "Tunnel device type" ); + config->deleteEntry( "Use userdefined port" ); + config->deleteEntry( "Userdefined port" ); + config->deleteEntry( "Keep default route" ); + config->deleteEntry( "Additional network routes" ); + config->deleteEntry("AuthWithUsernameAndPassword" ); + config->deleteEntry("AllowEmptyGroupPassword" ); + config->deleteEntry("Encryption algorithm"); + config->deleteEntry("Authentication algorithm"); + + config->deleteGroup( ProfileName ); + + /* give info */ + //slotStatusMsg ( i18n( "Profile \"%1\" removed." ).arg( Name ), ID_FLASH_MSG ); + appendLogEntry ( i18n( "Profile \"%1\" removed." ).arg( Name ) , info); + AccountList->remove(it); + break; + } + } + } + appPointer->processEvents(); + } + config->sync(); + appPointer->processEvents(); +} + diff --git a/src/kvpncconfig.h b/src/kvpncconfig.h new file mode 100644 index 0000000..4ea2ddd --- /dev/null +++ b/src/kvpncconfig.h @@ -0,0 +1,271 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef __KVPNCCONFIG_H__ +#define __KVPNCCONFIG_H__ + +//BEGIN INCLUDES +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "toolinfo.h" +#include "vpnaccountdata.h" + +// ID for statusbar +#define ID_STATUS_MSG 1 +#define ID_CONNECTION_MSG 2 +#define ID_FLASH_MSG 3 +//END INCLUDES + +/** +This class holds global configuration data. +@author Christoph Thielecke +*/ +class KVpncConfig : public QObject +{ +public: + KVpncConfig(QWidget *parent,KStatusBar *statusbar); + ~KVpncConfig(); + +public: + enum ConnectionStatus {disconnected=0, connecting=1, connected=2}; + enum LogType {info=0, remote=1, error=2, success=3, debug=4}; + + QString pathToVpnc; + QString pathToCiscoVpnc; + QString pathToRacoon; + QString pathToRacoonctl; + QString pathToSetkey; + QString pathToIptables; + QString pathToOpenssl; + QString pathToIpsec; + QString pathToPppd; + QString pathToPptp; + QString pathToL2tpd; + QString pathToXl2tpd; + QString pathToOpenl2tp; + QString pathToKill; + QString pathToKillall; + QString pathToPing; + QString pathToOpenvpn; + QString pathToIp; + QString pathToIfconfig; + QString pathToRoute; + QString pathToNetstat; + QString pathToPkcs11Tool; + QString pathToVtund; + QString pathToCiscoCertMgr; + QString pathToTail; + QString pathToSsh; + QString pathToKsshAskpass; + QString pathToGnomeSshAskpass; + QString AutoConnectProfile; + QString RacoonDebugLevel; + QString Vpnc_pid_file; + QString Pppd_pid_file; + QString lastProfile; + QString logfileName; + QString InterpreterShell; + + QString TmpPassword; //< from enter password dialog + QString TmpGroupPassword; //< from enter password dialog + QString TmpUsername; //< from enter password dialog + QString TmpPrivKeyPassStr; + QString TmpGatewayIP; + QString TmpXauthInterPasscode; //< from Xauth interactive passcode dialog + QString TmpPrivateKeyPass; + QString TmpHttpProxyPassword; + QString DnsDevice; //< device which the dns entry was added + + QString OldDefaultGw; //< default gw before connect + QString OldDefaultDev; //< default gw dev before connect + + QString NewDefaultGw; + + QStringList PlutoDebug; + QStringList KlipsDebug; + + bool minimizeAfterConnect; + bool showDebugConsole; + bool writeLogFile; + bool useDefaultPaths; + bool useSilentQuit; + bool holdGeneratedScripts; + bool programsInPath; + bool enableDebugPppd; + bool enableDebugPptpd; + bool enableDebugL2tpd; + bool enableDebugXl2tpd; + bool enableDebugOpenl2tp; + + bool enableDebugXl2tpdNetwork; + bool enableDebugXl2tpdpacket; + bool enableDebugXl2tpdstate; + bool enableDebugXl2tpdtunnel; + + bool enableFreeswanVerbose; + bool enableDebugOpenvpn; + bool useColorizedLogOutput; + bool showInterfaceIPinTooltip; + bool dontQuitOnCloseEvent; + bool doAutoConnectAtStartup; + bool useKwallet; + bool showStatusBar; + bool showToolBar; + bool hideMainWindow; + bool PppdDebugLevel; + bool firstUseOfKwallet; //< for importing passwords if there are stored before + bool shutdownIsCalled; + bool haveUserData; //< flag if user data already collected, set after data is entered and unset if authretry + bool skipKwalletStoring; //< true if save should skip saving into kwallet + bool hideOnCloseInfo; + bool feedbackMailSent; + bool doKillL2tpdIfStillRunning; //< kill l2tpd if its still running and not started from kvpnc + bool doKillXl2tpdIfStillRunning; //< kill xl2tpd if its still running and not started from kvpnc + bool doKillRacoonIfStillRunning; //< kill racoon if its still running and not started from kvpnc + bool showConnectionTimeInTooltip; //< True if the connection duration should be shown in kicker tooltip + bool WaitingForXauth; //< if waiting for xauth is set to true, needed to detect wrong xautn data on strongswan + bool prefDlgOpen; //< if true prefDlgOpen is open + + bool OpenvpnNeedSecurityParameter; + + int VpncDebugLevel; + int KvpncDebugLevel; + int OpenvpnDebugLevel; + int PptpLogLevel; + int PppdKernelLogLevel; + int SshDebugLevel; + int LogViewerFontSize; + int mainwindow_pos_x; + int mainwindow_pos_y; + int mainwindow_height; + int mainwindow_width; + int connectSleepDelay; //< time beetween retry + int connectSleepRetry; //< count of retries + int tryConnectTimeout; //< timeout in at connecting + int connectionStartTime; + int runningCheckCounter; + int runningCheckTimeout; + int OpenvpnManagementPort; + int AuthRetryCount; //< count of autn retry + int maxConnectRetry; // max connect tries + int currentConnectRetry; + + QPtrList *ToolList; + QPtrList *AccountList; + VpnAccountData *currentProfile; + + QColor InfoLogColor; + QColor RemoteLogColor; + QColor ErrorLogColor; + QColor SuccessLogColor; + QColor DebugLogColor; + QColor DebugBackgroundcolor; + + QApplication *appPointer; + QPoint pos; + ConnectionStatus status; + QFile logfile; + QTextStream logFileStream; + QTextEdit *LogOutput; + KWallet::Wallet *wallet; + KConfig* config; //< configuration data + + QPoint WindowPos; + QSize WindowSize; + + struct IpsecImportSection { + QString SectionName; + QStringList SectionData; + }; + + QPtrList *ImportedAccountList; + + QWidget *parent; + KStatusBar *statusbar; + + /** + * Appends a log enty to debug console and log file + * @param msg the text to append + * @param type the type of the msg (info, debug, error, etc) + */ + void appendLogEntry( QString msg, LogType type ); + + /** + * Sets the output textedit for debug output + * @param LogOutput + */ + void setLogOutput(QTextEdit *LogOutput); + + /** + * save configuration + */ + void saveOptions(bool saveOneProfile=false, QString Profile="" ); + + /** + * load configuration + */ + void loadOptions(); + + /** + * check the value of the paths + */ + void checkStandardPathValues(); + + /** + * collects the information of the external helper programs + */ + void getToolsInfo(); + + + /** + * removes a entry from configuration file + * @param Name the entry which should be removed + */ + void removeEntry(QString Name); + + VpnAccountData* findProfile(QPtrList *list,const QString& Name); + QString removeWhiteSpaceAtBegin(const QString); + + void slotStatusMsg( const QString &text, int id = ID_STATUS_MSG ); + void doBackupConfig(); + void restoreBackupConfig(); + + bool exportKvpncConfig(QString filename); + bool importKvpncConfig(QString filename, QString& Name, bool& openProfileManager); //< true if profiles imported + + bool importIpsecConfig(QString filename, QString& Name, bool& openProfileManager); + bool importFritzboxConfig(QString filename, QString& Name, bool& openProfileManager); + +}; + +#endif diff --git a/src/kvpncimportprofileselectiondialog.cpp b/src/kvpncimportprofileselectiondialog.cpp new file mode 100644 index 0000000..53c99a3 --- /dev/null +++ b/src/kvpncimportprofileselectiondialog.cpp @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "kvpncimportprofileselectiondialog.h" +#include +#include +#include + +KvpncImportProfileSelectionDialog::KvpncImportProfileSelectionDialog() +{ + allSelected = false; + connect (ToggleAllPushButton, SIGNAL(clicked()), this, SLOT(importAllToggled())); +} + + +KvpncImportProfileSelectionDialog::~KvpncImportProfileSelectionDialog() +{ +} + +void KvpncImportProfileSelectionDialog::importAllToggled() +{ + QListViewItemIterator it2( (QListView *) ImportProfileListView ); + for ( ; it2.current(); ++it2 ) + { + ((QCheckListItem*)it2.current())->setOn(!allSelected); + } + allSelected=!allSelected; +} + diff --git a/src/kvpncimportprofileselectiondialog.h b/src/kvpncimportprofileselectiondialog.h new file mode 100644 index 0000000..0a451bd --- /dev/null +++ b/src/kvpncimportprofileselectiondialog.h @@ -0,0 +1,42 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef KVPNCIMPORTPROFILESELECTIONDIALOG_H +#define KVPNCIMPORTPROFILESELECTIONDIALOG_H + +#include "kvpncimportprofileselectiondialogbase.h" + +/** + @author Christoph Thielecke +*/ +class KvpncImportProfileSelectionDialog : public KvpncImportProfileSelectionBase +{ +Q_OBJECT +public: + KvpncImportProfileSelectionDialog(); + ~KvpncImportProfileSelectionDialog(); + +public slots: + void importAllToggled(); + +private: + bool allSelected; +}; + +#endif diff --git a/src/kvpncimportprofileselectiondialogbase.ui b/src/kvpncimportprofileselectiondialogbase.ui new file mode 100644 index 0000000..85e51db --- /dev/null +++ b/src/kvpncimportprofileselectiondialogbase.ui @@ -0,0 +1,221 @@ + +KvpncImportProfileSelectionBase + + + KvpncImportProfileSelectionBase + + + + 0 + 0 + 698 + 457 + + + + Select profiles + + + + unnamed + + + + layout10 + + + + unnamed + + + + textLabel + + + Select profile for import: + + + + + ImportProfileListView + + + + + layout9 + + + + unnamed + + + + ImportGlobalSettingsCheckBox + + + import &global settings + + + Alt+G + + + + + OpenProfileManagerCheckBox + + + open &profile manager after import + + + Alt+P + + + + + spacer3 + + + Horizontal + + + Expanding + + + + 271 + 21 + + + + + + + + layout8 + + + + unnamed + + + + spacer4 + + + Horizontal + + + Expanding + + + + 271 + 21 + + + + + + textLabel1 + + + Import name prefix: + + + + + ImportNamePrefixLineEdit + + + + 100 + 0 + + + + + + + + layout7 + + + + unnamed + + + + CancelPushButton + + + Cancel + + + + + spacer1 + + + Horizontal + + + Expanding + + + + 260 + 31 + + + + + + ToggleAllPushButton + + + Togg&le all + + + Alt+L + + + + + ImportPushButton + + + &Import selected profiles + + + Alt+I + + + + + + + + + + + CancelPushButton + clicked() + KvpncImportProfileSelectionBase + reject() + + + ImportPushButton + clicked() + KvpncImportProfileSelectionBase + accept() + + + + + klistview.h + klineedit.h + kpushbutton.h + kpushbutton.h + kpushbutton.h + + diff --git a/src/kvpnckicker.cpp b/src/kvpnckicker.cpp new file mode 100644 index 0000000..7f24699 --- /dev/null +++ b/src/kvpnckicker.cpp @@ -0,0 +1,84 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include "kvpnckicker.h" +#include "kvpnc.h" + +KVpncKicker::KVpncKicker( KVpncConfig *GlobalConfig,QWidget* parent, const char *name ) + : KSystemTray( parent, name ) { + this->parent = parent; + this->initDockWindow(); + this->GlobalConfig = GlobalConfig; + KAction *quit = actionCollection()->action( "file_quit" ); + quit->disconnect(); + KVpnc *myParent = static_cast( parent ); + connect( quit, SIGNAL( activated() ), myParent, SLOT( quitCalledKicker() ) ); + + show(); +} + +KVpncKicker::~KVpncKicker() {} + +void KVpncKicker::closeEvent( QCloseEvent *e ) +{ + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "CloseEvent recieved (reciever: %1)." ).arg("kvpnckicker"), GlobalConfig->debug ); + + emit closeEventKicker(e); +} + +void KVpncKicker::enterEvent( QEvent* e ) +{ + if (e->type() == QEvent::Enter) + emit tooltipRequested(); + + KSystemTray::enterEvent(e); + +} + +void KVpncKicker::setStatus( int status ) { + if ( status == connecting ) { + setPixmap( connectingIcon ); + } + else if (status == connected){ + setPixmap( connectedIcon ); + } + else + setPixmap( disconnectedIcon ); +} + +void KVpncKicker::initDockWindow() { + disconnectedIcon = loadIcon( "disconnected"); + connectedIcon = loadIcon( "connected" ); + connectingIcon = loadIcon( "connecting" ); + //setFixedSize( DOCK_WIDTH, DOCK_HEIGHT ); + setPixmap( disconnectedIcon ); + QToolTip::add(this, i18n("Disconnected")); +} + +KPopupMenu* KVpncKicker::menu() { + return contextMenu(); +} diff --git a/src/kvpnckicker.h b/src/kvpnckicker.h new file mode 100644 index 0000000..60f94c5 --- /dev/null +++ b/src/kvpnckicker.h @@ -0,0 +1,60 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __KVPNCKICKER_H__ +#define __KVPNCKICKER_H__ + +#include +#include +#include +#include +#include + +#include "kvpncconfig.h" + +class KVpncKicker : public KSystemTray { + Q_OBJECT +public: + KVpncKicker( KVpncConfig *GlobalConfig,QWidget*parent = 0, const char *name = 0 ); + ~KVpncKicker(); + KPopupMenu* menu(); + enum status {disconnected=0, connecting=1, connected=2}; + void setStatus( int status ); +public slots: + void closeEvent( QCloseEvent* e ); + void enterEvent( QEvent* e ); +protected: + void initDockWindow(); + QWidget *parent; + KVpncConfig *GlobalConfig; + +private: + // color + QColor currentStatus; + // icons + QPixmap connectedIcon; + QPixmap disconnectedIcon; + QPixmap connectingIcon; +signals: + void closeEventKicker(QCloseEvent *e); + void tooltipRequested(); + +}; + +#endif diff --git a/src/kvpncui.rc b/src/kvpncui.rc new file mode 100644 index 0000000..6144f50 --- /dev/null +++ b/src/kvpncui.rc @@ -0,0 +1,54 @@ + + + + &File + + + + &Profile + + + + + + + + + + + + + + + + + + + &KVpnc + + + + + + + + + + + &Help + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/listviewtooltip.cpp b/src/listviewtooltip.cpp new file mode 100644 index 0000000..49c886f --- /dev/null +++ b/src/listviewtooltip.cpp @@ -0,0 +1,24 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "listviewtooltip.h" + + + + diff --git a/src/listviewtooltip.h b/src/listviewtooltip.h new file mode 100644 index 0000000..07c3293 --- /dev/null +++ b/src/listviewtooltip.h @@ -0,0 +1,73 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef __LISTVIEWTOOLTIP_H__ +#define __LISTVIEWTOOLTIP_H__ +#include +#include +#include + +#include + +/** + @author Christoph Thielecke +*/ +class ListViewToolTip : public QToolTip +{ + public: + ListViewToolTip ( QListView* parent ); + protected: + void maybeTip ( const QPoint& p ); + private: + QListView* listView; +}; +inline ListViewToolTip::ListViewToolTip ( QListView* parent ) : QToolTip ( parent->viewport() ), listView ( parent ) {} +inline void ListViewToolTip::maybeTip ( const QPoint& p ) +{ + if ( !listView ) + return; + const QListViewItem* item = listView->itemAt ( p ); + if ( !item ) + return; + const QRect itemRect = listView->itemRect ( item ); + if ( !itemRect.isValid() ) + return; + const int col = listView->header()->sectionAt ( p.x() ); + const int row = listView->header()->sectionAt ( p.y() ); + if ( col == -1 && row == -1 ) + return; + + const QRect headerRect = listView->header()->sectionRect ( col ); + if ( !headerRect.isValid() ) + return; +// const QRect cellRect ( headerRect.left(), itemRect.top(), +// headerRect.width(), itemRect.height() ); + const QRect cellRect ( headerRect.left(), itemRect.top(), 400, 200 ); + QString tipStr; + tipStr = QString ( "

"+item->text ( 0 )+"

  • "+i18n("Path:")+" "+item->text(5)+"
  • "+i18n("Usability:")+" "+item->text(3)+"
  • "+i18n("Comment:")+ " "+item->text(6)+"
"); + + tip ( cellRect, tipStr ); +} +#endif + + + + + + diff --git a/src/logviewerdialog.cpp b/src/logviewerdialog.cpp new file mode 100644 index 0000000..dbedf89 --- /dev/null +++ b/src/logviewerdialog.cpp @@ -0,0 +1,275 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "logviewerdialog.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +LogViewerDialog::LogViewerDialog(QWidget *parent, QApplication *app, KVpncConfig *GlobalConfig,const QString& caption, int count) : KDialogBase( parent, "Show_log", false, caption, +KDialogBase::Ok|KDialogBase::Cancel,KDialogBase::Ok, true ) +{ + main = new LogViewerDialogBase (this); + setMainWidget(main); + // main->setMinimumSize(main->sizeHint()); + main->setMinimumSize(750,500); + main->LineCountIntSpinBox->setValue(count); + + this->GlobalConfig = GlobalConfig; + this->app = app; + + // QPixmap info_icon = KGlobal::iconLoader()->loadIcon( "button_ok", KIcon::NoGroup, 16 ); + // QPixmap debug_icon = KGlobal::iconLoader()->loadIcon( "button_cancel", KIcon::NoGroup, 16 ); + // QPixmap error_icon = KGlobal::iconLoader()->loadIcon( "button_ok", KIcon::NoGroup, 16 ); + // QPixmap debug_icon = KGlobal::iconLoader()->loadIcon( "button_cancel", KIcon::NoGroup, 16 ); + + // InfoListView->setSorting(1); + + connect (main->LineCountApplyPushButton,SIGNAL(clicked()),this, SLOT(updateLineCountClicked())); + connect (main->FindPushButton,SIGNAL(clicked()),this, SLOT(findLogEntryClicked())); + + QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) ); + parseLog(); + QApplication::restoreOverrideCursor(); + + showLogPart(count*-1,count); + } +LogViewerDialog::~LogViewerDialog() +{} + +void LogViewerDialog::accept() +{ + QDialog::accept(); +} + + +void LogViewerDialog::parseLog() +{ + + KStandardDirs *dirs = KGlobal::dirs(); + QString logfileName = dirs->saveLocation( "data" ); + logfileName += "/kvpnc/kvpnc.log"; + QFile logfile; + int linecount=0; + //std::cout << "file exists: " << logfile.exists() << std::endl; + logfile.setName( logfileName ); + + if (logfile.open(IO_ReadOnly )) + { + char *tmpbuf= new char[500]; + int localcount=0; + while (logfile.readLine(tmpbuf, 500) > -1) + { + linecount++; + localcount++; + if (localcount == 50) + { + localcount=0; + app->processEvents(); + } + } + logfile.close(); + delete tmpbuf; + } + +// std::cout << "count: " << linecount << std::endl; + + KProgressDialog *ProgressDlg = new KProgressDialog (0, "loadprogress", i18n("Load progress"), i18n("Loading log..."), true); + ProgressDlg->progressBar()->setTotalSteps(linecount); + ProgressDlg->show(); + ProgressDlg->resize(ProgressDlg->width()+100,ProgressDlg->height()); + + if (logfile.open(IO_ReadOnly )) + { + QTextStream stream( &logfile ); + QString line; + QString lines; + QString prefix; + QString postfix; +// int type=0; + int i=0; + int localcount=0; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' + LogList.append(line); + i++; + localcount++; + ProgressDlg->progressBar()->setValue(i); + if (localcount == 100) + { + localcount=0; + app->processEvents(); + } + } + logfile.close(); + main->LineCountIntSpinBox->setMaxValue(i); + } + ProgressDlg->close(); + +} + +void LogViewerDialog::updateLineCountClicked() +{ + int count = main->LineCountIntSpinBox->value(); + main->LogTextBrowser->clear(); + showLogPart(count*-1,count); +} + +/** + * + * @param start + * @param count + */ +void LogViewerDialog::showLogPart(int start,int count, bool parseLogType) +{ + int startval=0; + if (start < 0) + { + // startval entries from end + + if (int(LogList.count()+start-1) < 0) + startval = 0; + else + startval= LogList.count()-1+start; + if (count+start > 0) + count = LogList.count()-1; + + } + else if (start > 0) + { + + + + } + + +// QString msg = QString("start: "); +// msg+=QString().setNum(startval); +// msg+=QString(", count: "); +// msg+=QString().setNum(count); +// msg+=QString(", loglist.count: "); +// msg+=QString().setNum(LogList.count()); +// KMessageBox::information(0,msg,"aaa"); + + + for ( int index = startval;index <= startval+count;index++) + { + QString prefix=""; + QString postfix=""; + int type=KVpncConfig::info; + QString line = LogList[index]; + if (!line.isEmpty()) + { + if (parseLogType) + { + if (line.find(i18n("Info:"),0, FALSE) > -1 ) + { + type = KVpncConfig::info; + } + else if (line.find(i18n("Debug:"),0, FALSE) > -1 ) + { + type = KVpncConfig::debug; + } + // else + // if (line.find("remote",0, FALSE) > -1 ) + // { + // type = KVpncConfig::remote; + // } + else + if (line.find(i18n("Error:"),0, FALSE) > -1 ) + { + type = KVpncConfig::error; + } + // else + // if (line.find("success",0, FALSE) > -1 ) + // { + // type = KVpncConfig::success; + // } + + + prefix+="InfoLogColor.name(); + prefix+="\">"; + // prefix+=i18n("info")+": "; + break; + case KVpncConfig::remote: + prefix+=GlobalConfig->RemoteLogColor.name(); + prefix+="\">"; + // prefix+=i18n("remote")+": "; + break; + case KVpncConfig::error: + prefix+=GlobalConfig->ErrorLogColor.name(); + prefix+="\">"; + // prefix+=i18n("error")+": "; + break; + case KVpncConfig::success: + prefix+=GlobalConfig->SuccessLogColor.name(); + prefix+="\">"; + // prefix+=i18n("success")+": "; + break; + case KVpncConfig::debug: + prefix+=GlobalConfig->DebugLogColor.name(); + prefix+="\">"; + // prefix+=i18n("debug")+": "; + break; + } + + postfix+=""; + main->LogTextBrowser->append( QString().setNum(index)+" "+prefix+line+postfix) ; + } + else + { + main->LogTextBrowser->append( QString().setNum(index)+" "+line) ; + } + } + } +} + +void LogViewerDialog::find(QString what) +{ + bool casesense=false; + bool whooleword=false; + main->LogTextBrowser->find(what,casesense,whooleword); +} + +void LogViewerDialog::findLogEntryClicked() +{ + find(main->SearchLineEdit->text()); +} + diff --git a/src/logviewerdialog.h b/src/logviewerdialog.h new file mode 100644 index 0000000..3ca9389 --- /dev/null +++ b/src/logviewerdialog.h @@ -0,0 +1,59 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef LogViewerDialog_H +#define LogViewerDialog_H + +#include "logviewerdialogbase.h" +#include +#include +#include +#include +#include "kvpncconfig.h" +#include + +/** +@author Christoph Thielecke +*/ +class LogViewerDialog : public KDialogBase +{ + Q_OBJECT +public: + LogViewerDialog(QWidget *parent,QApplication *app, KVpncConfig *GlobalConfig, const QString& caption, int count); + + ~LogViewerDialog(); + void showLogPart(int start, int count,bool parseLogType=true); + +public slots: + void accept(); + void parseLog(); + void updateLineCountClicked(); + void findLogEntryClicked(); + void find(QString what); + +private: + LogViewerDialogBase *main; + KVpncConfig *GlobalConfig; + QApplication *app; + QValueVector LogList; + int linecount; + +}; + +#endif diff --git a/src/logviewerdialogbase.ui b/src/logviewerdialogbase.ui new file mode 100644 index 0000000..12f61cd --- /dev/null +++ b/src/logviewerdialogbase.ui @@ -0,0 +1,129 @@ + +LogViewerDialogBase + + + LogViewerDialogBase + + + + 0 + 0 + 700 + 586 + + + + + 700 + 500 + + + + Log + + + + unnamed + + + + layout48 + + + + unnamed + + + + LogTextBrowser + + + + 0 + 120 + + + + + + + + + layout47 + + + + unnamed + + + + textLabel1 + + + Line count from end: + + + + + LineCountIntSpinBox + + + 100000 + + + 5 + + + 5 + + + + + LineCountApplyPushButton + + + up&date + + + Alt+D + + + + + textLabel2 + + + | + + + + + SearchLineEdit + + + + + FindPushButton + + + &find + + + Alt+F + + + + + + + + + + + ktextbrowser.h + knuminput.h + kpushbutton.h + klineedit.h + kpushbutton.h + + diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..c599ea5 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,162 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ + +// KDE includes +#include +#include +#include +#include +#include + +#include +#include +#include + +// App includes +#include "kvpnc.h" +static const char *description = + I18N_NOOP ( "KDE frontend for various vpn clients\nCurrently supported protocols:\n* Cisco (vpnc (free), vpnclient (propritary))\n* IPSec (FreeS/WAN, Openswan, strongSwan, racoon)\n* PPTP\n* OpenVPN\n* L2TP (l2tpd, xl2tpd, openl2tp) over IPSec (racoon, FreeS/WAN, Openswan, strongSwan)\n* Vtun\n* SSH" ); +// QDate().fromString(, Qt::LocalDate ).toString( "yyyyMMdd" ) +QString date ( __DATE__ ); +QString day= date.section ( ' ',0,0 ); +QString month= QString().setNum ( QDate::fromString ( date.section ( ' ',0,0 ),Qt::ISODate ).month() ); +QString year= date.section ( ' ',2,2 ); + +QString currentdate ( "+SVN(" + date+" "+ QTime().fromString ( QString ( __TIME__ ) ).toString ( "hhmm" ) + ")" ); + + +#define __is_release__ + +QString versionstring1 = "0.9.6"; + +#ifdef __is_release__ +static const char *KVPNCVERSION = versionstring1.ascii(); +QString versionstring =QString ( KVPNCVERSION ); +#else +QString versionstring = versionstring1 + QString (" KDE3 ") + currentdate; +static const char *KVPNCVERSION = versionstring.ascii() ; +#endif + + +static KCmdLineOptions options[] = +{ + // INSERT YOUR COMMANDLINE OPTIONS HERE + { "openvpnimport ", I18N_NOOP ( "Import OpenVPN config file" ), 0 }, + { "ciscoimport ", I18N_NOOP ( "Import Cisco PCF file" ), 0 }, + { ":", I18N_NOOP ( "Extra options:" ), 0 }, + KCmdLineLastOption // End of options. +}; + +int main ( int argc, char *argv[] ) +{ + KAboutData aboutData ( "kvpnc", I18N_NOOP ( "KVpnc" ), + KVPNCVERSION, description, KAboutData::License_GPL_V2, + I18N_NOOP ( "(C) 2005, the KVpnc team" ), 0, + "http://home.gna.org/kvpnc/", "crissi99@gmx.de" ); + + aboutData.addAuthor ( "Christoph Thielecke", I18N_NOOP ( "Developer and maintainer" ), "crissi99@gmx.de", "http://crissi.linux-administrator.com/" ); + + aboutData.setVersion (versionstring.ascii()); + aboutData.setShortDescription (description ); + + aboutData.addCredit ( "KDE Team" , I18N_NOOP ( "KDE" ), "", "http://www.kde.org/" ); + aboutData.addCredit ( "KDevelop Team" , I18N_NOOP ( "KDevelop" ), "", "http://www.kdevelop.org/" ); + aboutData.addCredit ( "Maurice Massar" , I18N_NOOP ( "Vpnc" ), "vpnc@unix-ag.uni-kl.de", "http://www.unix-ag.uni-kl.de/~massar/vpnc/" ); + aboutData.addCredit ( "Witek Strzelczyk", I18N_NOOP ( "Polish translation" ), "witek_strzelczyk@go2.pl" ); + aboutData.addCredit ( "Tomas Olah" , I18N_NOOP ( "Slovak translation" ), "tomas.olah@alert.sk" ); + aboutData.addCredit ( "Lapo Luchini" , I18N_NOOP ( "Italian translation" ), "lapo@lapo.it" ); + aboutData.addCredit ( "Karoly Barcza", I18N_NOOP ( "Hungary translation" ), "kbarcza@blackpanther.hu" ); + aboutData.addCredit ( "Luk De Ketelaere" , I18N_NOOP ( "Dutch translation" ), "balboy@kvirc.net" ); + aboutData.addCredit ( "Jorgen Kessler" , I18N_NOOP ( "Dutch translation" ), "jkesseler@home.nl" ); + aboutData.addCredit ( "Atanas M." , I18N_NOOP ( "Bulgarian translation" ), "bugar@developer.bg" ); + aboutData.addCredit ( "Juanjo Avarez Martinez" , I18N_NOOP ( "Spanish translation" ), "juanjux@yahoo.es" ); + aboutData.addCredit ( "He Shi Jun" , I18N_NOOP ( "Chinese translation" ), "hax.sfo@gmail.com" ); + aboutData.addCredit ( "Marius Pacha" , I18N_NOOP ( "Chinese translation" ), "marius@matux.de" ); + aboutData.addCredit ( "Valeriy Girchenko" , I18N_NOOP ( "Russian translation" ), "valeragir@mail.ru" ); + aboutData.addCredit ( "Ahinu" , I18N_NOOP ( "French translation" ), "ahinu@wanadoo.fr" ); + aboutData.addCredit ( "Florian Fainelli" , I18N_NOOP ( "French translation" ), "florian@alphacore.net" ); + aboutData.addCredit ( "Damien Raude-Morvan" , I18N_NOOP ( "French translation" ), "drazib@drazzib.com" ); + aboutData.addCredit ( "Daniel Nylander" , I18N_NOOP ( "Swedish translation" ), "po@danielnylander.se" ); + aboutData.addCredit ( "Yukiko Bando" , I18N_NOOP ( "Japanese translation" ), "ybando@k6.dion.ne.jp" ); + aboutData.addCredit ( "Marc Serra Romero" , I18N_NOOP ( "Catalan translation" ), "mad93@majomo.com" ); + aboutData.addCredit ( "Buelent SENER" , I18N_NOOP ( "Turkish translation" ), "bsener@inonu.edu.tr" ); + aboutData.addCredit ( "Laurent Montel", I18N_NOOP ( "Patches" ), "montel@kde.org" ); + aboutData.addCredit ( "Peter Kussmann" , I18N_NOOP ( "PPTP-Test environment, OpenVPN testing, new ideas" ), "peter.kussmann@gmx.de" ); + aboutData.addCredit ( "Ansgar Jazdzewski" , I18N_NOOP ( "OpenVPN-Test environment, OpenVPN testing, new ideas" ), "ansgarj@gmx.de" ); + aboutData.addCredit ( "D. Klinkenberg" , I18N_NOOP ( "Testing PPTP, usebility hints & tests, bug hunting" ), "d.klinkenberg@gmx.net" ); + aboutData.addCredit ( "Lenon Kitchens" , I18N_NOOP ( "Testing OpenSWAN, bug hunting" ), "lenon@sanctuary.org" ); + aboutData.addCredit ( "Fathi Boudra" , I18N_NOOP ( "Testing OpenVPN, bug hunting" ), "fboudra@free.fr" ); + aboutData.addCredit ( "HAL9000" , I18N_NOOP ( "Cisco password decoder" ), "hal9000@evilscientists.de" ); + aboutData.addCredit ( "Marcin Prejsnar" , I18N_NOOP ( "Testing OpenVPN auth+cert, bug hunting" ), "alex@pronet.pl" ); + aboutData.addCredit ( "Elias Probst" , I18N_NOOP ( "Icon artwork, bug hunting" )," elias.probst@gmx.de" ); + aboutData.addCredit ( "Andreas Diestelmann" , I18N_NOOP ( "Support KVpnc development with 15EUR" ),"andreas@diestelmann.de" ); + aboutData.addCredit ( "Frank Visconti" , I18N_NOOP ( "Support KVpnc development with 30$" ),"frank3@viscontifamily.net" ); + aboutData.addCredit ( "Christoph Schmid" , I18N_NOOP ( "Support KVpnc development with 30EUR" ),"chris@schlagmichtod.de" ); + aboutData.addCredit ( "Attila Ruzsinszky" , I18N_NOOP ( "Cisco testbed, bug hunting" ), "ruzsinszky.attila@gmail.com" ); + aboutData.addCredit ( "Christiansen" , I18N_NOOP ( "Danish translation" ), "susebruger@mailme.dk" ); + + // Initialize command line args + KCmdLineArgs::init ( argc, argv, &aboutData); + + // Add options from other components + KApplication::addCmdLineOptions(); + KCmdLineArgs::addCmdLineOptions ( options ); + + KApplication a; + KVpnc *kvpnc = new KVpnc ( &a ); + + DCOPClient* dcop = a.dcopClient(); + dcop->attach(); + dcop->registerAs ( "kvpnc" ); + dcop->setNotifications ( true ); + + // Broken on request from Eric M. + if ( a.isSessionRestored() ) + { + kvpnc->restore(); + } + else + { +// if (getenv("USER") != "root") +// { +// KMessageBox::error( 0, I18N_NOOP( "Kvpnc must be started as root!" ) ); +// exit(0); +// } + + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + + a.setMainWidget ( kvpnc ); + + if ( args->isSet ( "openvpnimport" ) ) + { + QString openvpnimportfile = QString ( args->getOption ( "openvpnimport" ) ); + kvpnc->importOpenvpnProfileClicked ( openvpnimportfile ); + } + else if ( args->isSet ( "ciscoimport" ) ) + { + QString ciscoimportfile = QString ( args->getOption ( "ciscoimport" ) ); + kvpnc->importOpenvpnProfileClicked ( ciscoimportfile ); + } + + } + int ret = a.exec(); + return ret; +} + diff --git a/src/mainview.cpp b/src/mainview.cpp new file mode 100644 index 0000000..d78ae1b --- /dev/null +++ b/src/mainview.cpp @@ -0,0 +1,54 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "mainview.h" + + +MainView::MainView( QWidget* parent, const char* name, bool, WFlags fl ) : MainViewBase( parent, name, fl ) +{ + DebugOutput = new DebugOutputTextEdit(this, "DebugOutput"); + MainViewBaseLayout->addMultiCellWidget(DebugOutput,1,1,0,4); + DebugOutput->setReadOnly(true); + DebugOutput->setText( QString::null ); + QToolTip::add( DebugOutput, tr2i18n( "Debug console" ) ); + QWhatsThis::add( DebugOutput, tr2i18n( "The debug console shows useful debug information to solve problems. You need to turn on debug features for the program you want to produce output in preferences dialog." ) ); + +} + + +MainView::~MainView() {} + + + + diff --git a/src/mainview.h b/src/mainview.h new file mode 100644 index 0000000..a8655dd --- /dev/null +++ b/src/mainview.h @@ -0,0 +1,46 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __MAINVIEW_H__ +#define __MAINVIEW_H__ + +#include +#include +#include +#include +#include +#include "mainviewbase.h" +#include "kvpnckicker.h" +#include "debugoutputtextedit.h" + +// ID for statusbar +#define ID_STATUS_MSG 1 +#define ID_CONNECTION_MSG 2 + +class MainView : public MainViewBase { + +public: + MainView( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); + + ~MainView(); + DebugOutputTextEdit *DebugOutput; + +}; + +#endif diff --git a/src/mainviewbase.ui b/src/mainviewbase.ui new file mode 100644 index 0000000..8b56a0b --- /dev/null +++ b/src/mainviewbase.ui @@ -0,0 +1,141 @@ + +MainViewBase + + + MainViewBase + + + + 0 + 0 + 407 + 58 + + + + + 3 + 3 + 0 + 0 + + + + KVpnc + + + + unnamed + + + + layout4 + + + + unnamed + + + + textLabel1 + + + <font size="+1"><b>Profile:</b></font> + + + + + SessionCombo + + + + 3 + 0 + 0 + 0 + + + + Name of the current profile + + + Here you can select the profile to use for connection. + + + + + buttonConnect + + + Connec&t + + + Alt+T + + + true + + + true + + + Click to establish connection for selected profile + + + Connect button + + + + + buttonDisconnect + + + &Disconnect + + + Alt+D + + + true + + + Click for disconnect the current connection + + + Disconnect button + + + + + + + spacer1 + + + Vertical + + + Expanding + + + + 20 + 31 + + + + + + + SessionCombo + buttonConnect + buttonDisconnect + + + advancedClicked() + + + + kcombobox.h + + diff --git a/src/manageciscocert.cpp b/src/manageciscocert.cpp new file mode 100644 index 0000000..611d185 --- /dev/null +++ b/src/manageciscocert.cpp @@ -0,0 +1,384 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "manageciscocert.h" +#include "utils.h" +#include "importcertificatedialog.h" +#include "displaycertdialog.h" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + + +#include + +ManageCiscoCert::ManageCiscoCert(QWidget *parent, const char* caption, KVpncConfig *GlobalConfig) : KDialogBase (parent, i18n ( "Manage Cisco certificates..." ).ascii(), true, caption, KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, true) +{ + main = new ManageCiscoCertBase ( this ); + setMainWidget ( main ); + main->sizeHint(); +// main->show(); +// main->setMinimumSize ( main->sizeHint() ); + sizeHint(); + + this->GlobalConfig = GlobalConfig; + connect (main->ImportCertFilePushButton,SIGNAL(clicked()),this,SLOT(importCertClicked())); + connect (main->DeleteCertPushButton,SIGNAL(clicked()),this,SLOT(deleteCertClicked())); + connect (main->CertListView,SIGNAL(contextMenuRequested ( QListViewItem *, const QPoint &, int )),this,SLOT(contextMenuRequested ( QListViewItem *, const QPoint &, int ))); + checkList(); +} + + +ManageCiscoCert::~ManageCiscoCert() +{ +} + +void ManageCiscoCert::deleteCertClicked() +{ + if ( main->CertListView->childCount() > 0 && main->CertListView->currentItem()!= 0 ) + { + QListViewItem *item = main->CertListView->currentItem(); + + int result = KMessageBox::questionYesNo ( this, i18n( "Do you really want to delete the cert \"%1\" (type: %2) from cert store?" ).arg(item->text(1).arg(item->text(2))), i18n( "Delete certificate?" ) ); + +// if ( GlobalConfig->KvpncDebugLevel > 2 ) +// GlobalConfig->appendLogEntry( "Result: "+ QString().setNum(result), GlobalConfig->debug ) ; + if ( result == 3) // Yes + { + + + DeleteProcess = new QProcess(0); + DeleteProcess->addArgument ( GlobalConfig->pathToCiscoCertMgr ); + + if (item->text(2) == i18n("User")) + DeleteProcess->addArgument ( "-U" ); + if (item->text(2) == i18n("CA")) + DeleteProcess->addArgument ( "-R" ); + DeleteProcess->addArgument ( "-op" ); + DeleteProcess->addArgument ( "delete" ); + DeleteProcess->addArgument ( "-ct" ); + DeleteProcess->addArgument ( item->text(0) ); + + connect ( DeleteProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_remove() ) ); + connect ( DeleteProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_remove() ) ); + connect ( DeleteProcess, SIGNAL ( processExited()) , this, SLOT(deleteProcessFinished())); + + QStringList *env = new QStringList(); + *env << "LC_ALL=C" << "LANG=C" << "PATH=/bin:/usr/bin:/usr/sbin:/sbin"; + + if ( !DeleteProcess->start ( env ) ) + { + + KMessageBox::sorry ( this, i18n ( "Unable to start process (%1)!" ).arg ( "cisco_cert_mgr" ) ); +// GlobalConfig->appPointer->restoreOverrideCursor(); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Process (%1) started." ).arg ("cisco_cert_mgr" ),GlobalConfig->debug ); + + QCString password; + int result = KPasswordDialog::getPassword(password, i18n("Certificate password")); + + if (result == KPasswordDialog::Accepted) + { + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Certicate password got from user, send it..." ),GlobalConfig->debug ); + + DeleteProcess->writeToStdin( QString(password)+"\n"); + while (DeleteProcess->isRunning()) + { + sleep(1); + } + + checkList(); + disconnect ( DeleteProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_remove() ) ); + disconnect ( DeleteProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_remove() ) ); + disconnect ( DeleteProcess, SIGNAL ( processExited()) , this, SLOT(deleteProcessFinished())); + delete DeleteProcess; + DeleteProcess=0L; + } + else + { + + // nothing + } + + } + } + + } +} + +void ManageCiscoCert::importCertClicked() +{ + ImportCertificateDialog dlg ( this, i18n ( "Import Certificate..." ).ascii(), GlobalConfig ); + dlg.main->ImporttypeComboBox->setCurrentItem ( ImportCertificateDialog::cisco ); + dlg.typeToggeled ( VpnAccountData::ciscoorig); + dlg.main->ImporttypeComboBox->setEnabled ( false ); + dlg.main->P12GroupBox->setTitle ( i18n ( "Import" ) ); + dlg.main->CertPathTextLabel->hide(); + dlg.main->RacoonCertificatePathUrlrequester->hide(); + dlg.main->PrivateKeyPassGroupBox->setTitle ( i18n ( "Certificate protection" ) ); + dlg.main->PrivateKeyPassTextLabel->setText(i18n ("Certificate password:")); + dlg.main->PrivateKeyPassAgainTextLabel->setText(i18n ("Certificate password again:")); + dlg.main->FilenameUrlrequester->setFilter ( "*" ); + //int result = + dlg.exec(); + + checkList(); +} + +void ManageCiscoCert::showCertClicked() +{ + if ( main->CertListView->childCount() > 0 && main->CertListView->currentItem()!= 0 ) + { + QListViewItem *item = main->CertListView->currentItem(); + CertDataName=item->text(1); + CertStartFound=false; + + ShowProcess = new QProcess(0); + ShowProcess->addArgument ( GlobalConfig->pathToCiscoCertMgr ); + + if (item->text(2) == i18n("User")) + { + ShowProcess->addArgument ( "-U" ); + CertType=i18n("User certificate"); + } + if (item->text(2) == i18n("CA")) + { + ShowProcess->addArgument ( "-R" ); + CertType=i18n("CA certificate"); + } + ShowProcess->addArgument ( "-op" ); + ShowProcess->addArgument ( "view" ); + ShowProcess->addArgument ( "-ct" ); + ShowProcess->addArgument ( item->text(0) ); + + connect ( ShowProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_display() ) ); + connect ( ShowProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_display() ) ); + connect ( ShowProcess, SIGNAL ( processExited()) , this, SLOT(showProcessFinished())); + + QStringList *env = new QStringList(); + *env << "LC_ALL=C" << "LANG=C" << "PATH=/bin:/usr/bin:/usr/sbin:/sbin"; + + GlobalConfig->appPointer->setOverrideCursor( QCursor(Qt::WaitCursor) ); + if (GlobalConfig->KvpncDebugLevel > 2) + GlobalConfig->appendLogEntry(i18n("Getting cert info from Cisco certificate store..."), GlobalConfig->debug); + if ( !ShowProcess->start ( env ) ) + { + KMessageBox::sorry ( this, i18n ( "Unable to start process (%1)!" ).arg ( "cisco_cert_mgr" ) ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n ( "Process (%1) started." ).arg ("cisco_cert_mgr" ),GlobalConfig->debug ); + while (ShowProcess->isRunning()) + { + usleep(200); + GlobalConfig->appPointer->processEvents(); + } + } + disconnect ( ShowProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readFromStdout_display() ) ); + disconnect ( ShowProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readFromStderr_display() ) ); + disconnect ( ShowProcess, SIGNAL ( processExited()) , this, SLOT(showProcessFinished())); + + } +} + +void ManageCiscoCert::deleteProcessFinished() +{ +// delete DeleteProcess; + checkList(); +} + +void ManageCiscoCert::showProcessFinished() +{ + GlobalConfig->appPointer->restoreOverrideCursor(); + if (GlobalConfig->KvpncDebugLevel > 2) + GlobalConfig->appendLogEntry(i18n("Done."), GlobalConfig->debug); + + GlobalConfig->slotStatusMsg(i18n("Done."), ID_FLASH_MSG); + GlobalConfig->slotStatusMsg(i18n("Ready."), ID_STATUS_MSG); + + delete ShowProcess; + ShowProcess=0L; + std::cout << "certdatalist" << CertDataList.join (" ") << std::endl; + DisplayCertDialog dlg(0,i18n("Certificate data"),GlobalConfig); + dlg.main->CertNameTextLabel->setText(CertDataName); + dlg.main->CertTypeTextLabel->setText(CertType); + dlg.CertDataList = CertDataList; + dlg.parseCertData(); + dlg.exec(); + CertDataName=""; + CertDataList.clear(); + +} + +void ManageCiscoCert::checkList() +{ + main->CertListView->clear(); + + GlobalConfig->appPointer->setOverrideCursor( QCursor(Qt::WaitCursor) ); + + GlobalConfig->slotStatusMsg(i18n("Collecting cisco certs from Cisco certificate store..."), ID_STATUS_MSG); + if (GlobalConfig->KvpncDebugLevel > 2) + GlobalConfig->appendLogEntry(i18n("Looking for certs in Cisco certificate store..."), GlobalConfig->debug); + + QStringList CiscoCerts = Utils(GlobalConfig).getCertsFromCiscoCertStore("user"); + if (GlobalConfig->KvpncDebugLevel > 2) + GlobalConfig->appendLogEntry(i18n("Done."), GlobalConfig->debug); + + GlobalConfig->slotStatusMsg(i18n("Collecting cisco CA certs from Cisco certificate store..."), ID_STATUS_MSG); + if (GlobalConfig->KvpncDebugLevel > 2) + GlobalConfig->appendLogEntry(i18n("Looking for CA certs in Cisco certificate store..."), GlobalConfig->debug); + QStringList CiscoCaCerts = Utils(GlobalConfig).getCertsFromCiscoCertStore("ca"); + if (GlobalConfig->KvpncDebugLevel > 2) + GlobalConfig->appendLogEntry(i18n("Done."), GlobalConfig->debug); + + GlobalConfig->slotStatusMsg(i18n("Done."), ID_FLASH_MSG); + GlobalConfig->slotStatusMsg(i18n("Ready."), ID_STATUS_MSG); + + main->CertListView->takeItem(main->CertListView->currentItem()); + int current_user_idx=0; + int current_ca_idx=0; + for ( QStringList::Iterator it = CiscoCerts.begin(); it != CiscoCerts.end(); ++it ) + { + if (GlobalConfig->KvpncDebugLevel > 2) + std::cout << "insert item (cisco certs): " << QString(*it) << std::endl; + main->CertListView->insertItem( new QListViewItem(main->CertListView, QString().setNum(current_user_idx),QString(*it),i18n("User"))); + current_user_idx++; + } + for ( QStringList::Iterator it = CiscoCaCerts.begin(); it != CiscoCaCerts.end(); ++it ) + { + if (GlobalConfig->KvpncDebugLevel > 2) + std::cout << "insert item (cisco certs): " << QString(*it) << std::endl; + main->CertListView->insertItem( new QListViewItem(main->CertListView, QString().setNum(current_ca_idx),QString(*it),i18n("CA"))); + current_ca_idx++; + } + + + if (main->CertListView->childCount() > 0 && main->CertListView->currentItem()!= 0 ) + { + main->DeleteCertPushButton->setEnabled(true); + } + else + { + main->DeleteCertPushButton->setEnabled(false); + } + GlobalConfig->appPointer->restoreOverrideCursor(); +} + +void ManageCiscoCert::readFromStdout_remove() +{ + while ( DeleteProcess->canReadLineStdout() ) + { + QString line = QString ( DeleteProcess->readLineStdout() ); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( "[cisco_cert_mgr]: "+line,GlobalConfig->debug ); + } +} + +void ManageCiscoCert::readFromStderr_remove() +{ + while ( DeleteProcess->canReadLineStderr() ) + { + QString line = QString ( DeleteProcess->readLineStderr() ); + GlobalConfig->appendLogEntry ( "[cisco_cert_mgr err]: "+line ,GlobalConfig->error ); + } + checkList(); + +} + +void ManageCiscoCert::readFromStdout_display() +{ + while ( ShowProcess->canReadLineStdout() ) + { + QString line = QString ( ShowProcess->readLineStdout() ); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( "[cisco_cert_mgr]: "+line,GlobalConfig->debug ); + + if (CertStartFound) + CertDataList.append(line); + else + { + if ( line.find ( "Common Name:" , 0, FALSE ) > -1) + { + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry ( i18n("Cert start found."),GlobalConfig->debug ); + + + CertStartFound=true; + CertDataList.append(line); + } + } + } +} + +void ManageCiscoCert::readFromStderr_display() +{ + while ( ShowProcess->canReadLineStderr() ) + { + QString line = QString ( ShowProcess->readLineStderr() ); + GlobalConfig->appendLogEntry ( "[cisco_cert_mgr err]: "+line ,GlobalConfig->error ); + } + +} + +void ManageCiscoCert::contextMenuRequested ( QListViewItem * item, const QPoint &pos, int ) +{ + ContextMenu = new QPopupMenu ( 0 ); + if (item != 0) + { + ContextMenu->insertItem(i18n("&Show...")); + ContextMenu->insertSeparator(); + ContextMenu->insertItem(i18n("&Delete...")); + } + ContextMenu->insertItem(i18n("&Add...")); + connect ( ContextMenu, SIGNAL ( activated ( int ) ), this, SLOT ( doContextMenuAction ( int ) ) ); + ContextMenu->show(); + ContextMenu->setGeometry(pos.x(),pos.y(), ContextMenu->width(),ContextMenu->height()); +} + +void ManageCiscoCert::doContextMenuAction ( int action) +{ + QString itemtext = ContextMenu->text ( action ); +// std::cout << "action: " << itemtext << std::endl; + if (itemtext == i18n("&Delete...")) + deleteCertClicked(); + if (itemtext == i18n("&Add...")) + importCertClicked(); + if (itemtext == i18n("&Show...")) + showCertClicked(); +} + diff --git a/src/manageciscocert.h b/src/manageciscocert.h new file mode 100644 index 0000000..ce499ad --- /dev/null +++ b/src/manageciscocert.h @@ -0,0 +1,73 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef MANAGECISCOCERT_H +#define MANAGECISCOCERT_H + +#include +#include + +#include +#include +#include + +#include "kvpncconfig.h" + +/** + @author Christoph Thielecke +*/ +class ManageCiscoCert : public KDialogBase +{ + Q_OBJECT + public: + ManageCiscoCert(QWidget *parent, const char* caption, KVpncConfig *GlobalConfig); + + ~ManageCiscoCert(); + + + private: + KVpncConfig *GlobalConfig; + QProcess *DeleteProcess; + QProcess *ShowProcess; + QPopupMenu *ContextMenu; + QStringList CertDataList; + QString CertDataName; + QString CertType; + bool CertStartFound; + + private slots: + void deleteCertClicked(); + void importCertClicked(); + void showCertClicked(); + void deleteProcessFinished(); + void showProcessFinished(); + void checkList(); + void readFromStdout_remove(); + void readFromStderr_remove(); + void readFromStdout_display(); + void readFromStderr_display(); + void contextMenuRequested ( QListViewItem * item, const QPoint &pos, int ); + void doContextMenuAction ( int action); + + public: + ManageCiscoCertBase *main; + +}; + +#endif diff --git a/src/manageciscocertbase.ui b/src/manageciscocertbase.ui new file mode 100644 index 0000000..1f0472f --- /dev/null +++ b/src/manageciscocertbase.ui @@ -0,0 +1,204 @@ + +ManageCiscoCertBase + + + ManageCiscoCertBase + + + + 0 + 0 + 466 + 336 + + + + Manage Cisco certificates... + + + + unnamed + + + + layout69 + + + + unnamed + + + + layout68 + + + + unnamed + + + + layout67 + + + + unnamed + + + + textLabel1 + + + <b>Certificates in the Cisco cert store:</b> + + + + + + # + + + true + + + true + + + + + Name + + + true + + + true + + + + + Type + + + true + + + true + + + + CertListView + + + AutoOneFit + + + + + layout66 + + + + unnamed + + + + DeleteCertPushButton + + + false + + + &Delete cert from cert store + + + Alt+D + + + + + spacer42 + + + Horizontal + + + Expanding + + + + 230 + 21 + + + + + + + + layout65 + + + + unnamed + + + + ImportCertFilePushButton + + + &Import certificate from file... + + + Alt+I + + + + + spacer50 + + + Horizontal + + + Expanding + + + + 221 + 20 + + + + + + + + + + + + spacer51 + + + Vertical + + + Expanding + + + + 21 + 41 + + + + + + + + + + kpushbutton.h + kpushbutton.h + + diff --git a/src/networkinterface.cpp b/src/networkinterface.cpp new file mode 100644 index 0000000..e757339 --- /dev/null +++ b/src/networkinterface.cpp @@ -0,0 +1,563 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +//BEGIN INCLUDES +#include "networkinterface.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//END INCLUDES + +NetworkInterface::NetworkInterface( KVpncConfig* GlobalConfig,QApplication *app, QObject *parent, const char *name ) : QObject( parent, name ) +{ + + this->app = app; + interfaceTest = false; + retrieveInterfaceAddress = false; + QPtrList*InterfaceList = new QPtrList(); + InterfaceList->setAutoDelete( TRUE ); // the list owns the objects + QString InterfaceIP = ""; + QString InterfaceAddress = ""; + IPforInterface = ""; + tmpInterface = ""; + interfaceExists = false; + defaultinterface="default"; + readOutput=false; + env = new QStringList(); + *env << "LC_ALL=C" << "LANG=C" << "PATH=/bin:/usr/bin:/usr/sbin:/sbin"; + this->GlobalConfig = GlobalConfig; +} + +NetworkInterface::~NetworkInterface() +{ + //delete proc; + if (defaultinterface == "default") + defaultinterface == ""; +} + +bool NetworkInterface::interfaceExist( QString Interface ) +{ + if ( !Interface.isEmpty() ) + { + QFile NetdevFile( "/proc/net/dev" ); + QTextStream stream ( &NetdevFile ); + if ( NetdevFile.open ( IO_ReadOnly ) ) + { + QString line = ""; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' and replace all white chars with one blank + if ( line.find ( ':' ) > -1 ) + { + QString tmpdev = line.section( ':', 0, 0 ).stripWhiteSpace(); + if ( tmpdev == Interface ) + { + NetdevFile.close(); + return true; + } + } + } + } + NetdevFile.close(); + } + return false; +} + +QStringList NetworkInterface::getAllNetworkInterfaces() +{ + QFile NetdevFile( "/proc/net/dev" ); + QTextStream stream ( &NetdevFile ); + if ( NetdevFile.open ( IO_ReadOnly ) ) + { + QString line = ""; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' and replace all white chars with one blank + if ( line.find ( ':' ) > -1 ) + { + InterfaceList.append( line.section( ':', 0, 0 ).stripWhiteSpace()); + } + } + } + NetdevFile.close(); + InterfaceList.sort(); + return InterfaceList; +} + +QString NetworkInterface::getInterfaceIP( QString Interface ) +{ + +//FIXME why this dont work on ppp0 device of l2tp tunnel? +// if ( !Interface.isEmpty() ) +// { +// int fd=-1; +// QString tmpip=""; +// struct ifreq ifr; +// fd = socket(AF_INET, SOCK_STREAM, 0); +// if (fd >= 0){ +// strcpy(ifr.ifr_name, Interface.ascii()); +// ifr.ifr_addr.sa_family = AF_INET; +// if (ioctl(fd, SIOCGIFADDR, &ifr) == 0){ +// tmpip = inet_ntoa(((struct sockaddr_in *) &ifr. ifr_addr)->sin_addr); +// return tmpip; +// } +// else +// return QString(""); +// } +// else +// return QString(""); +// } +// else +// return QString(""); + return getInterfaceIP2(Interface); +} + +QString NetworkInterface::getInterfaceIP2( QString Interface ) +{ + if ( !Interface.isEmpty() ) + { + + InterfaceIpProc = new QProcess(this); + InterfaceIpProc->addArgument( GlobalConfig->pathToIp ); + InterfaceIpProc->addArgument("addr"); + InterfaceIpProc->addArgument("show"); + InterfaceIpProc->addArgument(Interface); + + retrieveInterfaceIP=true; + readOutput=true; + + connect( InterfaceIpProc, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdout_interfaceip() ) ); + connect( InterfaceIpProc, SIGNAL( readyReadStderr() ), this, SLOT( readFromStderr_interfaceip() ) ); + connect( InterfaceIpProc, SIGNAL( processExited () ), this, SLOT( processHasFinished() ) ); + + if ( !InterfaceIpProc->start(env) ) + { + GlobalConfig->appendLogEntry(i18n("unable to start proc (%1)!").arg(i18n("getting IP address from interface")), KVpncConfig::error); + } + else + { + while ( retrieveInterfaceIP && InterfaceIpProc->isRunning() ) + { + if (GlobalConfig->appPointer->hasPendingEvents()) + GlobalConfig->appPointer->processEvents(); + usleep(500); + } + /* + while ( readOutput) + GlobalConfig->appPointer->processEvents();*/ + } + disconnect( InterfaceIpProc, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdout_interfaceip() ) ); + disconnect( InterfaceIpProc, SIGNAL( readyReadStderr() ), this, SLOT( readFromStderr_interfaceip() ) ); + disconnect( InterfaceIpProc, SIGNAL( processExited () ), this, SLOT( processHasFinished() ) ); + delete InterfaceIpProc; + InterfaceIpProc=0L; + } + return InterfaceIP; + +} + +QString NetworkInterface::getInterfaceAddress( QString IPforInterface ) +{ + /* + // TODO fixme + if ( !IPforInterface.isEmpty() ) + { + this->IPforInterface = IPforInterface; + QStringList devlist = getAllNetworkInterfaces(); + tmpfile = new KTempFile(); + QString tmpPath = locateLocal ( "data", "kvpnc/" ); + QString GetIpForInterfaceScript = tmpPath + "get_interface_for_ip_"+IPforInterface+".sh"; + + QFile file ( GetIpForInterfaceScript ); + QTextStream stream( &file ); + if ( file.open( IO_WriteOnly ) ) + { + stream << "# generated by kvpnc. Do not edit it." << "\n"; + stream << "\n"; + stream << GlobalConfig->pathToIfconfig +" | grep -B1 "+IPforInterface+" | head -n1 |awk {'print $1'} > "+ tmpfile->name()+"\n"; + file.close(); + + + + InterfaceAddressProc = new QProcess(this); + InterfaceAddressProc->addArgument( GlobalConfig->InterpreterShell ); + InterfaceAddressProc->addArgument(GetIpForInterfaceScript); + retrieveInterfaceAddress=true; + readOutput=true; + + //connect( InterfaceAddressProc, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdout_interfaceaddress() ) ); + // connect( InterfaceAddressProc, SIGNAL( readyReadStderr() ), this, SLOT( readFromStderr_interfaceaddress() ) ); + connect( InterfaceAddressProc, SIGNAL( processExited () ), this, SLOT( processHasFinished() ) ); + + + if ( !InterfaceAddressProc->start(env) ) + { + GlobalConfig->appendLogEntry(i18n("unable to start proc (%1)!").arg(i18n("script for get interface from IP address")), KVpncConfig::error); + } + + else + { + while ( InterfaceAddressProc->isRunning() ) + { + usleep(250); +// GlobalConfig->appPointer->processEvents(); + } + + while ( readOutput && retrieveInterfaceAddress == true ) + { + usleep(250); +// GlobalConfig->appPointer->processEvents(); + } + + // disconnect( InterfaceAddressProc, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdout_interfaceaddress() ) ); + // disconnect( InterfaceAddressProc, SIGNAL( readyReadStderr() ), this, SLOT( readFromStderr_interfaceaddress() ) ); + disconnect( InterfaceAddressProc, SIGNAL( processExited () ), this, SLOT( processHasFinished() ) ); + //delete InterfaceAddressProc; + } + } + } +*/ + if ( !IPforInterface.isEmpty() ) + { + this->IPforInterface = IPforInterface; + QStringList devlist = getAllNetworkInterfaces(); + if (!devlist.isEmpty()) + { + for ( QStringList::Iterator it = devlist.begin(); it != devlist.end(); ++it ) { + if (getInterfaceIP(*it) == IPforInterface) + return QString(*it); + } + } + else + return ""; + } + + return InterfaceAddress; + +} + +QString NetworkInterface::getNetmaskOfInterface(QString interface) +{ + QFile NetRouteFile ( "/proc/net/route" ); + QTextStream stream ( &NetRouteFile ); + QString tmpmask; + if ( NetRouteFile .open ( IO_ReadOnly ) ) + { + QString line = ""; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' and replace all white chars with one blank + + // FIXME netmask is guess to be ok if not 0.0.0.0 or 255.255.255.255 + if ( line.simplifyWhiteSpace().section( ' ', 1, 1 ) != "00000000" && line.simplifyWhiteSpace().section( ' ', 7, 7 ) != "FFFFFFFF" && line.simplifyWhiteSpace().section( ' ', 0, 0 ) == interface) + { + struct sockaddr_in name; + bool ok=true; + std::cout << "netmask of interface "<< interface.ascii() << ": " << line.simplifyWhiteSpace().section( ' ', 7, 7 ).ascii() << "\n"; + name.sin_addr.s_addr = line.simplifyWhiteSpace().section( ' ', 7, 7 ).toUInt(&ok,16); + tmpmask = inet_ntoa(name.sin_addr); // return the value of the netmask + NetRouteFile .close(); + return tmpmask; + } + } + } + NetRouteFile .close(); + + return "0.0.0.0"; +} + +QString NetworkInterface::getDefaultInterface() +{ + QFile NetRouteFile ( "/proc/net/route" ); + QTextStream stream ( &NetRouteFile ); + QString tmpdev; + if ( NetRouteFile .open ( IO_ReadOnly ) ) + { + QString line = ""; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' and replace all white chars with one blank + QString tmptarget = line.simplifyWhiteSpace().section( ' ', 1, 1 ); // return the value of the target which is 0.0.0.0 + if ( tmptarget == "00000000" ) + { + tmpdev = line.simplifyWhiteSpace().section( ' ', 0, 0 ); // return the value of the target which is 0.0.0.0 + NetRouteFile.close(); + return tmpdev; + } + } + } + NetRouteFile.close(); + + return ""; +} + +int NetworkInterface::getDefaultRouteCount() +{ + QFile NetRouteFile ( "/proc/net/route" ); + QTextStream stream ( &NetRouteFile ); + int defaultroutecount=0; + if ( NetRouteFile .open ( IO_ReadOnly ) ) + { + QString line = ""; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' and replace all white chars with one blank + QString tmptarget = line.simplifyWhiteSpace().section( ' ', 1, 1 ); // return the value of the target which is 0.0.0.0 + if ( tmptarget == "00000000" ) + defaultroutecount++; + } + NetRouteFile.close(); + } + + return defaultroutecount; +} + +QString NetworkInterface::getGatewayOfInterface(QString interface) +{ + QFile NetRouteFile ( "/proc/net/route" ); + QTextStream stream ( &NetRouteFile ); + QString tmpgw; + if ( NetRouteFile .open ( IO_ReadOnly ) ) + { + QString line = ""; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' and replace all white chars with one blank + if (line.simplifyWhiteSpace().section( ' ', 0, 0 ) == interface && line.simplifyWhiteSpace().section( ' ', 1, 1 ) != "00000000") + { + struct sockaddr_in name; + bool ok=true; +// std::cout << "gateway of interface "<< interface.ascii() << ": " << line.simplifyWhiteSpace().section( ' ', 2, 2 ).ascii() << "\n"; + name.sin_addr.s_addr = line.simplifyWhiteSpace().section( ' ', 2, 2 ).toUInt(&ok,16); + tmpgw = inet_ntoa(name.sin_addr); // return the value of the gateway + NetRouteFile .close(); + return tmpgw; + } + } + } + NetRouteFile .close(); + + return "0.0.0.0"; +} + +QString NetworkInterface::getGatewayOfDefaultInterface() +{ + QFile NetRouteFile ( "/proc/net/route" ); + QTextStream stream ( &NetRouteFile ); + QString tmpgw; + if ( NetRouteFile .open ( IO_ReadOnly ) ) + { + QString line = ""; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' and replace all white chars with one blank + std::cout << "line: \"" << line << "\"" << "\n"; + if (line.simplifyWhiteSpace().section( ' ', 1, 1 ) == "00000000" ) + { + struct sockaddr_in name; + bool ok=true; +// std::cout << "gateway of default interface " << ": " << line.simplifyWhiteSpace().section( ' ', 2, 2 ).ascii() << "\n"; + name.sin_addr.s_addr = line.simplifyWhiteSpace().section( ' ', 2, 2 ).toUInt(&ok,16); +// std::cout << "s_addr: " << QString().setNum(line.simplifyWhiteSpace().section( ' ', 2, 2 ).stripWhiteSpace().toUInt(&ok,16)) << std::endl; + tmpgw = inet_ntoa(name.sin_addr); // return the value of the gateway + NetRouteFile .close(); +// std::cout << "gateway of default interface (ascii)" << ": " << tmpgw<< "\n"; + return tmpgw; + } + } + NetRouteFile .close(); + } + else + { + std::cerr << "/proc/net/route cant be opened" << std::endl; + } + + return ""; +} + +QString NetworkInterface::getExternalIpAddress() +{ + qInitNetworkProtocols(); + ExternalIpAddress=""; + getExternalIpAddressRunning=true; + http = new QHttp(); + connect (http,SIGNAL(readyRead(const QHttpResponseHeader &)), this, SLOT(externalIpDataRecieved(const QHttpResponseHeader &))); + + // FIXME how it could be better? + http->setHost( "checkip.dyndns.org" ); + + http->get + ( "/" ); + while ( getExternalIpAddressRunning ) + { + usleep(250); +// GlobalConfig->appPointer->processEvents(); + } + delete http; + return ExternalIpAddress; +} + +bool NetworkInterface::inSameNetwork(QString ip1,QString Netmask1,QString ip2,QString Netmask2) +{ + // FIXME add valid ipv4 ip check + // FIXME add netmask check (subnetworks!) + if (ip1==ip2) + { + std::cout << "ip1 == ip2" << std::endl; + return true; + } + else + { + std::cout << "ip1: " << ip1.section( '.', 0, 2 ) << " , ip2: " << ip2.section( '.', 0, 2 ) << std::endl; + if (ip1.section( '.', 0, 2 ) == ip2.section( '.', 0, 2 )) + { + if (Netmask1 == Netmask2) + { + std::cout << "interface1 == interface2 and netmask1 == netmask2" << std::endl; + return true; + } + else + return false; + } + else + return false; + + } +} + +void NetworkInterface::readFromStdout() +{ + while ( proc->canReadLineStdout() ) + { + QString line = proc->readLineStdout() ; + // QString line = QString(proc->readStdout()); + + + /* + example for one interface + + eth0 Protokoll:Ethernet Hardware Adresse 00:10:4B:B2:19:00 + inet Adresse:192.168.0.99 Bcast:192.168.0.255 Maske:255.255.255.0 + inet6 Adresse: fe80::210:4bff:feb2:1900/64 Gltigkeitsbereich:Verbindung + UP BROADCAST NOTRAILERS RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:31549 errors:0 dropped:0 overruns:0 frame:0 + TX packets:34046 errors:0 dropped:0 overruns:0 carrier:0 + Kollisionen:0 Sendewarteschlangenlï¿œge:1000 + RX bytes:11308743 (10.7 Mb) TX bytes:3701511 (3.5 Mb) + Interrupt:10 Basisadresse:0xdc00 + */ + + if ( interfaceTest ) + { + if ( line.find( "proto", 0 , FALSE ) != -1 ) + { + interfaceExists = true; + interfaceTest = false; + } + } + + + } +} + +void NetworkInterface::readFromStderr() +{ + //while ( proc->canReadLineStderr() ) { + // QString line = proc->readLineStderr() ; + QString line = QString( proc->readStderr() ); + + if ( interfaceTest ) + { + interfaceExists = false; + interfaceTest = false; + } + //std::cerr << "dbg err: " << line << std::endl; + //} +} + +void NetworkInterface::processHasFinished() +{ + +// std::cout << "dbg: processHasFinished():" << std::endl;// << proc->exitStatus() << std::endl;; + + if (retrieveInterfaceAddress ) + { +// std::cout << "tmp file: " << tmpfile->name() << std::endl; + InterfaceAddress = QString(tmpfile->file()->readAll()).stripWhiteSpace(); +// KMessageBox::information( 0,this->defaultinterface,"default if"); + // tmpfile->unlink(); + retrieveInterfaceAddress=false; + } + + if (retrieveInterfaceIP) + retrieveInterfaceIP=false; + + readOutput=false; +} + +void NetworkInterface::externalIpDataRecieved(const QHttpResponseHeader &) +{ + ExternalIpAddress=QString(http->readAll()).stripWhiteSpace().remove ("Current IP Address: ").stripWhiteSpace(); + getExternalIpAddressRunning=false; +} + +void NetworkInterface::readFromStdout_interfaceip() +{ + while ( InterfaceIpProc && InterfaceIpProc->canReadLineStdout() ) + { + QString line = InterfaceIpProc->readLineStdout() ; + // QString line = QString(InterfaceIpProc->readStdout()); + + if (line.find( "inet ", 0 , FALSE ) != -1 ) + { + + InterfaceIP = line.simplifyWhiteSpace().section(' ', 1,1).section('/',0,0); // inet 192.168.10.100/24 brd 192.168.10.255 scope global + retrieveInterfaceIP=false; + // it could more than one ip addresses on a interface. we only need the first. + break; + } + } +} + +void NetworkInterface::readFromStderr_interfaceip() +{ + while ( InterfaceIpProc && InterfaceIpProc->canReadLineStderr() ) + { + QString line = InterfaceIpProc->readLineStderr() ; + // QString line = QString( InterfaceIpProc->readStderr() ); + + if ( interfaceTest ) + { + interfaceExists = false; + interfaceTest = false; + } + //std::cerr << "dbg err: " << line << std::endl; + } +} diff --git a/src/networkinterface.h b/src/networkinterface.h new file mode 100644 index 0000000..99e71b9 --- /dev/null +++ b/src/networkinterface.h @@ -0,0 +1,157 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef NETWORKINTERFACE_H +#define NETWORKINTERFACE_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include "kvpncconfig.h" + +/** +Class for interaction with network interface + +@author Christoph Thielecke +*/ +class NetworkInterface : public QObject +{ + Q_OBJECT + +public: + /** + * Konstruktor + * @param parent Pointer to parent widget + * @param name Name of the object + * @return nothing + */ + NetworkInterface( KVpncConfig* config,QApplication *app, QObject *parent = 0, const char *name = 0 ); + + /** + * Destruktor + * @return nothing + */ + ~NetworkInterface(); + + /** + * Tests if the interface exists + * @param Interface The interface to test + * @return True if interface exist + */ + bool interfaceExist(QString Interface); + + /** + * Retrieves a list of all availiable interfaces + * @return List with all interfaces + */ + QStringList getAllNetworkInterfaces(); + + /** + * Gets the IP from a given interface + * @param Interface The interface from which the IP whould be given + * @return The IP + */ + QString getInterfaceIP(QString Interface); + + QString getInterfaceIP2(QString Interface); // old style + /** + * Gets the device from a given IP + * @param IP The IP which the target interface has + * @return The interface where the IP is set + */ + QString getInterfaceAddress(QString IP); + + /** + * Gets the interface where the default route points + * @return The interface + */ + QString getDefaultInterface(); + + /** + * Gets the gateway of a given interface + * @return The interface + */ + QString getGatewayOfInterface(QString interface); + + QString getNetmaskOfInterface(QString interface); + + bool inSameNetwork(QString ip1,QString Netmask1,QString ip2,QString Netmask2); + + /** + * Gets the gateway of the default route + * @return The interface + */ + QString getGatewayOfDefaultInterface(); + + /** + * Gets the count of default route entries + * @return count + */ + int getDefaultRouteCount(); + + /** + * Gets the IP address which is used for communication with internet connections (same as local address if not behind router) + * @return The external IP address + */ + QString getExternalIpAddress(); + + bool inSameNetwork(QString ip1,QString ip2); + +public slots: + void readFromStdout(); + void readFromStderr(); + void processHasFinished(); + void readFromStdout_interfaceip(); + void readFromStderr_interfaceip(); + void externalIpDataRecieved(const QHttpResponseHeader & resp); + +protected: + QProcess *proc; //< The process for starting external programs + QProcess *InterfaceExitsProc; + QProcess *InterfaceIpProc; + bool interfaceTest; //< True if interface test is running + bool retrieveInterfaceIP; //< True if retrieve interface IP is running + bool retrieveInterfaceAddress; //< True if retrieve interface address is running + QStringList InterfaceList; //< List with interfaces + QString InterfaceIP; //< IP for interface + QString InterfaceAddress; //< Device for IP + QString GatewayAddress; //< Gateway of Device + QString GatewayOfInterfaceAddress; + QString GatewayOfDefaultInterfaceAddress; //< Gateway of Device + bool interfaceExists; //< True if interface exists + QString ifconfigbin; //< Path to ifconfig + QString routebin; //< Path to route + QString defaultinterface; //< Interface with defaultroute + QString IPforInterface; //< The Ip for interface + QString tmpInterface; //< Interface for getting devname + QApplication *app; + bool readOutput,getExternalIpAddressRunning; + KTempFile *tmpfile; + QHttp *http; + QString ExternalIpAddress; + QStringList *env; + KVpncConfig *GlobalConfig; +}; + +#endif diff --git a/src/newprofiledialog.cpp b/src/newprofiledialog.cpp new file mode 100644 index 0000000..f9cb763 --- /dev/null +++ b/src/newprofiledialog.cpp @@ -0,0 +1,669 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +//BEGIN includes +#include "newprofiledialog.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "utils.h" + + +#include "networkinterface.h" +#include "importcertificatedialog.h" +#include "importprofiledialog.h" +#include "vpnaccountdata.h" + +//END includes + +NewProfileDialog::NewProfileDialog( QApplication *app,QWidget *parent, const QString& caption, KVpncConfig *GlobalConfig) + : KDialogBase( parent, "New_profile", true, caption, + KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, true ) +{ + this->GlobalConfig = GlobalConfig; + + main = new NewProfileDialogbase(this); + setMainWidget(main); + main->setMinimumSize(main->sizeHint()); + + connect( main->ConnectionTypeComboBox, SIGNAL( activated( const QString& ) ), this, SLOT( connectiontypeChanged( const QString& ) ) ); + connect( main->AuthTypeComboBox , SIGNAL( activated( const QString& ) ), this, SLOT( authTypeChanged( const QString& ) ) ); + // connect( main->buttonCancel , SIGNAL( clicked () ), this, SLOT( reject() ) ); + connect( main->ImportCertificatePushButton, SIGNAL( clicked () ), this, SLOT( importCertificate() ) ); + connect( main->AdvancedSettingsPushButton, SIGNAL( clicked () ), this, SLOT( advancedSettingsClicked() ) ); + connect( main->ImportPcfProfilePushButton , SIGNAL( clicked () ), this, SLOT( importPcfFileClicked() ) ); + connect( main->GroupPasswordEdit, SIGNAL( textChanged(const QString&) ), this, SLOT( groupPasswordContentChanged() ) ); + connect( main->PasswordEdit, SIGNAL( textChanged(const QString&) ), this, SLOT( passwordContentChanged() ) ); + newProfileCreated = FALSE; + Name = ""; + + // currently static for new profile + VpnAccountData::ConnectionType ConnType = VpnAccountData::ConnectionType(VpnAccountData::other); + Port = 500; + Gateway = ""; + ID = ""; + Username = ""; + UserPassword = ""; + PreSharedKey = ""; + ApplicationVersion = ""; + NtDomainName = ""; + PerfectForwardSecrecy = ""; + IkeGroup = ""; + Description =""; + useApplicationVersion = false; + useGlobalIpsecSecret = false; + useIkeGroup = false; + useLocalPort = false; + useNtDomainName = false; + useSingleDes = false; + useAdvancedSettings = false; + usePerfectSecrecy = false; + saveUserPassword = false; + savePsk = false; + useUdp=false; + useUdpPort=false; + useDnsServer=false; + DnsServer=""; + useGetDnsFromPeer=true; + refuse40BitEncryption=true; + refuse128BitEncryption=false; + allowStatefulMode=false; + requireMppe=true; + refuseEap=false; + useNoBsdComp=true; + useNoDeflate=true; + savePsk=false; + + + profileData = new VpnAccountData( ConnType, Name ); + profileData->setGateway ( Gateway ); + profileData->setID( ID ); + profileData->setPreSharedKey( PreSharedKey); + profileData->setSavePsk( savePsk ); + profileData->setUserName( Username ); + profileData->setUserPassword( UserPassword ); + profileData->setSaveUserPassword( saveUserPassword ); + profileData->setSavePsk( savePsk ); + profileData->setApplicationVersion( ApplicationVersion ); + profileData->setUseLocalPort( useLocalPort ); + profileData->setLocalPort( Port ); + profileData->setUseSingleDes ( useSingleDes ); + profileData->setPerfectForwardSecrety ( PerfectForwardSecrecy ); + profileData->setIkeGroup( IkeGroup ); + profileData->setUseGlobalIpsecSecret (useGlobalIpsecSecret ); + profileData->setUseIkeGroup ( useIkeGroup ); + profileData->setNtDomainName (NtDomainName ); + profileData->setUseAdvancedSettings ( useAdvancedSettings ); + profileData->setUsePerfectForwardSecrety (usePerfectSecrecy ); + + + + + NetworkInterface iface(GlobalConfig,app); + QStringList list = iface.getAllNetworkInterfaces(); + main->NetworkDeviceComboBox->insertItem( "default" ); + for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) + { + main->NetworkDeviceComboBox->insertItem( QString( *it ) ); + } + main->NetworkDeviceComboBox->setEnabled( TRUE ); + main->NetworkDeviceComboBox->setCurrentText( "default" ); + + main->certpathURLRequester->setURL( "/etc/racoon/certs" ); + main->certpathURLRequester->setMode( 2 ); // directory + + main->ConnectionTypeComboBox->insertItem( i18n( "Cisco (vpnc)" ) ); + main->ConnectionTypeComboBox->insertItem( i18n( "IPSec (racoon)" ) ); + main->ConnectionTypeComboBox->insertItem( i18n( "IPSec (FreeS/WAN)" ) ); + main->ConnectionTypeComboBox->insertItem( i18n( "PPTP" ) ); + main->ConnectionTypeComboBox->insertItem( i18n( "OpenVPN" ) ); + main->AuthTypeComboBox->setCurrentItem(1); // cisco + + main->RemoteNetMaskComboBox->setCurrentText("24"); + + authTypeChanged( "" ); + connectiontypeChanged( "" ); +} + +NewProfileDialog::~NewProfileDialog() +{} + +void NewProfileDialog::accept() +{ + bool canSave = TRUE; + if ( main->ConnectionTypeComboBox->currentItem() == 0 ) { + profileData->setConnectionType( VpnAccountData::cisco ); + UdpPort=10000; +} + else if ( main->ConnectionTypeComboBox->currentItem() == 1 ) + { + profileData->setConnectionType( VpnAccountData::racoon ); + + if (main->AuthTypeComboBox->currentItem() == 0) + profileData->setAuthType( VpnAccountData::cert ); + else + profileData->setAuthType( VpnAccountData::psk ); + + profileData->setX509Certificate( main->x509certURLRequester->url() ); + profileData->setCertPath( main->certpathURLRequester->url() ); + + UdpPort=4500; + } + else if ( main->ConnectionTypeComboBox->currentItem() == 2 ) + { + profileData->setConnectionType( VpnAccountData::freeswan ); + UdpPort=4500; + } + else if ( main->ConnectionTypeComboBox->currentItem() == 3 ) + { + profileData->setConnectionType( VpnAccountData::pptp ); + } + else if ( main->ConnectionTypeComboBox->currentItem() == 4 ) + { + profileData->setConnectionType( VpnAccountData::openvpn ); + } + else + profileData->setConnectionType( VpnAccountData::other ); + + bool validAddr = TRUE; + + if ( profileData->getConnectionType() != VpnAccountData::cisco && profileData->getConnectionType() != VpnAccountData::openvpn ) + { + if ( main->RemoteNetAddrLineEdit->text().contains( '.' ) != 3 ) + { + KMessageBox::error ( this, i18n( "No IP address for remote network entered!" ), i18n( "No IP Address" ) ); + GlobalConfig->appendLogEntry( i18n( "No IP address for remote network entered!" ),GlobalConfig->error); + validAddr = canSave = FALSE; + } + else + { + if (!Utils(GlobalConfig).isValidIPv4Address(main->RemoteNetAddrLineEdit->text())) + { + + KMessageBox::error ( this, i18n( "IP address of remote network is not valid!" ), i18n( "Invalid IP Address" ) ); + GlobalConfig->appendLogEntry( i18n( "IP address of remote network not valid!" ) ,GlobalConfig->error); + + validAddr = canSave = FALSE; + } + if ( validAddr ) + { + profileData->setRemoteNetAddr( main->RemoteNetAddrLineEdit->text()); + profileData->setRemoteNetMask( main->RemoteNetMaskComboBox->currentText() ); + } + + } + } + + // profileData->setSavePsk( main->CheckGroupPass->isChecked() ); + // profileData->setSaveUserPassword( main->CheckUserPass->isChecked () ); + profileData->setSavePsk( !main->PSKLineEdit->text().isEmpty() ); + profileData->setSaveUserPassword( !main->PasswordEdit->text().isEmpty() ); + profileData->setID( main->IDLineEdit->text() ); + + profileData->setDescription( main->DescriptionLineEdit->text() ); + + profileData->setUserName( main->UsernameLineEdit->text () ); + + if ( main->CheckUserPass->isChecked ()) + { + profileData->setUserPassword( main->PasswordEdit->text ( ) ); + profileData->setSaveUserPassword(true); + } + + profileData->setGateway( main->gatewayLineEdit->text() ); + + + if ( main->CheckGroupPass->isChecked()) + { + if (!profileData->getConnectionType() == VpnAccountData::cisco) + profileData->setPreSharedKey( main->PSKLineEdit->text() ); + else + profileData->setPreSharedKey( main->GroupPasswordEdit->text() ); + profileData->setSavePsk(true); + } + + profileData->setX509Certificate( main->x509certURLRequester->url() ); + profileData->setCertPath( main->certpathURLRequester->url() ); + profileData->setNetworkDevice( main->NetworkDeviceComboBox->currentText() ); + if (main->AuthTypeComboBox->currentItem() == 0) + profileData->setAuthType( VpnAccountData::cert ); + else + profileData->setAuthType( VpnAccountData::psk ); + + if ( canSave ) + { + + bool nameOk = TRUE; + Name = main->ProfileLineEdit->text(); + + if (Name.contains(' ')) + { + KMessageBox::error ( this, i18n( "Profile name can not contain spaces!" ), i18n( "Spaces Not Allowed" ) ); + GlobalConfig->appendLogEntry( i18n( "Profile name can not contain spaces!" ) ,GlobalConfig->error); + + nameOk = FALSE; + } + + if (Name.isEmpty()) + { + KMessageBox::error ( this, i18n( "Profile name can not be empty!" ), i18n( "No Name Entered" ) ); + GlobalConfig->appendLogEntry( i18n( "Profile name can not be empty!" ) ,GlobalConfig->error); + + nameOk = FALSE; + } + + VpnAccountData * it; + for ( it = GlobalConfig->AccountList->first(); it; it = GlobalConfig->AccountList->next() ) + { + if ( it->getName() == Name ) + { + KMessageBox::error ( this, i18n( "Profile name already exists!" ), i18n( "Name Already Exists" ) ); + GlobalConfig->appendLogEntry(i18n( "Profile name already exists!" ) ,GlobalConfig->error); + + nameOk = FALSE; + break; + } + } + + if ( nameOk ) + { + profileData->setName(Name); + GlobalConfig->AccountList->append( profileData ); + newProfileCreated = TRUE; + QDialog::accept(); + } + + } +} + +void NewProfileDialog::importCertificate() +{ + //FIXME make dynamiclly + ImportCertificateDialog importdlg( this, i18n("Import certificate...").ascii(), GlobalConfig); + //dlg.resize(dlg.height(),600); + //int result = + importdlg.exec(); +} + + +void NewProfileDialog::connectiontypeChanged( const QString& ) +{ + + // First we should set a type + //buttonOk->setEnabled( FALSE ); + main->AdvancedSettingsPushButton->setEnabled( FALSE ); + + int item = main->ConnectionTypeComboBox->currentItem(); + + if ( item == VpnAccountData::ConnectionType(VpnAccountData::cisco) ) + { + + + GlobalConfig->appendLogEntry( i18n("New type: %1").arg("cisco"),GlobalConfig->debug ); + + profileData->setConnectionType( VpnAccountData::cisco ); + + main->CheckGroupPass->setEnabled( TRUE ); + main->CheckUserPass->setEnabled( TRUE ); + + main->IDLineEdit->setEnabled( TRUE ); + main->LabelID->setEnabled( TRUE ); + + main->UsernameLineEdit->setEnabled( TRUE ); + main->LabelUsername->setEnabled( TRUE ); + + main->PasswordEdit->setEnabled( TRUE ); + main->LabelPassword->setEnabled( TRUE ); + + main->AdvancedSettingsPushButton->setEnabled( TRUE ); + + main->x509certURLRequester->setEnabled( FALSE ); + main->LabelCertificate->setEnabled( FALSE ); + + main->certpathURLRequester->setEnabled( FALSE ); + main->LabelCertificatePath->setEnabled( FALSE ); + + main->NetworkDeviceComboBox->setEnabled( FALSE ); + main->LabelNetworkDevice->setEnabled( FALSE ); + main->AuthTypeComboBox->setEnabled( FALSE ); + main->LabelAuthType->setEnabled( FALSE ); + + main->PSKLineEdit->setEnabled( FALSE ); + main->LabelPsk->setEnabled( FALSE ); + + //buttonCancel->setEnabled( TRUE ); + //buttonOk->setEnabled( TRUE ); + + main->RemoteNetAddrLineEdit->setEnabled( FALSE ); + main->LabelRemoteNetwork->setEnabled( FALSE ); + + main->RemoteNetMaskComboBox->setEnabled( FALSE ); + + } // vpnc + + else if ( item == VpnAccountData::ConnectionType(VpnAccountData::racoon) ) + { + + + GlobalConfig->appendLogEntry( i18n("New type: %1").arg("racoon"),GlobalConfig->debug ); + // KURLRequester* main->x509certURLRequester; + // KComboBox* main->AuthTypeComboBox; + // KPushButton* ImportCertificatePushButton; + // KLineEdit* main->PSKLineEdit; + + profileData->setConnectionType( VpnAccountData::racoon ); + + main->x509certURLRequester->setEnabled( TRUE ); + main->LabelCertificate->setEnabled( TRUE ); + + main->certpathURLRequester->setEnabled( TRUE ); + main->LabelCertificatePath->setEnabled( TRUE ); + + main->NetworkDeviceComboBox->setEnabled ( TRUE ); + main->LabelNetworkDevice->setEnabled( TRUE ); + + main->AuthTypeComboBox->setEnabled( TRUE ); + main->LabelAuthType->setEnabled( TRUE ); + + main->PSKLineEdit->setEnabled( TRUE ); + main->LabelPsk->setEnabled( TRUE ); + + main->RemoteNetAddrLineEdit->setEnabled( TRUE ); + main->LabelRemoteNetwork->setEnabled( TRUE ); + + main->RemoteNetMaskComboBox->setEnabled( TRUE ); + + main->PasswordEdit->setEnabled( FALSE ); + main->LabelPassword->setEnabled( FALSE ); + + main->CheckGroupPass->setEnabled( FALSE ); + main->CheckUserPass->setEnabled( FALSE ); + + main->IDLineEdit->setEnabled( FALSE ); + main->LabelID->setEnabled( FALSE ); + + main->UsernameLineEdit->setEnabled( FALSE ); + main->LabelUsername->setEnabled( FALSE ); + + main->GroupPasswordEdit->setEnabled( FALSE ); + main->LabelGroupPassword->setEnabled( FALSE ); + + //buttonCancel->setEnabled( TRUE ); + //buttonOk->setEnabled( TRUE ); + main->AdvancedSettingsPushButton->setEnabled( TRUE ); + } // racoon + + else if ( item == VpnAccountData::ConnectionType(VpnAccountData::freeswan) ) + { + + + GlobalConfig->appendLogEntry( i18n("New type: %1").arg("freeswan"), GlobalConfig->debug ); + // KURLRequester* main->x509certURLRequester; + // KComboBox* main->AuthTypeComboBox; + // KPushButton* ImportCertificatePushButton; + // KLineEdit* main->PSKLineEdit; + + profileData->setConnectionType( VpnAccountData::freeswan ); + + main->x509certURLRequester->setEnabled( TRUE ); + main->LabelCertificate->setEnabled( TRUE ); + + main->certpathURLRequester->setEnabled( TRUE ); + main->LabelCertificatePath->setEnabled( TRUE ); + + main->NetworkDeviceComboBox->setEnabled ( TRUE ); + main->LabelNetworkDevice->setEnabled( TRUE ); + + main->AuthTypeComboBox->setEnabled( TRUE ); + main->LabelAuthType->setEnabled( TRUE ); + + main->PSKLineEdit->setEnabled( TRUE ); + main->LabelPsk->setEnabled( TRUE ); + + main->RemoteNetAddrLineEdit->setEnabled( TRUE ); + main->LabelRemoteNetwork->setEnabled( TRUE ); + + main->RemoteNetMaskComboBox->setEnabled( TRUE ); + + main->CheckGroupPass->setEnabled( FALSE ); + main->CheckUserPass->setEnabled( FALSE ); + + main->IDLineEdit->setEnabled( FALSE ); + main->LabelID->setEnabled( FALSE ); + + main->PasswordEdit->setEnabled( FALSE ); + main->LabelPassword->setEnabled( FALSE ); + + main->UsernameLineEdit->setEnabled( FALSE ); + main->LabelUsername->setEnabled( FALSE ); + + main->GroupPasswordEdit->setEnabled( FALSE ); + main->LabelGroupPassword->setEnabled( FALSE ); + + // buttonCancel->setEnabled( TRUE ); + // buttonOk->setEnabled( TRUE ); + main->AdvancedSettingsPushButton->setEnabled( TRUE ); + } // freeswan + + else if ( item == VpnAccountData::ConnectionType(VpnAccountData::pptp) ) + { + + + GlobalConfig->appendLogEntry( i18n("New type: %1").arg("pptp"),GlobalConfig->debug ); + // KURLRequester* main->x509certURLRequester; + // KComboBox* main->AuthTypeComboBox; + // KPushButton* ImportCertificatePushButton; + // KLineEdit* main->PSKLineEdit; + + profileData->setConnectionType( VpnAccountData::pptp ); + + main->x509certURLRequester->setEnabled( FALSE ); + main->LabelCertificate->setEnabled( FALSE ); + + main->certpathURLRequester->setEnabled( FALSE ); + main->LabelCertificatePath->setEnabled( FALSE ); + + main->NetworkDeviceComboBox->setEnabled ( FALSE ); + main->LabelNetworkDevice->setEnabled( FALSE ); + + main->AuthTypeComboBox->setEnabled( FALSE ); + main->LabelAuthType->setEnabled( FALSE ); + + main->PSKLineEdit->setEnabled( FALSE ); + main->LabelPsk->setEnabled( FALSE ); + + main->RemoteNetAddrLineEdit->setEnabled( TRUE ); + main->LabelRemoteNetwork->setEnabled( TRUE ); + + main->RemoteNetMaskComboBox->setEnabled( TRUE ); + + main->CheckGroupPass->setEnabled( FALSE ); + main->CheckUserPass->setEnabled( TRUE ); + + main->IDLineEdit->setEnabled( FALSE ); + main->LabelID->setEnabled( FALSE ); + + main->PasswordEdit->setEnabled( TRUE ); + main->LabelPassword->setEnabled( TRUE ); + + main->UsernameLineEdit->setEnabled( TRUE ); + main->LabelUsername->setEnabled( TRUE ); + + main->GroupPasswordEdit->setEnabled( FALSE ); + main->LabelGroupPassword->setEnabled( FALSE ); + + //buttonCancel->setEnabled( TRUE ); + //buttonOk->setEnabled( TRUE ); + main->AdvancedSettingsPushButton->setEnabled( TRUE ); + } // pptp + else if ( item == VpnAccountData::ConnectionType(VpnAccountData::openvpn) ) + { + if (GlobalConfig->KvpncDebugLevel > 0) + GlobalConfig->appendLogEntry( i18n("New type: %1").arg("openvpn"),GlobalConfig->debug ); + // KURLRequester* main->x509certURLRequester; + // KComboBox* main->AuthTypeComboBox; + // KPushButton* ImportCertificatePushButton; + // KLineEdit* main->PSKLineEdit; + + profileData->setConnectionType( VpnAccountData::openvpn ); + + main->x509certURLRequester->setEnabled( TRUE ); + main->LabelCertificate->setEnabled( TRUE ); + + main->certpathURLRequester->setEnabled( TRUE ); + main->LabelCertificatePath->setEnabled( TRUE ); + + main->NetworkDeviceComboBox->setEnabled ( TRUE ); + main->LabelNetworkDevice->setEnabled( TRUE ); + + main->AuthTypeComboBox->setEnabled( TRUE ); + main->LabelAuthType->setEnabled( TRUE ); + + main->PSKLineEdit->setEnabled( TRUE ); + main->LabelPsk->setEnabled( TRUE ); + + main->RemoteNetAddrLineEdit->setEnabled( FALSE ); + main->LabelRemoteNetwork->setEnabled( FALSE ); + + main->RemoteNetMaskComboBox->setEnabled( TRUE ); + + main->PasswordEdit->setEnabled( FALSE ); + main->LabelPassword->setEnabled( FALSE ); + + main->CheckGroupPass->setEnabled( FALSE ); + main->CheckUserPass->setEnabled( FALSE ); + + main->IDLineEdit->setEnabled( FALSE ); + main->LabelID->setEnabled( FALSE ); + + + main->UsernameLineEdit->setEnabled( FALSE ); + main->LabelUsername->setEnabled( FALSE ); + + main->GroupPasswordEdit->setEnabled( FALSE ); + main->LabelGroupPassword->setEnabled( FALSE ); + + //buttonCancel->setEnabled( TRUE ); + //buttonOk->setEnabled( TRUE ); + main->AdvancedSettingsPushButton->setEnabled( TRUE ); + } // openvpn + + // other + else + { + + if (GlobalConfig->KvpncDebugLevel > 0) + GlobalConfig->appendLogEntry( "new type: other",GlobalConfig->debug ); + // main->x509certURLRequester->setEnabled( FALSE ); + // main->AuthTypeComboBox->setEnabled( FALSE ); + // main->PSKLineEdit->setEnabled( FALSE ); + // + // main->CheckGroupPass->setEnabled( FALSE ); + // main->CheckUserPass->setEnabled( FALSE ); + // main->IDLineEdit->setEnabled( FALSE ); + // main->UsernameLineEdit->setEnabled( FALSE ); + // main->AdvancedSettingsPushButton->setEnabled( FALSE ); + // buttonCancel->setEnabled( FALSE ); + //buttonOk->setEnabled( FALSE ); + } +} + +void NewProfileDialog::authTypeChanged( const QString& ) +{ + if ( main->AuthTypeComboBox->currentItem() == VpnAccountData::AuthenticationType(VpnAccountData::cert )) + { + // certificate + main->PSKLineEdit->setEnabled( FALSE ); + main->LabelPsk->setEnabled( FALSE ); + + main->x509certURLRequester->setEnabled( TRUE ); + main->LabelCertificate->setEnabled( TRUE ); + + main->certpathURLRequester->setEnabled( TRUE ); + main->LabelCertificatePath->setEnabled( TRUE ); + } + if ( main->AuthTypeComboBox->currentItem() == VpnAccountData::AuthenticationType(VpnAccountData::psk )) + { + // psk + main->PSKLineEdit->setEnabled( TRUE ); + main->LabelPsk->setEnabled( TRUE ); + + main->x509certURLRequester->setEnabled( FALSE ); + main->LabelCertificate->setEnabled( FALSE ); + + main->certpathURLRequester->setEnabled( FALSE ); + main->LabelCertificatePath->setEnabled( FALSE ); + } + +} + +void NewProfileDialog::reject() +{ + QDialog::reject(); +} + +void NewProfileDialog::profileNameChanged( const QString& ) +{ + // LogOutput->append ( "text changed!" ); + // if ( main->ProfileLineEdit->text().isEmpty() ) + // buttonOk->setEnabled( FALSE ); + // else + // buttonOk->setEnabled( TRUE ); +} + +QString NewProfileDialog::getName() +{ + return Name; +} + +void NewProfileDialog::importPcfFileClicked() +{ + ImportProfileDialog dlg(GlobalConfig,this, i18n("Import Cisco PCF Profile..."),""); + dlg.exec(); + dlg.resize(800,dlg.height()); +} + +void NewProfileDialog::groupPasswordContentChanged() +{ + if (!main->GroupPasswordEdit->text().isEmpty()) + main->CheckGroupPass->setChecked(true); + else + main->CheckGroupPass->setChecked(false); +} + + +void NewProfileDialog::passwordContentChanged() +{ + if (!main->PasswordEdit->text().isEmpty()) + main->CheckUserPass ->setChecked(true); + else + main->CheckUserPass->setChecked(false); +} + diff --git a/src/newprofiledialog.h b/src/newprofiledialog.h new file mode 100644 index 0000000..7fecfd4 --- /dev/null +++ b/src/newprofiledialog.h @@ -0,0 +1,100 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef NEWPROFILEDIALOG_H +#define NEWPROFILEDIALOG_H + +#include "newprofiledialogbase.h" +#include "vpnaccountdata.h" +#include +#include +#include +#include +#include "kvpncconfig.h" + +/** +@author Christoph Thielecke +*/ +class NewProfileDialog : public KDialogBase +{ + Q_OBJECT +public: + NewProfileDialog( QApplication *app, QWidget *parent, const QString& caption, KVpncConfig *GlobalConfig); + ~NewProfileDialog(); + QString getName(); + + +public slots: + void accept(); + void reject(); + void importCertificate(); + void connectiontypeChanged( const QString& ); + void authTypeChanged( const QString& ); + void profileNameChanged(const QString&); + void importPcfFileClicked(); + void groupPasswordContentChanged(); + void passwordContentChanged(); + +protected: + NewProfileDialogbase *main; + QString ConnectionType; + QString Gateway; + QString ID; + QString Username; + QString UserPassword; + QString PreSharedKey; + QString ApplicationVersion; + QString NtDomainName; + QString PerfectForwardSecrecy; + QString IkeGroup; + QString DnsServer; //< userdefined DNS server for pptp + QString Name; + QString Description; + bool saveUserPassword; + bool savePsk; + bool useApplicationVersion; + bool useGlobalIpsecSecret; + bool useIkeGroup; + bool useLocalPort; + bool useNtDomainName; + bool useSingleDes; + bool useAdvancedSettings; + bool usePerfectSecrecy; + bool useUdp; //< True if NAT-T should be used + bool useUdpPort; //< True if userdefined UDP port should be used + bool useDnsServer; //< True if userdefined DNS server should be used + bool useGetDnsFromPeer; //< True if DNS servers should be retrieved from peer (pptp)bool + bool refuse40BitEncryption; //< True if 40 bit encryption is refused (pptp) + bool refuse128BitEncryption; //< True if 128 bit encryption is refused (pptp) + bool allowStatefulMode; + bool useNoBsdComp; + bool useNoDeflate; + bool requireMppe; //< True if MPPE is required (pptp) + bool refuseEap; //< True if EAP is refused (pptp) + int Port; + int UdpPort; //< Port number of UDP port + KVpncConfig *GlobalConfig; + + +public: + bool newProfileCreated; + VpnAccountData *profileData; +}; + +#endif diff --git a/src/newprofiledialogbase.ui b/src/newprofiledialogbase.ui new file mode 100644 index 0000000..7635225 --- /dev/null +++ b/src/newprofiledialogbase.ui @@ -0,0 +1,703 @@ + +NewProfileDialogbase + + + NewProfileDialogBase + + + + 0 + 0 + 461 + 623 + + + + Add new Profile + + + + unnamed + + + 11 + + + 6 + + + + layout9 + + + + unnamed + + + + AdvancedSettingsPushButton + + + Ad&vanced... + + + Alt+V + + + Advanced settings (mostly not need) + + + + + spacer7 + + + Horizontal + + + Expanding + + + + 321 + 20 + + + + + + + + layout11 + + + + unnamed + + + + ImportPcfProfilePushButton + + + &Import Cisco PCF Profile... + + + Alt+I + + + Import Cisco PCF profile + + + + + ImportCertificatePushButton + + + Import p1&2 Certificate... + + + Alt+2 + + + Import a certificate in P12 format + + + + + spacer132 + + + Horizontal + + + Expanding + + + + 110 + 20 + + + + + + + + spacer47 + + + Vertical + + + Expanding + + + + 20 + 16 + + + + + + IDLineEdit + + + IPSec ID of the remote side + + + + + LabelNetworkDevice + + + true + + + Network device: + + + + + PSKLineEdit + + + Password + + + Pre-shared key for authentication (shared secret) + + + + + x509certURLRequester + + + Certificate file name + + + + + LabelProfilename_2 + + + true + + + Description: + + + + + LabelPassword + + + Password: + + + + + LabelRemoteNetwork + + + true + + + Remote network: + + + + + CheckUserPass + + + &Save user password + + + Alt+S + + + Save the user password in config file (or in KWallet if available) + + + + + LabelID + + + IPSec ID: + + + + + ConnectionTypeComboBox + + + Connection type of the new profile + + + This is the connection type of the profile (e.g. Cisco). + + + + + DescriptionLineEdit + + + Description of the new profile + + + Enter the description of this profile here. + + + + + LabelGroupPassword + + + Group password: + + + + + LabelCertificatePath + + + Certificates path: + + + + + UsernameLineEdit + + + Username for authentication + + + Enter here your username + + + + + certpathURLRequester + + + Path to the certificates, used if no absolute path is given. + + + + + GroupPasswordEdit + + + Password + + + Group password for remote side + + + + + PasswordEdit + + + Password + + + Password for authentication + + + + + LabelPsk + + + true + + + Pre-shared key: + + + + + ProfileLineEdit + + + Name for the new profile + + + + + spacer30 + + + Horizontal + + + Expanding + + + + 159 + 20 + + + + + + LabelGateway + + + VPN gateway: + + + + + CheckGroupPass + + + Save &group password + + + Alt+G + + + Save the group password in config file (or in KWallet if available) + + + + + LabelConnectionType + + + Connection type: + + + + + LabelAuthType + + + Authentication type: + + + + + spacer31 + + + Horizontal + + + Expanding + + + + 159 + 20 + + + + + + LabelCertificate + + + Certificate: + + + + + gatewayLineEdit + + + Hostname or IP address of the VPN gateway + + + + + LabelProfilename + + + true + + + Profile name: + + + + + LabelUsername + + + Username: + + + + + spacer169 + + + Horizontal + + + Expanding + + + + 114 + 20 + + + + + + NetworkDeviceComboBox + + + true + + + Network device for use with tunnel + + + This the the network device which should be used for the tunnel. <br>Its only active if needed. If no selection made, <br>"default" is set for using the device where the defaultroute points to. + + + + + spacer46 + + + Horizontal + + + Expanding + + + + 75 + 20 + + + + + + + X.509 Certificate + + + + + Pre Shared Key + + + + AuthTypeComboBox + + + Authentication type + + + + + layout8 + + + + unnamed + + + + RemoteNetAddrLineEdit + + + Remote network address + + + This is the remote network where the connection should going to. <br>Use this at a PPTP connection for set another network than the retrieved IP is located. + + + + + RemoteNetDividetextLabel + + + / + + + + + + 10 + + + + + 11 + + + + + 12 + + + + + 13 + + + + + 14 + + + + + 15 + + + + + 16 + + + + + 17 + + + + + 18 + + + + + 19 + + + + + 20 + + + + + 21 + + + + + 22 + + + + + 23 + + + + + 24 + + + + + 26 + + + + + 25 + + + + + 27 + + + + + 28 + + + + + 29 + + + + + 30 + + + + + 32 + + + + RemoteNetMaskComboBox + + + Network prefix (netmask) + + + + + + + + ProfileLineEdit + DescriptionLineEdit + ConnectionTypeComboBox + gatewayLineEdit + GroupPasswordEdit + RemoteNetAddrLineEdit + RemoteNetMaskComboBox + AuthTypeComboBox + IDLineEdit + PSKLineEdit + NetworkDeviceComboBox + UsernameLineEdit + PasswordEdit + certpathURLRequester + x509certURLRequester + CheckGroupPass + CheckUserPass + AdvancedSettingsPushButton + ImportPcfProfilePushButton + ImportCertificatePushButton + + + profileNameChanged(const QString&) + importPcfFileClicked() + passwordContentChanged() + groupPasswordContentChanged() + + + + kpushbutton.h + kpushbutton.h + kpushbutton.h + klineedit.h + klineedit.h + kurlrequester.h + klineedit.h + kpushbutton.h + kcombobox.h + klineedit.h + klineedit.h + kurlrequester.h + klineedit.h + kpushbutton.h + klineedit.h + klineedit.h + kcombobox.h + klineedit.h + kcombobox.h + klineedit.h + kcombobox.h + + diff --git a/src/newprofilewizard.cpp b/src/newprofilewizard.cpp new file mode 100644 index 0000000..296d80c --- /dev/null +++ b/src/newprofilewizard.cpp @@ -0,0 +1,4008 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +//BEGIN INCLUDES + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "kvpncconfig.h" +#include "networkinterface.h" +#include "newprofilewizard.h" +#include "addnetworkroutedialog.h" +#include "utils.h" +//END INCLUDES + +NewProfileWizard::NewProfileWizard ( KVpncConfig* GlobalConfig ) +{ + this->GlobalConfig = GlobalConfig; + + newProfileCreated = false; + setCaption ( i18n ( "Add new profile..." ) ); + //setMinimumSize( 400,300); + + SetupPixmap = new QPixmap ( locate ( "data", "kvpnc/newprofilewizard.png" ) ); + SetupPixmapFinal = new QPixmap ( locate ( "data", "kvpnc/newprofilewizard_final.png" ) ); + + // currently static for new profile + VpnAccountData::ConnectionType ConnType = VpnAccountData::ConnectionType ( VpnAccountData::other ); + Port = 500; + Gateway = ""; + ID = ""; + Username = ""; + UserPassword = ""; + PreSharedKey = ""; + ApplicationVersion = ""; + NtDomainName = ""; + PerfectForwardSecrecy = ""; + IkeGroup = ""; + Description = ""; + Name = "None"; + useApplicationVersion = false; + useGlobalIpsecSecret = false; + useIkeGroup = false; + useLocalPort = false; + useNtDomainName = false; + useSingleDes = false; + useAdvancedSettings = false; + usePerfectSecrecy = false; + saveUserPassword = false; + savePsk = false; + useUdp = false; + useUdpPort = false; + useDnsServer = false; + DnsServer = ""; + useGetDnsFromPeer = true; + refuse40BitEncryption = true; + refuse128BitEncryption = false; + allowStatefulMode = false; + requireMppe = true; + useNoBsdComp = true; + useNoDeflate = true; + savePsk = false; + connectaftercreating = true; + daemonavailable = false; + enterdatamanually = false; + importOK = false; + + currentpage = 0; + previouspage = 0; + + profileData = new VpnAccountData ( ConnType, Name ); + profileData->setGateway ( Gateway ); + profileData->setID ( ID ); + profileData->setPreSharedKey ( PreSharedKey ); + profileData->setSavePsk ( savePsk ); + profileData->setUserName ( Username ); + profileData->setUserPassword ( UserPassword ); + profileData->setSaveUserPassword ( saveUserPassword ); + profileData->setSavePsk ( savePsk ); + profileData->setApplicationVersion ( ApplicationVersion ); + profileData->setUseLocalPort ( useLocalPort ); + profileData->setLocalPort ( Port ); + profileData->setUseSingleDes ( useSingleDes ); + profileData->setPerfectForwardSecrety ( PerfectForwardSecrecy ); + profileData->setIkeGroup ( IkeGroup ); + profileData->setUseGlobalIpsecSecret ( useGlobalIpsecSecret ); + profileData->setUseIkeGroup ( useIkeGroup ); + profileData->setNtDomainName ( NtDomainName ); + profileData->setUseAdvancedSettings ( useAdvancedSettings ); + profileData->setUsePerfectForwardSecrety ( usePerfectSecrecy ); + profileData->setUseTlsAuth ( false ); + + setupPages(); + + // // tmp + // newprofilewizardtypeselectionpagecontent->FreeswanRadioButton->setEnabled(false); + // newprofilewizardtypeselectionpagecontent->RacoonRadioButton->setEnabled(false); +} + +void NewProfileWizard::accept() +{ + + if ( !enterdatamanually ) + { + if ( profileData->getConnectionType() == VpnAccountData::cisco ) + { +// importProfile( VpnAccountData::cisco ); +// if ( importOK ) +// newProfileCreated = true; +// else +// newProfileCreated = false; + } + } + else + { + newProfileCreated = true; + } + finished = true; + + if ( newProfileCreated && profileData->getAuthType() == VpnAccountData::cert ) + {} + + QWizard::accept(); +} + +void NewProfileWizard::reject() +{ + finished = false; + QWizard::reject(); +} + +void NewProfileWizard::setupPages() +{ + + // setup start page + page1 = new QHBox ( 0 ); + // page1->setSpacing(8); + QLabel *setupPixmapContent1 = new QLabel ( page1 ); + setupPixmapContent1->setPixmap ( *SetupPixmap ); + setupPixmapContent1->resize ( setupPixmapContent1->sizeHint() ); + newprofilewizardstartcontent = new NewProfileWizardStart ( page1 ); + newprofilewizardstartcontent->resize ( newprofilewizardstartcontent->sizeHint() ); + page1->sizeHint(); + addPage ( page1, "" + i18n ( "Welcome" ) + "" ); + + // type selection + newprofilewizardtypeselectionpage = new QHBox ( 0 ); + // newprofilewizardtypeselectionpage->setSpacing(8); + QLabel *setupPixmapContent2 = new QLabel ( newprofilewizardtypeselectionpage ); + setupPixmapContent2->setPixmap ( *SetupPixmap ); + setupPixmapContent2->resize ( setupPixmapContent2->sizeHint() ); + newprofilewizardtypeselectionpagecontent = new NewProfileWizardTypeSelection ( newprofilewizardtypeselectionpage ); + newprofilewizardtypeselectionpagecontent->FreeswanRadioButton->setText ( i18n ( "IPSec (%1)" ).arg ( "FreeS/WAN/Openswan/strongSwan" ) ); + newprofilewizardtypeselectionpagecontent->L2tpFreeswanRadioButton->setText ( i18n ( "L2TP over IPSec (%1)" ).arg ( "FreeS/WAN/Openswan/strongSwan" ) ); + newprofilewizardtypeselectionpage->sizeHint(); + addPage ( newprofilewizardtypeselectionpage, "" + i18n ( "Type selection" ) + "" ); + + // cisco + newprofilewizardciscoselectionpage = new QHBox ( 0 ); + // newprofilewizardciscoselectionpage->setSpacing(8); + QLabel *setupPixmapContent3 = new QLabel ( newprofilewizardciscoselectionpage ); + setupPixmapContent3->setPixmap ( *SetupPixmap ); + setupPixmapContent3->resize ( setupPixmapContent3->sizeHint() ); + newprofilewizardciscoselectionpagecontent = new NewProfileWizardCiscoSelection ( newprofilewizardciscoselectionpage ); + newprofilewizardciscoselectionpage->sizeHint(); + + newprofilewizardciscomanuallypage = new QHBox ( 0 ); + // newprofilewizardciscomanuallypage->setSpacing(8); + QLabel *setupPixmapContent4 = new QLabel ( newprofilewizardciscomanuallypage ); + setupPixmapContent4->setPixmap ( *SetupPixmap ); + setupPixmapContent4->resize ( setupPixmapContent4->sizeHint() ); + newprofilewizardciscomanuallypagecontent = new NewProfileWizardCiscoManually ( newprofilewizardciscomanuallypage ); + newprofilewizardciscomanuallypage->sizeHint(); + + connect ( newprofilewizardciscomanuallypagecontent->GroupPasswordLineEdit , SIGNAL ( textChanged ( const QString& ) ), this, SLOT ( pskToggled ( const QString& ) ) ); + + // racoon + newprofilewizardracoonpage = new QHBox ( 0 ); + // newprofilewizardracoonpage->setSpacing(8); + QLabel *setupPixmapContent5 = new QLabel ( newprofilewizardracoonpage ); + setupPixmapContent5->setPixmap ( *SetupPixmap ); + setupPixmapContent5->resize ( setupPixmapContent5->sizeHint() ); + newprofilewizardracoonpagecontent = new NewProfileWizardRacoon ( newprofilewizardracoonpage ); + newprofilewizardracoonpagecontent->ExchangeModeComboBox->insertItem ( "main", 0 ); + newprofilewizardracoonpagecontent->ExchangeModeComboBox->insertItem ( "aggressive", 1 ); + newprofilewizardracoonpagecontent->ExchangeModeComboBox->insertItem ( "base", 2 ); + newprofilewizardracoonpagecontent->ExchangeModeComboBox->setCurrentItem ( 0 ); // main + + newprofilewizardracoonpagecontent->HashAlgoComboBox->insertItem ( "SHA1" ); + newprofilewizardracoonpagecontent->HashAlgoComboBox->insertItem ( "MD5" ); + newprofilewizardracoonpagecontent->HashAlgoComboBox->setCurrentItem ( 0 ); //SHA1 + + newprofilewizardracoonpagecontent->DHGroupComboBox->insertItem ( "modp768" ); + newprofilewizardracoonpagecontent->DHGroupComboBox->insertItem ( "modp1024" ); + newprofilewizardracoonpagecontent->DHGroupComboBox->insertItem ( "ec2n155" ); + newprofilewizardracoonpagecontent->DHGroupComboBox->insertItem ( "ec2n185" ); + newprofilewizardracoonpagecontent->DHGroupComboBox->insertItem ( "modp1536" ); + newprofilewizardracoonpagecontent->DHGroupComboBox->insertItem ( "modp2048" ); + newprofilewizardracoonpagecontent->DHGroupComboBox->insertItem ( "modp3072" ); + newprofilewizardracoonpagecontent->DHGroupComboBox->insertItem ( "modp4096" ); + newprofilewizardracoonpagecontent->DHGroupComboBox->insertItem ( "modp6144" ); + newprofilewizardracoonpagecontent->DHGroupComboBox->insertItem ( "modp8192" ); + + newprofilewizardracoonpagecontent->LocalIdTypeCombobox->insertItem("none"); + newprofilewizardracoonpagecontent->LocalIdTypeCombobox->insertItem("address"); + newprofilewizardracoonpagecontent->LocalIdTypeCombobox->insertItem("user_fqdn"); + newprofilewizardracoonpagecontent->LocalIdTypeCombobox->insertItem("fqdn"); + newprofilewizardracoonpagecontent->LocalIdTypeCombobox->insertItem("keyid (file)"); + newprofilewizardracoonpagecontent->LocalIdTypeCombobox->insertItem("keyid"); + newprofilewizardracoonpagecontent->LocalIdTypeCombobox->insertItem("asn1dn"); + + newprofilewizardracoonpagecontent->RemoteIdTypeCombobox->insertItem("none"); + newprofilewizardracoonpagecontent->RemoteIdTypeCombobox->insertItem("address"); + newprofilewizardracoonpagecontent->RemoteIdTypeCombobox->insertItem("user_fqdn"); + newprofilewizardracoonpagecontent->RemoteIdTypeCombobox->insertItem("fqdn"); + newprofilewizardracoonpagecontent->RemoteIdTypeCombobox->insertItem("keyid (file)"); + newprofilewizardracoonpagecontent->RemoteIdTypeCombobox->insertItem("keyid"); + newprofilewizardracoonpagecontent->RemoteIdTypeCombobox->insertItem("asn1dn"); + + QToolTip::add( newprofilewizardracoonpagecontent->RemoteIdTypeCombobox, i18n("Remote ID type
" + "" + "" + "" + "" + "" + "" + "
none:No ID
address:The type is the IP address. This is the default type if you do not specify an identifier to use
user_fqdn:The type is a USER_FQDN (user fully-qualified domain name)
fqdn:The type is a FQDN (fully-qualified domain name)
keyid (file):The type is a KEY_ID, read from the file
keyid:The type is a KEY_ID, specified in field
asn1dn:The type is an ASN.1 distinguished name. If empty, DN from the Subject field in the certificate will be used" + "")); + + QToolTip::add( newprofilewizardracoonpagecontent->LocalIdTypeCombobox, i18n("Local ID type
" + "" + "" + "" + "" + "" + "" + "
none:No ID
address:The type is the IP address. This is the default type if you do not specify an identifier to use
user_fqdn:The type is a USER_FQDN (user fully-qualified domain name)
fqdn:The type is a FQDN (fully-qualified domain name)
keyid (file):The type is a KEY_ID, read from the file
keyid:The type is a KEY_ID, specified in field
asn1dn:The type is an ASN.1 distinguished name. If empty, DN from the Subject field in the certificate will be used" + "")); + + newprofilewizardracoonpagecontent->PerfectForwardSecurityCheckbox->setChecked(true); + newprofilewizardracoonpagecontent->PerfectForwardSecrecyCombobox->setCurrentText("modp2048"); + + connect ( newprofilewizardracoonpagecontent->LocalIdTypeCombobox, SIGNAL ( highlighted ( const QString& ) ), this, SLOT ( localIDTypeRacoonToggled ( const QString& ) ) ); + connect ( newprofilewizardracoonpagecontent->RemoteIdTypeCombobox, SIGNAL ( highlighted ( const QString& ) ), this, SLOT ( remoteIDTypeRacoonToggled ( const QString& ) ) ); + + connect ( newprofilewizardracoonpagecontent->IkeGroupCheckbox, SIGNAL ( toggled ( bool ) ), this, SLOT ( ikeGroupToggled ( bool ) ) ); + connect ( newprofilewizardracoonpagecontent->UseXauthCheckBox, SIGNAL(toggled(bool)),this, SLOT(useXauthRacoonToggled(bool))); + + Utils::IpsecAlgos KernelCrypto = Utils ( GlobalConfig ).getKernelCrypto(); + + // man racoon.conf + newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->insertItem("des" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->insertItem("3des" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->insertItem("blowfish" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->insertItem("cast128" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->insertItem("aes" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->insertItem("camellia" ); + + // man racoon.conf + newprofilewizardracoonpagecontent->HashAlgoComboBox->insertItem( "md5" ); + newprofilewizardracoonpagecontent->HashAlgoComboBox->insertItem( "sha1" ); + newprofilewizardracoonpagecontent->HashAlgoComboBox->insertItem( "sha256" ); + newprofilewizardracoonpagecontent->HashAlgoComboBox->insertItem( "sha384" ); + newprofilewizardracoonpagecontent->HashAlgoComboBox->insertItem( "sha512" ); + + + + +// // phase 2 encr algos from kernel +// for ( QStringList::Iterator it = KernelCrypto.IpsecEspEncryptionAlgorithms.begin(); it != KernelCrypto.IpsecEspEncryptionAlgorithms.end(); ++it ) +// { +// newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem ( *it ); +// } +// +// // phase 2 auth algos from kernel +// for ( QStringList::Iterator it = KernelCrypto.IpsecEspAuthenticationAlgorithms.begin(); it != KernelCrypto.IpsecEspAuthenticationAlgorithms.end(); ++it ) +// { +// newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem ( *it ); +// } + + // vpn mit linux book + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem("des" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem("3des" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem("des_iv64" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem("des_iv32" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem("rc5" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem("rc4" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem("idea" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem("3idea" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem("cast128" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem("blowfish" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem("null_enc" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem("twofish" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem("rijndael" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem("aes" ); + + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem( "des" ); + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem( "3des" ); + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem( "des_iv64" ); + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem( "des_iv32" ); + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem( "hmac_md5" ); + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem( "hmac_sha1" ); + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem( "hmac_sha256" ); + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem( "hmac_sha384" ); + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem( "hmac_sha512" ); + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem( "non_auth" ); + + + // FIXME save not implemented yet + newprofilewizardracoonpagecontent->PerfectForwardSecurityCheckbox->hide(); + newprofilewizardracoonpagecontent->PerfectForwardSecrecyCombobox->hide(); + + newprofilewizardracoonpage->sizeHint(); + + //freeswan + newprofilewizardfreeswanselectionpage = new QHBox ( 0 ); + // newprofilewizardfreeswanselectionpage->setSpacing(8); + QLabel *setupPixmapContent711 = new QLabel ( newprofilewizardfreeswanselectionpage ); + setupPixmapContent711->setPixmap ( *SetupPixmap ); + setupPixmapContent711->resize ( setupPixmapContent711->sizeHint() ); + newprofilewizardfreeswanselectionpagecontent = new NewProfileWizardOpenvpnSelection ( newprofilewizardfreeswanselectionpage ); + newprofilewizardfreeswanselectionpagecontent->OpenvpnImportRadioButton->setText(i18n("Import &Ipsec config file")); + newprofilewizardfreeswanselectionpage->sizeHint(); + + newprofilewizardfreeswanpage = new QHBox ( 0 ); + // newprofilewizardfreeswanpage->setSpacing(8); + QLabel *setupPixmapContent6 = new QLabel ( newprofilewizardfreeswanpage ); + setupPixmapContent6->setPixmap ( *SetupPixmap ); + setupPixmapContent6->resize ( setupPixmapContent6->sizeHint() ); + newprofilewizardfreeswanpagecontent = new NewProfileWizardFreeswan ( newprofilewizardfreeswanpage ); + newprofilewizardfreeswanpage->sizeHint(); + + //freeswan + newprofilewizardfreeswanpage = new QHBox ( 0 ); + // newprofilewizardfreeswanpage->setSpacing(8); + QLabel *setupPixmapContent66 = new QLabel ( newprofilewizardfreeswanpage ); + setupPixmapContent66->setPixmap ( *SetupPixmap ); + setupPixmapContent66->resize ( setupPixmapContent66->sizeHint() ); + newprofilewizardfreeswanpagecontent = new NewProfileWizardFreeswan ( newprofilewizardfreeswanpage ); + + newprofilewizardfreeswanpagecontent->LocalIdTypeCombobox->insertItem(i18n("Certificate ID")); + newprofilewizardfreeswanpagecontent->LocalIdTypeCombobox->insertItem("asn1dn"); + newprofilewizardfreeswanpagecontent->LocalIdTypeCombobox->insertItem("address"); + newprofilewizardfreeswanpagecontent->LocalIdTypeCombobox->insertItem("fqdn"); + newprofilewizardfreeswanpagecontent->LocalIdTypeCombobox->insertItem("keyid"); + newprofilewizardfreeswanpagecontent->LocalIdTypeCombobox->insertItem("user_fqdn"); + + newprofilewizardfreeswanpagecontent->RemoteIdTypeCombobox->insertItem("asn1dn"); + newprofilewizardfreeswanpagecontent->RemoteIdTypeCombobox->insertItem("address"); + newprofilewizardfreeswanpagecontent->RemoteIdTypeCombobox->insertItem("fqdn"); + newprofilewizardfreeswanpagecontent->RemoteIdTypeCombobox->insertItem("keyid"); + newprofilewizardfreeswanpagecontent->RemoteIdTypeCombobox->insertItem("user_fqdn"); + newprofilewizardfreeswanpagecontent->RemoteIdTypeCombobox->insertItem("none"); + + newprofilewizardfreeswanpagecontent->IpsecVpnModeCombobox->insertItem( "transport" ); + newprofilewizardfreeswanpagecontent->IpsecVpnModeCombobox->insertItem( "tunnel" ); + + newprofilewizardfreeswanpagecontent->IpsecVpnModeCombobox->setCurrentItem(1); + newprofilewizardfreeswanpagecontent->DisableOpportunisticEncryptionCheckBox->setChecked(true); + newprofilewizardfreeswanpagecontent->UseModeConfigCheckBox->hide(); + newprofilewizardfreeswanpagecontent->PerfectForwardSecurityCheckbox->setChecked(true); + + connect ( newprofilewizardfreeswanpagecontent->LocalIdTypeCombobox, SIGNAL ( highlighted ( const QString& ) ), this, SLOT ( localIDTypeIpsecToggled ( const QString& ) ) ); + + connect( newprofilewizardfreeswanpagecontent->UseCustomEspCheckBox, SIGNAL( toggled(bool) ), this, SLOT( useEspToogled(bool) ) ); + connect( newprofilewizardfreeswanpagecontent->UseCustomIkeCheckBox, SIGNAL( toggled(bool) ), this, SLOT( useIkeToggled(bool) ) ); + connect( newprofilewizardfreeswanpagecontent->UseLeftNextHopCheckBox, SIGNAL( toggled(bool) ), this, SLOT( useLeftNextHopToggled(bool) ) ); + connect( newprofilewizardfreeswanpagecontent->UseRightNextHopCheckBox, SIGNAL( toggled(bool) ), this, SLOT( useRightNextHopToggled(bool) ) ); + connect (newprofilewizardfreeswanpagecontent->UseXauthCheckBox, SIGNAL(toggled(bool)),this, SLOT(useXauthFreeswanToggled(bool))); + + connect ( newprofilewizardfreeswanpagecontent->LocalIdTypeCombobox, SIGNAL ( highlighted ( const QString& ) ), this, SLOT ( localIDTypeIpsecToggled ( const QString& ) ) ); + connect ( newprofilewizardfreeswanpagecontent->RemoteIdTypeCombobox, SIGNAL ( highlighted ( const QString& ) ), this, SLOT ( remoteIDTypeIpsecToggled ( const QString& ) ) ); + + newprofilewizardfreeswanpage->sizeHint(); + + // openvpn + newprofilewizardopenvpnselectionpage = new QHBox ( 0 ); + // newprofilewizardopenvpnselectionpage->setSpacing(8); + QLabel *setupPixmapContent7 = new QLabel ( newprofilewizardopenvpnselectionpage ); + setupPixmapContent7->setPixmap ( *SetupPixmap ); + setupPixmapContent7->resize ( setupPixmapContent7->sizeHint() ); + newprofilewizardopenvpnselectionpagecontent = new NewProfileWizardOpenvpnSelection ( newprofilewizardopenvpnselectionpage ); + newprofilewizardopenvpnselectionpage->sizeHint(); + + newprofilewizardopenvpnauthpage = new QHBox ( 0 ); + // newprofilewizardopenvpnauthpage->setSpacing(8); + QLabel *setupPixmapContent71 = new QLabel ( newprofilewizardopenvpnauthpage ); + setupPixmapContent71->setPixmap ( *SetupPixmap ); + setupPixmapContent71->resize ( setupPixmapContent71->sizeHint() ); + newprofilewizardopenvpnauthpagecontent = new NewProfileWizardOpenvpnAuth ( newprofilewizardopenvpnauthpage ); + newprofilewizardopenvpnauthpage->sizeHint(); + connect ( newprofilewizardopenvpnauthpagecontent->AuthWithUsernameAndPasswordCheckBox, SIGNAL ( toggled ( bool ) ), this, SLOT ( authenticateWithUsernameAndPasswordToggled ( bool ) ) ); + connect ( newprofilewizardopenvpnauthpagecontent->UseAuthenticationAlgorithmCheckBox, SIGNAL ( toggled ( bool ) ), this, SLOT ( useAuthenticationAlgorithmToggled ( bool ) ) ); + + newprofilewizardopenvpnpage = new QHBox ( 0 ); + // newprofilewizardopenvpnpage->setSpacing(8); + QLabel *setupPixmapContent8 = new QLabel ( newprofilewizardopenvpnpage ); + setupPixmapContent8->setPixmap ( *SetupPixmap ); + setupPixmapContent8->resize ( setupPixmapContent8->sizeHint() ); + newprofilewizardopenvpnpagecontent = new NewProfileWizardOpenvpn ( newprofilewizardopenvpnpage ); + newprofilewizardopenvpnpage->sizeHint(); + newprofilewizardopenvpnpagecontent->TunnelDeviceTypeComboBox->insertItem ( "tun" ); + newprofilewizardopenvpnpagecontent->TunnelDeviceTypeComboBox->insertItem ( "tap" ); + newprofilewizardopenvpnpagecontent->NsCertTypeComboBox->insertItem ( "client" ); + newprofilewizardopenvpnpagecontent->NsCertTypeComboBox->insertItem ( "server" ); + newprofilewizardopenvpnpagecontent->NsCertTypeComboBox->setEnabled ( false ); + newprofilewizardopenvpnpagecontent->UserdefinedPortSpinBox->setEnabled ( false ); + + newprofilewizardopenvpnpagecontent->UseUserdefinedPortCheckBox->setChecked ( false ); + newprofilewizardopenvpnpagecontent->UseNsCertTypeCheckBox->setChecked ( false ); + newprofilewizardopenvpnpagecontent->UseTlsAuthCheckBox->setChecked ( false ); + newprofilewizardopenvpnpagecontent->UseTlsRemoteHostCheckBox->setChecked ( false ); + newprofilewizardopenvpnpagecontent->UseUserdefiniedCipherCheckBox->setChecked ( false ); + newprofilewizardopenvpnpagecontent->UseHttpProxyCheckBox->setChecked ( false ); + + connect ( newprofilewizardopenvpnpagecontent->UseUserdefinedPortCheckBox , SIGNAL ( toggled ( bool ) ), this, SLOT ( userdefinedOpenvpnPortToggeled ( bool ) ) ); + connect ( newprofilewizardopenvpnpagecontent->UseNsCertTypeCheckBox , SIGNAL ( toggled ( bool ) ), this, SLOT ( nsCertTypeOpenvpnToggled ( bool ) ) ); + connect ( newprofilewizardopenvpnpagecontent->UseUserdefinedPortCheckBox, SIGNAL ( toggled ( bool ) ), this, SLOT ( userdefinedOpenvpnPortToggeled ( bool ) ) ); + connect ( newprofilewizardopenvpnpagecontent->UseTlsAuthCheckBox, SIGNAL ( toggled ( bool ) ), this, SLOT ( useTlsAuthToggled ( bool ) ) ); + connect ( newprofilewizardopenvpnpagecontent->UseTlsRemoteHostCheckBox, SIGNAL ( toggled ( bool ) ), this, SLOT ( useTlsRemoteHostToggled ( bool ) ) ); + connect ( newprofilewizardopenvpnpagecontent->UseUserdefiniedCipherCheckBox, SIGNAL ( toggled ( bool ) ), this, SLOT ( useUserdefiniedCipherToggled ( bool ) ) ); + connect ( newprofilewizardopenvpnpagecontent->UseHttpProxyCheckBox, SIGNAL ( toggled ( bool ) ), this, SLOT ( useHttpProxyToggeled ( bool ) ) ); + + QStringList ciphers = Utils ( GlobalConfig ).getOpenvpnCiphers(); + QStringList digests = Utils ( GlobalConfig ).getOpenvpnDigests(); + + for ( QStringList::Iterator it = ciphers.begin(); it != ciphers.end(); ++it ) + { + newprofilewizardopenvpnpagecontent->UserdefiniedCipherComboBox->insertItem ( *it ); + } + + for ( QStringList::Iterator it = digests.begin(); it != digests.end(); ++it ) + { + newprofilewizardopenvpnauthpagecontent->UserdefiniedDigestComboBox->insertItem ( *it ); + } + + // pptp + newprofilewizardpptppage = new QHBox ( 0 ); + // newprofilewizardpptppage->setSpacing(8); + QLabel *setupPixmapContent9 = new QLabel ( newprofilewizardpptppage ); + setupPixmapContent9->setPixmap ( *SetupPixmap ); + setupPixmapContent9->resize ( setupPixmapContent9->sizeHint() ); + newprofilewizardpptppagecontent = new NewProfileWizardPptp ( newprofilewizardpptppage ); + newprofilewizardpptppage->sizeHint(); + newprofilewizardpptppagecontent->DnsServerLineedit->setEnabled ( false ); + newprofilewizardpptppagecontent->RequireMppeCheckbox->setChecked( profileData->getRequireMppe() ); + newprofilewizardpptppagecontent->Refuse128BitEncryptionCheckbox->setChecked( profileData->getRefuse128BitEncryption() ); + newprofilewizardpptppagecontent->Refuse40BitEncryptionCheckbox->setChecked( profileData->getRefuse40BitEncryption() ); + newprofilewizardpptppagecontent->UseNoMPPECompressionCheckbox->setChecked( profileData->getDisableMPPEComp() ); + newprofilewizardpptppagecontent->DnsServerCheckbox->setChecked( profileData->getUseDnsUpdate() ); + newprofilewizardpptppagecontent->DnsServerCheckbox->setChecked( profileData->getUseDnsServer() ); + newprofilewizardpptppagecontent->DnsServerLineedit->setText( profileData->getDnsServer() ); + newprofilewizardpptppagecontent->UseNoBsdCompCheckbox->setChecked( profileData->getUseNoBsdComp() ); + newprofilewizardpptppagecontent->UseNoDeflateCheckbox->setChecked( profileData->getUseNoDeflate() ); + newprofilewizardpptppagecontent->AllowStatefulModeCheckbox->setChecked( profileData->getAllowStatefulMode() ); + newprofilewizardpptppagecontent->UseNoIpDefaultCheckbox->setChecked( profileData->getUseNoIpDefault() ); + newprofilewizardpptppagecontent->DisableCcpCheckbox->setChecked( profileData->getDisableCcp() ); + newprofilewizardpptppagecontent->DisableHeaderCompressionCheckbox->setChecked(profileData->getDisableHeaderCompression()); + newprofilewizardpptppagecontent->DisableMagicNumberNegotiationCheckbox->setChecked(profileData->getDisableMagicNumberNegotiation()); + newprofilewizardpptppagecontent->DisableIpxCheckbox->setChecked(profileData->getDisableIpx()); + newprofilewizardpptppagecontent->DisableAdressControlCompressionCheckbox->setChecked(profileData->getDisableAdressControlCompression()); + newprofilewizardpptppagecontent->DisableProtocolFieldCompressionCheckbox->setChecked(profileData->getDisableProtocolFieldCompression()); + + + newprofilewizardpptppagecontent->AuthMethodComboBox->insertItem ( "chap" ); + newprofilewizardpptppagecontent->AuthMethodComboBox->insertItem ( "pap" ); + newprofilewizardpptppagecontent->AuthMethodComboBox->insertItem ( "mschap" ); + newprofilewizardpptppagecontent->AuthMethodComboBox->insertItem ( "mschap-v2" ); + + connect( newprofilewizardpptppagecontent->DnsServerCheckbox, SIGNAL( toggled(bool) ), this, SLOT( useDnsServerToggled(bool) ) ); + connect( newprofilewizardpptppagecontent->UseSearchDomainInResolvConfCheckbox, SIGNAL( toggled(bool) ), this, SLOT( useSearchDomainInResolvConfToggled(bool) ) ); + connect( newprofilewizardpptppagecontent->UseDomainInResolvConfCheckbox, SIGNAL( toggled(bool) ), this, SLOT( useDomainInResolvConfToggled(bool) ) ); + + // vtun + newprofilewizardvtunpage = new QHBox ( 0 ); + // newprofilewizardvtunpage->setSpacing(8); + QLabel *setupPixmapContent19 = new QLabel ( newprofilewizardvtunpage ); + setupPixmapContent19->setPixmap ( *SetupPixmap ); + setupPixmapContent19->resize ( setupPixmapContent19->sizeHint() ); + newprofilewizardvtunpagecontent = new ProfileVtunOptions ( newprofilewizardvtunpage ); + newprofilewizardvtunpage->sizeHint(); + connect ( newprofilewizardvtunpagecontent->PortCheckbox, SIGNAL ( toggled ( bool ) ), this, SLOT ( usePortToggled ( bool ) ) ); + + // ssh + newprofilewizardsshpage = new QHBox ( 0 ); + // newprofilewizardsshpage->setSpacing(8); + QLabel *setupPixmapContent191 = new QLabel ( newprofilewizardsshpage ); + setupPixmapContent191->setPixmap ( *SetupPixmap ); + setupPixmapContent191->resize ( setupPixmapContent191->sizeHint() ); + newprofilewizardsshpagecontent = new ProfileSshOptions ( newprofilewizardsshpage ); + newprofilewizardsshpage->sizeHint(); + + QString Home= QString(getenv("HOME")); + if (!Home.isEmpty()) + { + QDir dir( Home+"/.ssh" ); + QStringList KeyFiles = dir.entryList( "*" ); + + //if (GlobalConfig->KvpncDebugLevel > 2) + //{ + // GlobalConfig->appendLogEntry(i18n("SSH files: %1").arg(KeyFiles.join(",")),GlobalConfig->debug); + //} + + if (KeyFiles.size() > 1) + { + for ( QStringList::Iterator it = KeyFiles.begin(); it != KeyFiles.end(); ++it ) + { + QString item = QString(*it); + if (GlobalConfig->KvpncDebugLevel > 2) + { + //GlobalConfig->appendLogEntry(i18n("processing entry: %1").arg(item),GlobalConfig->debug); + } + if (!item.contains (".pub", false) && !item.contains ("authorized_keys", false) && !item.contains ("known_hosts", false) && !item.contains (".", false) && !item.contains ("..", false) && !item.contains ("config", false) ) + { + if (GlobalConfig->KvpncDebugLevel > 2) + { + GlobalConfig->appendLogEntry(i18n("SSH key found: %1").arg(*it),GlobalConfig->debug); + } + newprofilewizardsshpagecontent->SshKeyComboBox->insertItem(*it); + } + } + } + } + + + newprofilewizardauthselectionpage = new QHBox ( 0 ); + // newprofilewizardauthselectionpage->setSpacing(8); + QLabel *setupPixmapContent81 = new QLabel ( newprofilewizardauthselectionpage ); + setupPixmapContent81->setPixmap ( *SetupPixmap ); + setupPixmapContent81->resize ( setupPixmapContent81->sizeHint() ); + newprofilewizardauthselectioncontent = new NewProfileWizardAuthSelection ( newprofilewizardauthselectionpage ); + newprofilewizardauthselectionpage->sizeHint(); + newprofilewizardauthselectioncontent->CertificateRadioButton->setChecked ( true ); + newprofilewizardauthselectioncontent->HybridRadioButton->hide (); + + + // virtual ip + newprofilewizardvirtualipaddresspage = new QHBox ( 0 ); + QLabel *setupPixmapContent_virtualip = new QLabel ( newprofilewizardvirtualipaddresspage ); + setupPixmapContent_virtualip->setPixmap ( *SetupPixmap ); + setupPixmapContent_virtualip->resize ( setupPixmapContent_virtualip->sizeHint() ); + profilenetworkvirtualipoptionscontent = new ProfileNetworkVirtualIpOptions ( newprofilewizardvirtualipaddresspage ); + newprofilewizardvirtualipaddresspage->sizeHint(); + insertPage ( newprofilewizardvirtualipaddresspage, "" + i18n ( "Virtual IP address options" ) + "",-1 ); + connect ( profilenetworkvirtualipoptionscontent->UseVirtualIPCheckBox, SIGNAL ( toggled ( bool ) ), this, SLOT ( useVirtualIpAddressToggled ( bool ) ) ); + + // psk + newprofilewizardpskpage = new QHBox ( 0 ); + // newprofilewizardpskpage->setSpacing(8); + QLabel *setupPixmapContent72 = new QLabel ( newprofilewizardpskpage ); + setupPixmapContent72->setPixmap ( *SetupPixmap ); + setupPixmapContent72->resize ( setupPixmapContent72->sizeHint() ); + newprofilewizardpskcontent = new NewProfileWizardPsk ( newprofilewizardpskpage ); + newprofilewizardpskpage->sizeHint(); + + connect ( newprofilewizardpskcontent->PskInFileCheckBox , SIGNAL ( toggled ( bool ) ), this, SLOT ( pskIsInFileToggled ( bool ) ) ); + connect ( newprofilewizardpskcontent->PSKLineEdit , SIGNAL ( textChanged ( const QString & ) ), this, SLOT ( pskInputToggled ( const QString& ) ) ); + + newprofilewizardp12certselectionpage = new QHBox ( 0 ); + // newprofilewizardp12certselectionpage->setSpacing(8); + QLabel *setupPixmapContent74 = new QLabel ( newprofilewizardp12certselectionpage ); + setupPixmapContent74->setPixmap ( *SetupPixmap ); + setupPixmapContent74->resize ( setupPixmapContent74->sizeHint() ); + newprofilewizardp12certselectioncontent = new NewProfileWizardP12CertSelection ( newprofilewizardp12certselectionpage ); + newprofilewizardp12certselectionpage->sizeHint(); + connect ( newprofilewizardp12certselectioncontent->UseSmartcardCheckBox, SIGNAL ( toggled ( bool ) ), this, SLOT ( useSmartcardOnCertFormateToggled ( bool ) ) ); + + // cert + newprofilewizardcertpage = new QHBox ( 0 ); + // newprofilewizardcertpage->setSpacing(8); + QLabel *setupPixmapContent73 = new QLabel ( newprofilewizardcertpage ); + setupPixmapContent73->setPixmap ( *SetupPixmap ); + setupPixmapContent73->resize ( setupPixmapContent73->sizeHint() ); + newprofilewizardcertcontent = new NewProfileWizardCert ( newprofilewizardcertpage ); + newprofilewizardcertpage->sizeHint(); + connect ( newprofilewizardcertcontent->UseSpecialServerCertificateCheckBox , SIGNAL ( toggled ( bool ) ), this, SLOT ( useSpecialServerCertificateToggled ( bool ) ) ); + connect ( newprofilewizardcertcontent->UseSmartcardCheckBox, SIGNAL ( toggled ( bool ) ), this, SLOT ( useSmartcardToggled ( bool ) ) ); + connect ( newprofilewizardcertcontent->UsePkcs11ProvidersCheckBox, SIGNAL ( toggled ( bool ) ), this, SLOT ( usePkcs11ProvidersToggled ( bool ) ) ); + connect ( newprofilewizardcertcontent->DetectPkcs11SlotsPushButton, SIGNAL ( clicked() ), this, SLOT ( detectPkcs11Slots() ) ); + connect ( newprofilewizardcertcontent->DetectPkcs11IdPushButton, SIGNAL ( clicked() ), this, SLOT ( detectPkcs11Ids() ) ); + newprofilewizardcertcontent->Pkcs11SlotTypeComboBox->setEnabled ( false ); + newprofilewizardcertcontent->Pkcs11SlotTypeLabel->setEnabled ( false ); + newprofilewizardcertcontent->Pkcs11ProvidersURLRequester->setURL ( QString ( "/usr/local/lib/libetpkcs11.so" ) ); + + + // user + newprofilewizarduserpage = new QHBox ( 0 ); + // newprofilewizarduserpage->setSpacing(8); + QLabel *setupPixmapContent75 = new QLabel ( newprofilewizarduserpage ); + setupPixmapContent75->setPixmap ( *SetupPixmap ); + setupPixmapContent75->resize ( setupPixmapContent75->sizeHint() ); + newprofilewizarduserpagecontent = new NewProfileWizardUser ( newprofilewizarduserpage ); + newprofilewizarduserpage->sizeHint(); + + connect ( newprofilewizarduserpagecontent->PasswordEdit , SIGNAL ( textChanged ( const QString& ) ), this, SLOT ( userpassToggled ( const QString& ) ) ); + connect ( newprofilewizarduserpagecontent->UsernameLineEdit , SIGNAL ( textChanged ( const QString& ) ), this, SLOT ( usernameToggled ( const QString& ) ) ); + connect ( newprofilewizarduserpagecontent->NtDomainNameCheckbox, SIGNAL ( toggled ( bool ) ), this, SLOT ( domainNameToggled ( bool ) ) ); + newprofilewizarduserpagecontent ->NtDomainNameCheckbox->setEnabled ( true ); + newprofilewizarduserpagecontent ->NtDomainNameCheckbox->hide(); + newprofilewizarduserpagecontent ->NtDomainNameLineedit->hide(); + + + // network + newprofilewizardnetworkpage = new QHBox ( 0 ); + // newprofilewizardnetworkpage->setSpacing(8); + QLabel *setupPixmapContent76 = new QLabel ( newprofilewizardnetworkpage ); + setupPixmapContent76->setPixmap ( *SetupPixmap ); + setupPixmapContent76->resize ( setupPixmapContent76->sizeHint() ); + newprofilewizardnetworkcontent = new NewProfileWizardNetwork ( newprofilewizardnetworkpage ); + newprofilewizardnetworkpage->sizeHint(); + newprofilewizardnetworkcontent->NetworkDeviceComboBox->insertItem ( "default" ); + + NetworkInterface iface ( GlobalConfig, GlobalConfig->appPointer ); + QStringList list = iface.getAllNetworkInterfaces(); + for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) + newprofilewizardnetworkcontent->NetworkDeviceComboBox->insertItem ( QString ( *it ) ); + + newprofilewizardnetworkcontent->MtuSpinbox->hide(); + newprofilewizardnetworkcontent->MtuCheckbox->hide(); + newprofilewizardnetworkcontent->MruSpinbox->hide(); + newprofilewizardnetworkcontent->MruCheckbox->hide(); + + newprofilewizardnetworkcontent->TunnelDeviceTypeLabel->hide(); + newprofilewizardnetworkcontent->TunnelDeviceTypeComboBox->hide(); + + newprofilewizardnetworkcontent->TunnelDeviceTypeComboBox->insertItem("tun"); + newprofilewizardnetworkcontent->TunnelDeviceTypeComboBox->insertItem("tap"); + + connect ( newprofilewizardnetworkcontent->MtuCheckbox, SIGNAL ( toggled ( bool ) ), this, SLOT ( mtuToggled ( bool ) ) ); + connect ( newprofilewizardnetworkcontent->MtuCheckbox, SIGNAL ( toggled ( bool ) ), this, SLOT ( mtuToggled ( bool ) ) ); + connect ( newprofilewizardnetworkcontent->UseRemoteNetworkCheckBox, SIGNAL ( toggled ( bool ) ) , this, SLOT( useRemoteNetworkToggled (bool ))); + connect ( newprofilewizardnetworkcontent->TunnelDeviceTypeComboBox, SIGNAL(activated ( const QString & )),this, SLOT(tunnelDeviceTypeChanged(const QString& ))); + + // network routes + newprofilewizardnetworkroutepage = new QHBox ( 0 ); + // newprofilewizardnetworkroutepage->setSpacing(8); + QLabel *setupPixmapContent761 = new QLabel ( newprofilewizardnetworkroutepage ); + setupPixmapContent761->setPixmap ( *SetupPixmap ); + setupPixmapContent761->resize ( setupPixmapContent761->sizeHint() ); + newprofilewizardnetworkroutecontent = new ProfileNetworkRouteOptions ( newprofilewizardnetworkroutepage ); + newprofilewizardnetworkroutepage->sizeHint(); + + connect(newprofilewizardnetworkroutecontent->DefaultRouteComboBox, SIGNAL(activated(const QString&)), this, SLOT(defaultRouteToggled(const QString&))); + + newprofilewizardnetworkroutecontent->DefaultRouteComboBox->setCurrentItem(1); + + + // nat + newprofilewizardnatpage = new QHBox ( 0 ); + // newprofilewizardnatpage->setSpacing(8); + QLabel *setupPixmapContent77 = new QLabel ( newprofilewizardnatpage ); + setupPixmapContent77->setPixmap ( *SetupPixmap ); + setupPixmapContent77->resize ( setupPixmapContent77->sizeHint() ); + newprofilewizardnatcontent = new NewProfileWizardNat ( newprofilewizardnatpage ); + newprofilewizardnatpage->sizeHint(); + newprofilewizardnatcontent->UseUdpCheckbox->setChecked ( true ); + newprofilewizardnatcontent->UseNatCheckbox->setChecked ( true ); + connect ( newprofilewizardnatcontent->UseNatCheckbox, SIGNAL ( toggled ( bool ) ), this, SLOT ( useNatToggled ( bool ) ) ); + connect ( newprofilewizardnatcontent->UdpPortCheckbox, SIGNAL ( toggled ( bool ) ), this, SLOT ( udpPortToggled ( bool ) ) ); + useNatToggled(true); + + // connectionstatuscheck + newprofilewizardconnectionstatuscheckpage = new QHBox ( 0 ); + // newprofilewizardconnectionstatuscheckpage->setSpacing(8); + QLabel *setupPixmapContent79 = new QLabel ( newprofilewizardconnectionstatuscheckpage ); + setupPixmapContent79->setPixmap ( *SetupPixmap ); + setupPixmapContent79->resize ( setupPixmapContent79->sizeHint() ); + newprofilewizardconnectionstatuscheckcontent = new NewProfileWizardConnectionStatusCheck ( newprofilewizardconnectionstatuscheckpage ); + newprofilewizardconnectionstatuscheckpage->sizeHint(); + insertPage ( newprofilewizardconnectionstatuscheckpage, "" + i18n ( "Connection status check" ) + "", -1 ); + connect ( newprofilewizardconnectionstatuscheckcontent->PingUserdefiniedAddressCheckBox, SIGNAL ( toggled ( bool ) ), this, SLOT ( pingIpAfterConnectToggled ( bool ) ) ); + connect ( newprofilewizardconnectionstatuscheckcontent->UseConnectionStatusCheckCheckBox, SIGNAL ( toggled ( bool ) ), this, SLOT ( connectionStatusCheckToggled ( bool ) ) ); + + // connectoptions + newprofilewizardconnectoptionspage = new QHBox ( 0 ); + + // newprofilewizardconnectoptionspage->setSpacing(8); + QLabel *setupPixmapContent80 = new QLabel ( newprofilewizardconnectoptionspage ); + setupPixmapContent80->setPixmap ( *SetupPixmap ); + setupPixmapContent80->resize ( setupPixmapContent80->sizeHint() ); + newprofilewizardconnectoptionscontent = new NewProfileWizardConnectOptions ( newprofilewizardconnectoptionspage ); + newprofilewizardconnectoptionspage->sizeHint(); + newprofilewizardconnectoptionscontent->DoAutoConnectCheckBox->hide(); //TODO later + newprofilewizardconnectoptionscontent->AutoConnectProfileComboBox->hide(); //TODO_ later + insertPage ( newprofilewizardconnectoptionspage, "" + i18n ( "Connect options" ) + "", -1 ); + + // general + newprofilewizardgeneralpage = new QHBox ( 0 ); + // newprofilewizardgeneralpage->setSpacing(8); + QLabel *setupPixmapContent78 = new QLabel ( newprofilewizardgeneralpage ); + setupPixmapContent78->setPixmap ( *SetupPixmap ); + setupPixmapContent78->resize ( setupPixmapContent78->sizeHint() ); + newprofilewizardgeneralpagecontent = new NewProfileWizardGeneral ( newprofilewizardgeneralpage ); + newprofilewizardgeneralpage->sizeHint(); + insertPage ( newprofilewizardgeneralpage, "" + i18n ( "General settings" ) + "", -1 ); + + // setup end page + endpage = new QHBox ( 0 ); + // endpage->setSpacing(8); + QLabel *setupPixmapContent11 = new QLabel ( endpage ); + setupPixmapContent11->setPixmap ( *SetupPixmapFinal ); + setupPixmapContent11->resize ( setupPixmapContent11->sizeHint() ); + QLabel *endpagecontent = new QLabel ( endpage ); + endpagecontent->setMargin ( 11 ); + endpagecontent->setText ( i18n ( "Now you have completed all steps for creating a new profile.\nClick \"Finish\" to continue." ) ); + endpagecontent->setMaximumSize ( endpagecontent->sizeHint() ); + endpage->sizeHint(); + insertPage ( endpage, "" + i18n ( "Finish" ) + "", -1 ); // last page +} + +void NewProfileWizard::next () +{ + // called at each finish of a page + bool ok = true; + QString msg = i18n ( "Please fill in all fields!" ); + + if ( currentpage == page1 ) + { + // nothing here + } + else if ( currentpage == newprofilewizardgeneralpage ) + { + msg = i18n ( "These fields must be filled in:\n" ); + if ( newprofilewizardgeneralpagecontent->NameLineEdit->text().isEmpty() ) + { + msg += "- " + i18n ( "Name" ) + "\n"; + GlobalConfig->appendLogEntry ( i18n ( "Name is empty!" ), GlobalConfig->error ); + } + else + { + QString Name = newprofilewizardgeneralpagecontent->NameLineEdit->text(); + + + bool nameOk = true; + if ( Name.contains ( ' ' ) ) + { + KMessageBox::error ( this, i18n ( "Profile name can not contain spaces!" ), i18n ( "Spaces Not Allowed" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Profile name can not contain spaces!" ) , GlobalConfig->error ); + msg += "- " + i18n ( "Name" ) + "\n"; + nameOk = FALSE; + ok = false; + } + + if ( Name.isEmpty() ) + { + KMessageBox::error ( this, i18n ( "Profile name can not be empty!" ), i18n ( "No Name Entered" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Profile name can not be empty!" ) , GlobalConfig->error ); + msg += "- " + i18n ( "Name" ) + "\n"; + nameOk = FALSE; + ok = false; + } + + VpnAccountData * it; + + while ( nameOk == false ) + { + for ( it = GlobalConfig->AccountList->first(); it; it = GlobalConfig->AccountList->next() ) + { + if ( it->getName() == Name ) + { + //account->setName( QString( account->getName() + "_2" ) ); + // KMessageBox::information ( this, i18n( "Profile name exists!\n It will be renamed to \"%1\"." ).arg( account->getName() ), i18n( "Name exist, renamed" ) ); + KMessageBox::error ( this, i18n ( "Profile name exists!" ), i18n ( "Name Exists" ) ); + + QString newName = KInputDialog::getText ( i18n ( "New Name" ), i18n ( "New name for profile:" ), QString ( Name += "_2" ), &ok ); + + if ( !Name.isEmpty() ) + { + nameOk = true; + break; + } + } + nameOk = true; + } + nameOk = true; + } + + if ( nameOk ) + { + profileData->setName ( Name ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Profile name: %1" ).arg ( profileData->getName() ), KVpncConfig::debug ); + + newProfileCreated = TRUE; + } + else + { + return ; + } + } + + if ( newprofilewizardgeneralpagecontent->gatewayLineEdit->text().isEmpty() ) + { + ok = false; + msg += "- " + i18n ( "Gateway" ) + "\n"; + GlobalConfig->appendLogEntry ( i18n ( "Gateway is empty!" ), GlobalConfig->error ); + } + else + { + profileData->setGateway ( newprofilewizardgeneralpagecontent->gatewayLineEdit->text() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Gateway: %1" ).arg ( newprofilewizardgeneralpagecontent->gatewayLineEdit->text() ), KVpncConfig::debug ); + } + profileData->setDescription ( newprofilewizardgeneralpagecontent->DescriptionLineEdit->text() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Description: %1" ).arg ( newprofilewizardgeneralpagecontent->DescriptionLineEdit->text() ), KVpncConfig::debug ); + } + else if ( currentpage == newprofilewizardtypeselectionpage ) + { + if ( newprofilewizardtypeselectionpagecontent->CiscoRadioButton->isChecked() ) + { + profileData->setConnectionType ( VpnAccountData::cisco ); + removePage ( newprofilewizardcertpage ); + removePage ( newprofilewizardpskpage ); + removePage ( newprofilewizardp12certselectionpage ); + removePage ( newprofilewizardfreeswanpage ); + removePage ( newprofilewizardfreeswanselectionpage ); + removePage ( newprofilewizardracoonpage ); + removePage ( newprofilewizardopenvpnpage ); + removePage ( newprofilewizardopenvpnselectionpage ); + removePage ( newprofilewizardpptppage ); + removePage ( newprofilewizardvirtualipaddresspage ); + newprofilewizardnetworkcontent->RemoteNetworkGroupBox->hide(); +// newprofilewizardnetworkcontent->LabelRemoteNetwork->hide(); +// newprofilewizardnetworkcontent->RemoteNetMaskComboBox->hide(); +// newprofilewizardnetworkcontent->RemoteNetAddrLineEdit->hide(); +// newprofilewizardnetworkcontent->RemoteNetDividetextLabel->hide(); +// newprofilewizardp12certselectioncontent->UseSmartcardCheckBox->hide(); + + newprofilewizarduserpagecontent ->NtDomainNameCheckbox->show(); + newprofilewizarduserpagecontent ->NtDomainNameLineedit->show(); + + insertPage ( newprofilewizardciscoselectionpage, "" + i18n ( "Cisco selection" ) + "", indexOf ( currentpage ) + 1 ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Selected type: %1" ).arg ( "Cisco (free)" ), KVpncConfig::debug ); + } + else if ( newprofilewizardtypeselectionpagecontent->CiscoVpncRadioButton->isChecked() ) + { + profileData->setConnectionType ( VpnAccountData::ciscoorig ); +// removePage ( newprofilewizardcertpage ); + removePage ( newprofilewizardpskpage ); + removePage ( newprofilewizardp12certselectionpage ); + removePage ( newprofilewizardfreeswanpage ); + removePage ( newprofilewizardfreeswanselectionpage ); + removePage ( newprofilewizardracoonpage ); + removePage ( newprofilewizardopenvpnpage ); + removePage ( newprofilewizardopenvpnselectionpage ); + removePage ( newprofilewizardpptppage ); + removePage ( newprofilewizardvirtualipaddresspage ); + newprofilewizardnetworkcontent->LabelRemoteNetwork->hide(); + newprofilewizardnetworkcontent->RemoteNetMaskComboBox->hide(); + newprofilewizardnetworkcontent->RemoteNetAddrLineEdit->hide(); + newprofilewizardnetworkcontent->RemoteNetDividetextLabel->hide(); + newprofilewizardp12certselectioncontent->UseSmartcardCheckBox->hide(); + + newprofilewizarduserpagecontent ->NtDomainNameCheckbox->show(); + newprofilewizarduserpagecontent ->NtDomainNameLineedit->show(); + + insertPage ( newprofilewizardciscoselectionpage, "" + i18n ( "Cisco selection" ) + "", indexOf ( currentpage ) + 1 ); + + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Selected type: %1" ).arg ( "Cisco (propritary)" ), KVpncConfig::debug ); + } + else if ( newprofilewizardtypeselectionpagecontent->FreeswanRadioButton->isChecked() ) + { + profileData->setConnectionType ( VpnAccountData::freeswan ); + removePage ( newprofilewizardciscoselectionpage ); + removePage ( newprofilewizardciscomanuallypage ); + removePage ( newprofilewizardopenvpnpage ); + removePage ( newprofilewizardopenvpnselectionpage ); + removePage ( newprofilewizardpptppage ); + removePage ( newprofilewizardvirtualipaddresspage ); + + insertPage ( newprofilewizardfreeswanpage, "" + i18n ( "FreeSWAN/OpenSWAN settings" ) + "", indexOf ( currentpage ) + 1 ); + + newprofilewizardfreeswanpagecontent->ExchangeModeComboBox->insertItem ( "main", 0 ); + newprofilewizardfreeswanpagecontent->ExchangeModeComboBox->insertItem ( "aggressive", 1 ); + newprofilewizardfreeswanpagecontent->ExchangeModeComboBox->setCurrentItem ( 0 ); // main + newprofilewizardfreeswanpagecontent->ExchangeModeComboBox->setEnabled ( true ); + + newprofilewizardfreeswanpagecontent->IpsecVpnModeCombobox->setCurrentItem(1); // tunnel + + newprofilewizardcertcontent->certpathURLRequester->setURL ( "/etc/ipsec.d/cacerts" ); + newprofilewizardcertcontent->Pkcs11IdTypeComboBox->setEnabled ( false ); + newprofilewizardcertcontent->Pkcs11IdTypeComboBox->setCurrentText ( i18n ( "ID" ) ); + +// profileData->setIkeGroup ( "modp2048" ); // default for windows?! +// profileData->setAuthenticationAlgorithm ( "hmac_md5" ); // default for windows?! +// profileData->setHashAlgo ( "sha1" ); // default for windows?! + + +// newprofilewizardfreeswanpagecontent->InfoLabel->setText ( i18n ( "Please enter %1 specific settings:" ).arg ( "FreeS/WAN/Openswan/strongSwan" ) ); + insertPage ( newprofilewizardfreeswanselectionpage, "" + i18n ( "IPSec selection" ) + "", indexOf ( currentpage ) + 1 ); + + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Selected type: %1" ).arg ( "FreeS/WAN/Openswan/strongSwan" ), KVpncConfig::debug ); + } + else if ( newprofilewizardtypeselectionpagecontent->RacoonRadioButton->isChecked() ) + { + profileData->setConnectionType ( VpnAccountData::racoon ); + removePage ( newprofilewizardciscoselectionpage ); + removePage ( newprofilewizardciscomanuallypage ); + removePage ( newprofilewizardfreeswanpage ); + removePage ( newprofilewizardfreeswanselectionpage ); + removePage ( newprofilewizardopenvpnpage ); + removePage ( newprofilewizardopenvpnselectionpage ); + removePage ( newprofilewizardpptppage ); + removePage ( newprofilewizardvirtualipaddresspage ); + + +// profileData->setIkeGroup ( "modp2048" ); // default for windows?! +// profileData->setHashAlgo ( "sha1" ); // default for windows?! +// profileData->setAuthenticationAlgorithm ( "hmac_md5" ); + + profileData->setUseMailAddressAsIdentifier ( false ); + +// newprofilewizardracoonpagecontent->DHGroupComboBox->setCurrentText ( profileData->getIkeGroup() ); +// newprofilewizardracoonpagecontent->AuthenticationAlgorithmComboBox->setCurrentText ( profileData->getAuthenticationAlgorithm() ); +// newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->setCurrentText ( profileData->getEncryptionAlgorithm() ); + + Utils::IpsecAlgos KernelCrypto = Utils ( GlobalConfig ).getKernelCrypto(); + + // man racoon.conf + newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->insertItem("des" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->insertItem("3des" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->insertItem("blowfish" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->insertItem("cast128" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->insertItem("aes" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->insertItem("camellia" ); + + newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->setCurrentText("3des"); + + // man racoon.conf + newprofilewizardracoonpagecontent->HashAlgoComboBox->insertItem( "md5" ); + newprofilewizardracoonpagecontent->HashAlgoComboBox->insertItem( "sha1" ); + newprofilewizardracoonpagecontent->HashAlgoComboBox->insertItem( "sha256" ); + newprofilewizardracoonpagecontent->HashAlgoComboBox->insertItem( "sha384" ); + newprofilewizardracoonpagecontent->HashAlgoComboBox->insertItem( "sha512" ); + + newprofilewizardracoonpagecontent->HashAlgoComboBox->setCurrentText("md5"); + + // vpn mit linux book + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem("des" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem("3des" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem("des_iv64" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem("des_iv32" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem("rc5" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem("rc4" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem("idea" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem("3idea" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem("cast128" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem("blowfish" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem("null_enc" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem("twofish" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem("rijndael" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem("aes" ); + + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->setCurrentText("3des"); + + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem( "des" ); + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem( "3des" ); + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem( "des_iv64" ); + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem( "des_iv32" ); + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem( "hmac_md5" ); + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem( "hmac_sha1" ); + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem( "hmac_sha256" ); + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem( "hmac_sha384" ); + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem( "hmac_sha512" ); + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem( "non_auth" ); + + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->setCurrentText( "hmac_md5" ); + + for ( QStringList::Iterator it = KernelCrypto.IpsecEspEncryptionAlgorithms.begin(); it != KernelCrypto.IpsecEspEncryptionAlgorithms.end(); ++it ) + { + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem ( *it ); + } + + newprofilewizardcertcontent->UseSmartcardCheckBox->hide(); + newprofilewizardcertcontent->SmartcardGroupBox->hide(); + newprofilewizardp12certselectioncontent->UseSmartcardCheckBox->hide(); + + + insertPage ( newprofilewizardauthselectionpage, i18n ( "Authentication settings" ), indexOf ( currentpage ) + 1 ); + insertPage ( newprofilewizardracoonpage, "" + i18n ( "Racoon settings" ) + "", indexOf ( currentpage ) + 2 ); + + newprofilewizardauthselectioncontent->HybridRadioButton->show(); + + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Selected type: %1" ).arg ( "Racoon" ), KVpncConfig::debug ); + } + else if ( newprofilewizardtypeselectionpagecontent->L2tpRacoonRadioButton->isChecked() ) + { + profileData->setConnectionType ( VpnAccountData::l2tpd_racoon ); + removePage ( newprofilewizardciscoselectionpage ); + removePage ( newprofilewizardciscomanuallypage ); + removePage ( newprofilewizardfreeswanpage ); + removePage ( newprofilewizardfreeswanselectionpage ); + removePage ( newprofilewizardopenvpnpage ); + removePage ( newprofilewizardopenvpnselectionpage ); + removePage ( newprofilewizardpptppage ); + removePage ( newprofilewizardnetworkpage ); + removePage ( newprofilewizardvirtualipaddresspage ); + + profileData->setUseMailAddressAsIdentifier ( false ); + +// profileData->setIkeGroup ( "modp2048" ); // default for windows?! +// profileData->setHashAlgo ( "sha1" ); // default for windows?! +// profileData->setAuthenticationAlgorithm ( "hmac_md5" ); // default for windows? + + Utils::IpsecAlgos KernelCrypto = Utils ( GlobalConfig ).getKernelCrypto(); + + //FIXME why this is not in kernel crypto list??? +// newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->insertItem ( "3des" ); + + newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->insertItem("des" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->insertItem("des_iv64" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->insertItem("des_iv32" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->insertItem("rc5" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->insertItem("rc4" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->insertItem("idea" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->insertItem("3idea" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->insertItem("cast128" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->insertItem("blowfish" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->insertItem("null_enc" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->insertItem("twofish" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->insertItem("rijndael" ); + newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->insertItem("aes" ); + + newprofilewizardracoonpagecontent->HashAlgoComboBox->insertItem( "md5" ); + newprofilewizardracoonpagecontent->HashAlgoComboBox->insertItem( "sha1" ); + newprofilewizardracoonpagecontent->HashAlgoComboBox->insertItem( "sha256" ); + newprofilewizardracoonpagecontent->HashAlgoComboBox->insertItem( "sha384" ); + newprofilewizardracoonpagecontent->HashAlgoComboBox->insertItem( "sha512" ); + + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem( "des" ); + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem( "3des" ); + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem( "des_iv64" ); + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem( "des_iv32" ); + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem( "hmac_md5" ); + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem( "hmac_sha1" ); + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem( "hmac_sha256" ); + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem( "hmac_sha384" ); + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem( "hmac_sha512" ); + newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem( "non_auth" ); + +// for ( QStringList::Iterator it = KernelCrypto.IpsecIkeEncryptionAlgorithms.begin(); it != KernelCrypto.IpsecIkeEncryptionAlgorithms.end(); ++it ) +// { +// newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->insertItem ( *it ); +// } +// +// for ( QStringList::Iterator it = KernelCrypto.IpsecIkeHashAlgorithms.begin(); it != KernelCrypto.IpsecIkeHashAlgorithms.end(); ++it ) +// { +// newprofilewizardracoonpagecontent->HashAlgoComboBox->insertItem ( *it ); +// } + + for ( QStringList::Iterator it = KernelCrypto.IpsecEspEncryptionAlgorithms.begin(); it != KernelCrypto.IpsecEspEncryptionAlgorithms.end(); ++it ) + { + newprofilewizardracoonpagecontent->EncryptionAlgorithm2ComboBox->insertItem ( *it ); + } + +// for ( QStringList::Iterator it = KernelCrypto.IpsecEspAuthenticationAlgorithms.begin(); it != KernelCrypto.IpsecEspAuthenticationAlgorithms.end(); ++it ) +// { +// newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->insertItem ( *it ); +// } + insertPage ( newprofilewizardracoonpage, "" + i18n ( "Racoon settings" ) + "", indexOf ( currentpage ) + 1 ); + insertPage ( newprofilewizardauthselectionpage, i18n ( "Authentication settings" ), indexOf ( currentpage ) + 2 ); + insertPage ( newprofilewizarduserpage, "" + i18n ( "User settings" ) + "", indexOf ( currentpage ) + 3 ); + + newprofilewizardnetworkcontent->LabelRemoteNetwork->hide(); + newprofilewizardnetworkcontent->RemoteNetMaskComboBox->hide(); + newprofilewizardnetworkcontent->RemoteNetAddrLineEdit->hide(); + newprofilewizardnetworkcontent->RemoteNetDividetextLabel->hide(); + newprofilewizarduserpagecontent ->NtDomainNameCheckbox->show(); + newprofilewizarduserpagecontent ->NtDomainNameLineedit->show(); + newprofilewizardcertcontent->UseSmartcardCheckBox->hide(); + newprofilewizardcertcontent->SmartcardGroupBox->hide(); + newprofilewizardp12certselectioncontent->UseSmartcardCheckBox->hide(); + newprofilewizardcertcontent->certpathURLRequester->setURL ( "/etc/racoon/" ); + + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Selected type: %1" ).arg ( "L2TP (racoon)" ), KVpncConfig::debug ); + } + else if ( newprofilewizardtypeselectionpagecontent->L2tpFreeswanRadioButton->isChecked() ) + { + profileData->setConnectionType ( VpnAccountData::l2tpd_freeswan ); + removePage ( newprofilewizardciscoselectionpage ); + removePage ( newprofilewizardciscomanuallypage ); + removePage ( newprofilewizardopenvpnpage ); + removePage ( newprofilewizardopenvpnselectionpage ); + removePage ( newprofilewizardpptppage ); + removePage ( newprofilewizardnetworkpage ); + removePage ( newprofilewizardvirtualipaddresspage ); + + profileData->setUseMailAddressAsIdentifier ( false ); + + newprofilewizardfreeswanpagecontent->ExchangeModeComboBox->insertItem ( "main", 0 ); + newprofilewizardfreeswanpagecontent->ExchangeModeComboBox->insertItem ( "aggressive", 1 ); + newprofilewizardfreeswanpagecontent->ExchangeModeComboBox->setCurrentItem ( 0 ); // main + newprofilewizardfreeswanpagecontent->ExchangeModeComboBox->setEnabled ( true ); + newprofilewizardfreeswanpagecontent->IpsecVpnModeCombobox->setCurrentItem(1); // transport + newprofilewizardfreeswanpagecontent->IpsecVpnModeCombobox->setEnabled(false); + + + newprofilewizarduserpagecontent ->NtDomainNameCheckbox->show(); + newprofilewizarduserpagecontent ->NtDomainNameLineedit->show(); + newprofilewizardcertcontent->Pkcs11IdTypeComboBox->setEnabled ( false ); + newprofilewizardcertcontent->Pkcs11IdTypeComboBox->setCurrentText ( i18n ( "ID" ) ); + newprofilewizardauthselectioncontent->CertificateRadioButton->setText ( i18n ( "&Certificate/Smartcard" ) ); + newprofilewizardcertcontent->certpathURLRequester->setURL ( "/etc/ipsec.d/cacerts" ); + +// newprofilewizardfreeswanpagecontent->InfoLabel->setText ( i18n ( "Please enter %1 specific settings:" ).arg ( "FreeS/WAN/Openswan/strongSwan" ) ); + + insertPage ( newprofilewizardfreeswanselectionpage, "" + i18n ( "IPSec selection" ) + "", indexOf ( currentpage ) + 1 ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Selected type: %1" ).arg ( "L2TP (OpenS/WAN)" ), KVpncConfig::debug ); + } + else if ( newprofilewizardtypeselectionpagecontent->OpenvpnRadioButton->isChecked() ) + { + profileData->setConnectionType ( VpnAccountData::openvpn ); + profileData->setLocalPort ( 1194 ); + profileData->setRemotePort ( 1194 ); + profileData->setUserdefinedPort ( 1194 ); + profileData->setUseSmartcard ( false ); + profileData->setCertPath ( "/etc/openvpn" ); + profileData->setHashAlgo ( "SHA1" ); + profileData->setAuthenticationAlgorithm ( "MD5" ); + removePage ( newprofilewizardciscoselectionpage ); + removePage ( newprofilewizardciscomanuallypage ); + removePage ( newprofilewizardracoonpage ); + removePage ( newprofilewizardpptppage ); + removePage ( newprofilewizardfreeswanpage ); + removePage ( newprofilewizardfreeswanselectionpage ); + newprofilewizardnetworkcontent->LabelRemoteNetwork->hide(); + newprofilewizardnetworkcontent->RemoteNetMaskComboBox->hide(); + newprofilewizardnetworkcontent->RemoteNetAddrLineEdit->hide(); + newprofilewizardnetworkcontent->RemoteNetDividetextLabel->hide(); + + newprofilewizardcertcontent->UseSmartcardCheckBox->show(); + newprofilewizardcertcontent->SmartcardGroupBox->show(); + newprofilewizardp12certselectioncontent->UseSmartcardCheckBox->show(); + newprofilewizardauthselectioncontent->CertificateRadioButton->setText ( i18n ( "&Certificate/Smartcard" ) ); + newprofilewizardcertcontent->certpathURLRequester->setURL ( "/etc/openvpn" ); + + profilenetworkvirtualipoptionscontent->SourceIpgroupBox->hide(); + + insertPage ( newprofilewizardopenvpnauthpage, "" + i18n ( "OpenVPN authentication settings" ) + "", indexOf ( currentpage ) + 1 ); + + connect ( newprofilewizardopenvpnauthpagecontent->AuthWithUsernameAndPasswordCheckBox, SIGNAL ( toggled ( bool ) ), this, SLOT ( authenticateWithUsernameAndPasswordToggled ( bool ) ) ); + newprofilewizardopenvpnauthpagecontent->UserdefiniedDigestComboBox->setCurrentText ( "SHA1" ); + + + insertPage ( newprofilewizardopenvpnselectionpage, "" + i18n ( "OpenVPN selection" ) + "", indexOf ( currentpage ) + 1 ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Selected type: %1" ).arg ( "OpenVPN" ), KVpncConfig::debug ); + } + else if ( newprofilewizardtypeselectionpagecontent->PptpRadioButton->isChecked() ) + { + profileData->setConnectionType ( VpnAccountData::pptp ); + profileData->setUseMtu ( false ); + profileData->setUseMru ( false ); + profileData->setMtu ( 1500 ); + profileData->setMru ( 1500 ); + newprofilewizardnetworkcontent->MtuSpinbox->show(); + newprofilewizardnetworkcontent->MtuCheckbox->show(); + newprofilewizardnetworkcontent->MruSpinbox->show(); + newprofilewizardnetworkcontent->MruCheckbox->show(); + newprofilewizardnetworkcontent->MtuSpinbox->setValue ( profileData->getMtu() ); + newprofilewizardnetworkcontent->MruSpinbox->setValue ( profileData->getMru() ); + newprofilewizardnetworkcontent->MtuSpinbox->setEnabled ( false ); + newprofilewizardnetworkcontent->MruSpinbox->setEnabled ( false ); + newprofilewizardnetworkcontent->MtuCheckbox->setChecked ( false ); + newprofilewizardnetworkcontent->MruCheckbox->setChecked ( false ); + + newprofilewizardpptppagecontent->AuthMethodComboBox->setCurrentText ( profileData->getAuthMethod() ); + newprofilewizardpptppagecontent->L2tpDaemonComboBox->hide(); + newprofilewizardpptppagecontent->L2tpdDaemonLabel->hide(); + newprofilewizardpptppagecontent->AuthGroupBox->hide(); + newprofilewizardpptppagecontent->UseNoDeflateCheckbox->setChecked( ! profileData->getUseNoDeflate()); + newprofilewizardpptppagecontent->UseNoBsdCompCheckbox->setChecked( ! profileData->getUseNoBsdComp()); + + removePage ( newprofilewizardciscoselectionpage ); + removePage ( newprofilewizardciscomanuallypage ); + removePage ( newprofilewizardcertpage ); + removePage ( newprofilewizardpskpage ); + removePage ( newprofilewizardp12certselectionpage ); + removePage ( newprofilewizardfreeswanpage ); + removePage ( newprofilewizardfreeswanselectionpage ); + removePage ( newprofilewizardracoonpage ); + removePage ( newprofilewizardopenvpnpage ); + removePage ( newprofilewizardopenvpnselectionpage ); + insertPage ( newprofilewizardpptppage, "" + i18n ( "PPTP settings" ) + "", indexOf ( currentpage ) + 1 ); + insertPage ( newprofilewizardnetworkpage, "" + i18n ( "Network settings" ) + "", indexOf ( currentpage ) + 2 ); + insertPage ( newprofilewizardnetworkroutepage, "" + i18n ( "Network routes" ) + "", indexOf ( currentpage ) + 3 ); + + newprofilewizarduserpagecontent ->NtDomainNameCheckbox->show(); + newprofilewizarduserpagecontent ->NtDomainNameLineedit->show(); + newprofilewizardcertcontent->UseSmartcardCheckBox->hide(); + newprofilewizardcertcontent->SmartcardGroupBox->hide(); + + profilenetworkvirtualipoptionscontent->SourceIpgroupBox->hide(); + + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Selected type: %1" ).arg ( "PPTP" ), KVpncConfig::debug ); + } + else if ( newprofilewizardtypeselectionpagecontent->VtunRadioButton->isChecked() ) + { + profileData->setConnectionType ( VpnAccountData::vtun ); + profileData->setLocalPort ( 5000 ); + profileData->setRemotePort ( 5000 ); + profileData->setUserdefinedPort ( 5000 ); + profileData->setUseSmartcard ( false ); +// profileData->setCertPath( "/etc/openvpn" ); +// profileData->setHashAlgo("SHA1"); +// profileData->setAuthenticationAlgorithm("MD5"); + removePage ( newprofilewizardciscoselectionpage ); + removePage ( newprofilewizardciscomanuallypage ); + removePage ( newprofilewizardracoonpage ); + removePage ( newprofilewizardpptppage ); + removePage ( newprofilewizardfreeswanpage ); + removePage ( newprofilewizardfreeswanselectionpage ); + removePage ( newprofilewizardopenvpnpage ); + newprofilewizardnetworkcontent->LabelRemoteNetwork->hide(); + newprofilewizardnetworkcontent->RemoteNetMaskComboBox->hide(); + newprofilewizardnetworkcontent->RemoteNetAddrLineEdit->hide(); + newprofilewizardnetworkcontent->RemoteNetDividetextLabel->hide(); + + + insertPage ( newprofilewizardvtunpage, "" + i18n ( "Vtun options" ) + "",2 ); + insertPage ( newprofilewizardnetworkpage, "" + i18n ( "Network settings" ) + "", indexOf ( currentpage ) + 3 ); + insertPage ( newprofilewizardnetworkroutepage, "" + i18n ( "Network routes" ) + "", indexOf ( currentpage ) + 4 ); + + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Selected type: %1" ).arg ( "Vtun" ), KVpncConfig::debug ); + } + else if ( newprofilewizardtypeselectionpagecontent->SshRadioButton->isChecked() ) + { + profileData->setConnectionType ( VpnAccountData::ssh ); + profileData->setRemotePort ( 22 ); + profileData->setUseSmartcard ( false ); + profileData->setTunnelDeviceType("tun"); + removePage ( newprofilewizardvtunpage); + removePage ( newprofilewizardciscoselectionpage ); + removePage ( newprofilewizardciscomanuallypage ); + removePage ( newprofilewizardracoonpage ); + removePage ( newprofilewizardpptppage ); + removePage ( newprofilewizardfreeswanpage ); + removePage ( newprofilewizardfreeswanselectionpage ); + removePage ( newprofilewizardopenvpnpage ); + newprofilewizardnetworkcontent->LabelRemoteNetwork->hide(); + newprofilewizardnetworkcontent->RemoteNetMaskComboBox->hide(); + newprofilewizardnetworkcontent->RemoteNetAddrLineEdit->hide(); + newprofilewizardnetworkcontent->RemoteNetDividetextLabel->hide(); + + profilenetworkvirtualipoptionscontent->SourceIpgroupBox->hide(); + + newprofilewizardnetworkcontent->LabelRemoteNetwork->hide(); + newprofilewizardnetworkcontent->RemoteNetMaskComboBox->hide(); + newprofilewizardnetworkcontent->RemoteNetAddrLineEdit->hide(); + newprofilewizardnetworkcontent->RemoteNetDividetextLabel->hide(); + newprofilewizardnetworkcontent->UseRemoteNetworkCheckBox->hide(); + newprofilewizardnetworkcontent->RemoteNetworkGroupBox->hide(); + + newprofilewizardnetworkcontent->TunnelDeviceTypeLabel->show(); + newprofilewizardnetworkcontent->TunnelDeviceTypeComboBox->show(); + newprofilewizardnetworkcontent->TunnelDeviceTypeLabel->setEnabled(true); + newprofilewizardnetworkcontent->TunnelDeviceTypeComboBox->setEnabled(true); + + + profilenetworkvirtualipoptionscontent->UseVirtualIPCheckBox->setChecked(true); + newprofilewizarduserpagecontent->UsernameLineEdit->setText("root"); + + insertPage ( newprofilewizarduserpage, "" + i18n ( "User settings" ) + "", indexOf ( currentpage ) + 1 ); + insertPage ( newprofilewizardsshpage, "" + i18n ( "SSH options" ) + "",2 ); + insertPage ( newprofilewizardnetworkpage, "" + i18n ( "Network settings" ) + "", indexOf ( currentpage ) + 3 ); + insertPage ( newprofilewizardnetworkroutepage, "" + i18n ( "Network routes" ) + "", indexOf ( currentpage ) + 4 ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Selected type: %1" ).arg ( "SSH" ), KVpncConfig::debug ); + } + + + QString type = ""; // visible name + QString bin = ""; // executable name + if ( profileData->getConnectionType() == VpnAccountData::cisco ) + { + type = "vpnc"; + bin = "vpnc"; + } + else if ( profileData->getConnectionType() == VpnAccountData::freeswan ) + { + type = "freeswan"; + bin = "ipsec"; + } + else if ( profileData->getConnectionType() == VpnAccountData::racoon ) + { + type = "racoon"; + bin = "racoon"; + } + else if ( profileData->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { + type = "L2TP (racoon)"; + bin = "racoon"; + } + else if ( profileData->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { + type = "L2TP (OpenSWAN)"; + bin = "ipsec"; + } + else if ( profileData->getConnectionType() == VpnAccountData::pptp ) + { + type = "pptp"; + bin = "pppd pptp"; + } + else if ( profileData->getConnectionType() == VpnAccountData::openvpn ) + { + type = "openvpn"; + bin = "openvpn"; + } + else if ( profileData->getConnectionType() == VpnAccountData::vtun ) + { + type = "vtun"; + bin = "vtund"; + } + else if ( profileData->getConnectionType() == VpnAccountData::ssh ) + { + type = "ssh"; + bin = "ssh"; + } + else + { + type = "other"; + bin = ""; + } + + ToolInfo *it = 0; + //std::cout << "Tool (bin): " << bin << std::endl; + + if ( !GlobalConfig->ToolList->isEmpty() ) + { + if ( type != "pptp" ) + { + it = Utils ( GlobalConfig ).getToolInfo ( bin ); + if ( it != 0 ) + { + if ( it->PathToExec.section ( '/', -1 ) == bin ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "The required daemon (%1) is available, you will be able to use this connection." ).arg ( bin ), KVpncConfig::info ); + daemonavailable = true; + } + else + { + KMessageBox::information ( this, i18n ( "The required daemon (%1) isn't available, you will not be able to use this connection until the daemon is not installed." ).arg ( bin ) ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "The required daemon (%1) isn't available, you will not be able to use this connection until the daemon is not installed." ).arg ( bin ), KVpncConfig::error ); + daemonavailable = false; + removePage ( newprofilewizardconnectoptionspage ); + } + } + if ( type == "ipsec" ) + { + + QString realversion = it->Version.section ( ' ', 1, 1 ).section ( '/', 0, 0 ).right ( it->Version.section ( ' ', 1, 1 ).section ( '/', 0, 0 ).length() - 1 ); + QString realtype = it->Version.section ( ' ', 0, 0 ).lower(); + + if ( realversion.find ( "1.", 0, -1 ) > -1 ) + { + KMessageBox::information ( this, i18n ( "The required version (%1) of FreeSWAN/OpenSWAN was not found. You will not be able to use the Agressive Mode. It will be used the Main Mode." ).arg ( "2" ) ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "The required version (%1) of FreeSWAN/OpenSWAN was not found. You will not be able to use the Agressive Mode. It will be used the Main Mode." ).arg ( "2" ).arg ( bin ), KVpncConfig::error ); + } + } + } + else + { + bool pppd_and_pptp_available = false; + it = Utils ( GlobalConfig ).getToolInfo ( "pppd" ); + if ( it->PathToExec.section ( '/', -1 ) == "pppd" ) + { + it = Utils ( GlobalConfig ).getToolInfo ( "pptp" ); + if ( it->PathToExec.section ( '/', -1 ) == "pptp" ) + pppd_and_pptp_available = true; + } + if ( pppd_and_pptp_available ) + { + // programs are installed + daemonavailable = true; + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "The required daemons (%1 and %2) are available." ).arg ( "pppd" ).arg ( "pptp" ), KVpncConfig::info ); + } + else + { + KMessageBox::information ( this, i18n ( "The required daemons (%1 and %2) aren't available, you will not be able to use this connection until the daemons are not installed." ).arg ( "pppd" ).arg ( "pptpd" ) ); + GlobalConfig->appendLogEntry ( i18n ( "The required daemons (%1 and %2) are not available, connect will be disabled." ).arg ( "pppd" ).arg ( "pptpd" ), KVpncConfig::error ); + daemonavailable = false; + removePage ( newprofilewizardconnectoptionspage ); + } + } + + } + + } + else if ( currentpage == newprofilewizardciscoselectionpage ) + { + if ( newprofilewizardciscoselectionpagecontent->PcfImportRadioButton->isChecked() ) + { + enterdatamanually = false; + removePage ( newprofilewizardciscomanuallypage ); + removePage ( newprofilewizardgeneralpage ); + //insertPage ( newprofilewizarduserpage, "" + i18n ( "User settings" ) + "", indexOf ( currentpage ) + 1 ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Cisco selection: import PCF file" ), KVpncConfig::debug ); + + if ( profileData->getConnectionType() == VpnAccountData::cisco ) + importProfile ( VpnAccountData::cisco ); + if ( profileData->getConnectionType() == VpnAccountData::ciscoorig ) + importProfile ( VpnAccountData::ciscoorig ); + if ( importOK ) + newProfileCreated = true; + else + newProfileCreated = false; + + } + else + { + enterdatamanually = true; + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Cisco selection: enter data manually" ), KVpncConfig::debug ); + + if ( profileData->getConnectionType() == VpnAccountData::cisco ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Cisco selection: cisco" ), KVpncConfig::debug ); + + insertPage ( newprofilewizarduserpage, "" + i18n ( "User settings" ) + "", indexOf ( currentpage ) + 1 ); + insertPage ( newprofilewizardciscomanuallypage, "" + i18n ( "Cisco settings" ) + "", indexOf ( currentpage ) + 2 ); + insertPage ( newprofilewizardnetworkpage, "" + i18n ( "Network settings" ) + "", indexOf ( currentpage ) + 3 ); + insertPage ( newprofilewizardnetworkroutepage, "" + i18n ( "Network routes" ) + "", indexOf ( currentpage ) + 4 ); + } + if ( profileData->getConnectionType() == VpnAccountData::ciscoorig ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Cisco selection: ciscoorig" ), KVpncConfig::debug ); + + insertPage ( newprofilewizardauthselectionpage, ""+ i18n ( "Authentication settings" ) +"", indexOf ( currentpage ) + 1 ); + insertPage ( newprofilewizarduserpage, "" + i18n ( "User settings" ) + "", indexOf ( currentpage ) + 2 ); + insertPage ( newprofilewizardnetworkpage, "" + i18n ( "Network settings" ) + "", indexOf ( currentpage ) + 4 ); + insertPage ( newprofilewizardnetworkroutepage, "" + i18n ( "Network routes" ) + "", indexOf ( currentpage ) + 5 ); + + newprofilewizardauthselectioncontent->PskRadioButton->setChecked(true); + } + + } + } + else if ( currentpage == newprofilewizardciscomanuallypage ) + { + msg = i18n ( "These fields must be filled in:\n" ); + if ( newprofilewizardciscomanuallypagecontent->IDLineEdit->text().isEmpty() ) + { + ok = false; + msg += "- " + i18n ( "Cisco IPSec ID" ) + "\n"; + GlobalConfig->appendLogEntry ( i18n ( "Cisco IPSec ID is empty!" ), GlobalConfig->error ); + } + profileData->setGateway ( newprofilewizardciscomanuallypagecontent->IDLineEdit->text() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Cisco IPSec ID: %1" ).arg ( newprofilewizardciscomanuallypagecontent->IDLineEdit->text() ), KVpncConfig::debug ); + + profileData->setAllowEmptyGroupPassword ( newprofilewizardciscomanuallypagecontent->AllowEmptyGroupPasswordCheckBox->isChecked() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + { + if ( newprofilewizardciscomanuallypagecontent->AllowEmptyGroupPasswordCheckBox->isChecked() ) + GlobalConfig->appendLogEntry ( i18n ( "Allow empty group password: true" ), KVpncConfig::debug ); + else + GlobalConfig->appendLogEntry ( i18n ( "Allow empty group password: false" ), KVpncConfig::debug ); + } + +// if ( !newprofilewizardciscomanuallypagecontent->AllowEmptyGroupPasswordCheckBox->isChecked() && newprofilewizardciscomanuallypagecontent->GroupPasswordLineEdit->text().isEmpty() ) +// { +// ok = false; +// msg += "- " + i18n( "Group password" ) + "\n"; +// GlobalConfig->appendLogEntry( i18n( "Group password is empty but you dont have checked to allow that!" ), GlobalConfig->error ); +// } +// else + profileData->setPreSharedKey ( newprofilewizardciscomanuallypagecontent->GroupPasswordLineEdit->text() ); + + profileData->setSavePsk ( newprofilewizardciscomanuallypagecontent->CheckSavePsk->isChecked() ); + + profileData->setID ( newprofilewizardciscomanuallypagecontent->IDLineEdit->text() ); + profileData->setAllowEmptyGroupPassword ( newprofilewizardciscomanuallypagecontent->AllowEmptyGroupPasswordCheckBox->isChecked() ); + + profileData->setUseDpdIdleTimeout(true); + if (profileData->getConnectionType() == VpnAccountData::cisco ) + profileData->setDpdIdleTimeout(300); + if (profileData->getConnectionType() == VpnAccountData::ciscoorig ) + profileData->setDpdIdleTimeout(90); + + insertPage ( newprofilewizarduserpage, "" + i18n ( "User settings" ) + "", indexOf ( currentpage ) + 1 ); + insertPage ( newprofilewizardnetworkpage, "" + i18n ( "Network settings" ) + "", indexOf ( currentpage ) + 2 ); + insertPage ( newprofilewizardnatpage, "" + i18n ( "NAT settings" ) + "", indexOf ( currentpage ) + 3 ); + insertPage ( newprofilewizardnetworkroutepage, "" + i18n ( "Network routes" ) + "", indexOf ( currentpage ) + 4 ); + + } + else if ( currentpage == newprofilewizardfreeswanpage ) + { + msg = i18n ( "These fields must be filled in:\n" ); + profileData->setUseModeConfig ( newprofilewizardfreeswanpagecontent->UseModeConfigCheckBox->isChecked() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + { + if ( newprofilewizardfreeswanpagecontent->UseModeConfigCheckBox->isChecked() ) + GlobalConfig->appendLogEntry ( i18n ( "Use Mode Config: %1" ).arg ( i18n ( "yes" ) ), KVpncConfig::debug ); + else + GlobalConfig->appendLogEntry ( i18n ( "Use Mode Config: %1" ).arg ( i18n ( "no" ) ), KVpncConfig::debug ); + } + + profileData->setExchangeMode ( newprofilewizardfreeswanpagecontent->ExchangeModeComboBox->currentText() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Exchange mode (%1): %2" ).arg ( "ipsec" ).arg ( newprofilewizardfreeswanpagecontent->ExchangeModeComboBox->currentText() ), KVpncConfig::debug ); + + profileData->setLeftNextHop ( newprofilewizardfreeswanpagecontent->LeftNextHopLineEdit->text() ); //TODO check valid IP + profileData->setRightNextHop ( newprofilewizardfreeswanpagecontent->RightNextHopLineEdit->text( ) ); //TODO check valid IP + profileData->setDisableOpportunisticEncryption ( newprofilewizardfreeswanpagecontent->DisableOpportunisticEncryptionCheckBox->isChecked( ) ); + + // xauth + if (newprofilewizardfreeswanpagecontent->UseXauthCheckBox->isChecked()) + { + profileData->setAuthWithUsernameAndPassword(true); + } + else + { + profileData->setAuthWithUsernameAndPassword(false); + } + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + { + if ( newprofilewizardfreeswanpagecontent->DisableOpportunisticEncryptionCheckBox->isChecked() ) + GlobalConfig->appendLogEntry ( i18n ( "Disable opportunistic encryption: %1" ).arg ( i18n ( "yes" ) ), KVpncConfig::debug ); + else + GlobalConfig->appendLogEntry ( i18n ( "Disable opportunistic encryption: %1" ).arg ( i18n ( "no" ) ), KVpncConfig::debug ); + GlobalConfig->appendLogEntry ( i18n ( "Right next hop: %1" ).arg ( newprofilewizardfreeswanpagecontent->RightNextHopLineEdit->text() ), KVpncConfig::debug ); + GlobalConfig->appendLogEntry ( i18n ( "Left next hop: %1" ).arg ( newprofilewizardfreeswanpagecontent->LeftNextHopLineEdit->text() ), KVpncConfig::debug ); + GlobalConfig->appendLogEntry ( i18n ( "Use PFS: %1" ).arg ( profileData->getPerfectForwardSecrety() ), KVpncConfig::debug ); + + } + + profileData->setExchangeMode ( newprofilewizardfreeswanpagecontent->ExchangeModeComboBox->currentText() ); + + if (newprofilewizardfreeswanpagecontent->UseXauthCheckBox->isChecked()) + { + if ( newprofilewizardfreeswanpagecontent->LocalIDLineEdit->text().isEmpty() ) + { + ok = false; + msg += "- " + i18n ( "Local ID (Group ID)" ) + "\n"; + GlobalConfig->appendLogEntry ( i18n ( "Local ID (Group ID) is empty!" ), GlobalConfig->error ); + } + profileData->setUseSpecialLocalID(true); + } + + profileData->setLocalIDType ( newprofilewizardfreeswanpagecontent->LocalIdTypeCombobox->currentText() ); + + if (newprofilewizardfreeswanpagecontent->RemoteIdTypeCombobox->currentText() != "none" && newprofilewizardfreeswanpagecontent->RemoteIDLineEdit->text().isEmpty() ) + { + ok = false; + msg += "- " + i18n ( "Remote ID" ) + "\n"; + GlobalConfig->appendLogEntry ( i18n ( "Remote ID is empty!" ), GlobalConfig->error ); + } + if (newprofilewizardfreeswanpagecontent->RemoteIdTypeCombobox->currentText() != "none") + profileData->setUseSpecialRemoteID(true); + else + profileData->setUseSpecialRemoteID(false); + + profileData->setRemoteIDType ( newprofilewizardfreeswanpagecontent->RemoteIdTypeCombobox->currentText() ); + + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Type of local ID: %1" ).arg ( newprofilewizardfreeswanpagecontent->LocalIdTypeCombobox->currentText() ), KVpncConfig::debug ); + + profileData->setSpecialLocalID ( newprofilewizardfreeswanpagecontent->LocalIDLineEdit->text() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Local ID value: %1" ).arg ( newprofilewizardfreeswanpagecontent->LocalIDLineEdit->text() ), KVpncConfig::debug ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Type of remote ID: %1" ).arg ( newprofilewizardfreeswanpagecontent->RemoteIdTypeCombobox->currentText() ), KVpncConfig::debug ); + + profileData->setSpecialRemoteID ( newprofilewizardfreeswanpagecontent->RemoteIDLineEdit->text() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Remote ID value: %1" ).arg ( newprofilewizardfreeswanpagecontent->RemoteIDLineEdit->text() ), KVpncConfig::debug ); + + + // ike + esp + QStringList IkeList; + QStringList EspList; + + if (newprofilewizardfreeswanpagecontent->IkeAes256Sha1CheckBox->isChecked()) + IkeList.append("aes256-sha1"); + if (newprofilewizardfreeswanpagecontent->IkeAes128Sha1CheckBox->isChecked()) + IkeList.append("aes128-sha1"); + if (newprofilewizardfreeswanpagecontent->IkeDesSha1Modp2048CheckBox->isChecked()) + IkeList.append("3des-sha1-modp2048"); + if (newprofilewizardfreeswanpagecontent->IkeDesMd5CheckBox->isChecked()) + IkeList.append("3des-md5"); + if (newprofilewizardfreeswanpagecontent->IkeDesSha1CheckBox->isChecked()) + IkeList.append("3des-sha1"); + + if (!newprofilewizardfreeswanpagecontent->OtherIkeLineEdit->text().isEmpty()) + IkeList.append(newprofilewizardfreeswanpagecontent->OtherIkeLineEdit->text()); + + if (newprofilewizardfreeswanpagecontent->Esp3desMd5CheckBox->isChecked()) + EspList.append("3des-md5"); + if (newprofilewizardfreeswanpagecontent->EspDesSha1CheckBox->isChecked()) + EspList.append("3des-sha1"); + if (newprofilewizardfreeswanpagecontent->EspAes128Sha1CheckBox->isChecked()) + EspList.append( "aes128-sha1"); + if (newprofilewizardfreeswanpagecontent->EspAes256Sha1CheckBox->isChecked()) + EspList.append( "aes256-sha1"); + + if (!newprofilewizardfreeswanpagecontent->OtherEspLineEdit->text().isEmpty()) + EspList.append(newprofilewizardfreeswanpagecontent->OtherEspLineEdit->text()); + +// for ( QStringList::Iterator ikeit = IkeList.begin(); ikeit != IkeList.end(); ++ikeit ) +// std::cout << "ike: " << *ikeit << ":" << std::endl; + +// for ( QStringList::Iterator espit = EspList.begin(); espit != EspList.end(); ++espit ) +// std::cout << "esp: " << *espit << ":" << std::endl; + + if(newprofilewizardfreeswanpagecontent->UseCustomEspCheckBox->isChecked() && !EspList.isEmpty()) + { + profileData->setUseCustomEsp(true); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Use custom %1: %2" ).arg ( i18n("ESP") ).arg(i18n("yes")), KVpncConfig::debug ); + + profileData->setIpsecEsp(EspList.join(",")); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "ESP settings: %1" ).arg ( EspList.join(",") ), KVpncConfig::debug ); + + } + else if(newprofilewizardfreeswanpagecontent->UseCustomEspCheckBox->isChecked() && EspList.isEmpty()) + { + ok = false; + msg += "- " + i18n ( "Use custom ESP checked but none selected!" ) + "\n"; + GlobalConfig->appendLogEntry ( i18n ( "Use custom ESP checked but none selected!" ), GlobalConfig->error ); + } + else if(!newprofilewizardfreeswanpagecontent->UseCustomEspCheckBox->isChecked()) + { + profileData->setUseCustomEsp(false); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Use custom %1: %2" ).arg ( i18n("ESP") ).arg(i18n("no")), KVpncConfig::debug ); + } + + if(newprofilewizardfreeswanpagecontent->UseCustomIkeCheckBox->isChecked() && !IkeList.isEmpty()) + { + profileData->setUseCustomIke(true); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Use custom %1: %2" ).arg ( i18n("IKE") ).arg(i18n("yes")), KVpncConfig::debug ); + + profileData->setIpsecIke(IkeList.join(",")); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "IKE settings: %1" ).arg ( IkeList.join(",") ), KVpncConfig::debug ); + + } + else if(newprofilewizardfreeswanpagecontent->UseCustomIkeCheckBox->isChecked() && IkeList.isEmpty()) + { + ok = false; + msg += "- " + i18n ( "Use custom IKE checked but none selected!" ) + "\n"; + GlobalConfig->appendLogEntry ( i18n ( "Use custom IKE checked but none selected!" ), GlobalConfig->error ); + } + else if (!newprofilewizardfreeswanpagecontent->UseCustomIkeCheckBox->isChecked()) + { + profileData->setUseCustomIke(false); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Use custom %1: %2" ).arg ( i18n("IKE") ).arg(i18n("false")), KVpncConfig::debug ); + } + + if (ok) + { + if (newprofilewizardfreeswanpagecontent->UseXauthCheckBox->isChecked()) + { + if (GlobalConfig->KvpncDebugLevel > 1) + GlobalConfig->appendLogEntry ( i18n ( "Authenticate with username and password: %1" ).arg ( i18n ( "yes" ) ), KVpncConfig::debug ); + profileData->setAuthWithUsernameAndPassword(true); + + insertPage ( newprofilewizarduserpage, "" + i18n ( "User settings" ) + "", indexOf ( currentpage ) + 1 ); + insertPage ( newprofilewizardnetworkpage, "" + i18n ( "Network settings" ) + "", indexOf ( currentpage ) + 2 ); + insertPage ( newprofilewizardnatpage, "" + i18n ( "NAT settings" ) + "", indexOf ( currentpage ) + 3 ); + insertPage ( newprofilewizardnetworkroutepage, "" + i18n ( "Network routes" ) + "", indexOf ( currentpage ) + 4 ); + } + else + { + if (GlobalConfig->KvpncDebugLevel > 1) + GlobalConfig->appendLogEntry ( i18n ( "Authenticate with username and password: %1" ).arg ( i18n ( "no" ) ), KVpncConfig::debug ); + + insertPage ( newprofilewizardnetworkpage, "" + i18n ( "Network settings" ) + "", indexOf ( currentpage ) + 1 ); + insertPage ( newprofilewizardnatpage, "" + i18n ( "NAT settings" ) + "", indexOf ( currentpage ) + 2 ); + insertPage ( newprofilewizardnetworkroutepage, "" + i18n ( "Network routes" ) + "", indexOf ( currentpage ) + 3 ); + } + } + + } + else if ( currentpage == newprofilewizardfreeswanselectionpage ) + { + if ( newprofilewizardfreeswanselectionpagecontent->OpenvpnImportRadioButton->isChecked() ) + { + enterdatamanually = false; + removePage ( newprofilewizardfreeswanpage ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "IPSec selection: import profile file" ), KVpncConfig::debug ); + + // removePage ( newprofilewizardgeneralpage ); +// removePage ( newprofilewizardvirtualipaddresspage ); + + if ( importProfile ( VpnAccountData::freeswan ) == true ) + { + newProfileCreated = true; + newprofilewizardgeneralpagecontent->NameLineEdit->setText ( profileData->getName() ); + newprofilewizardgeneralpagecontent->gatewayLineEdit->setText ( profileData->getGateway() ); + newprofilewizardgeneralpagecontent->DescriptionLineEdit->setText ( profileData->getDescription() ); + + } + else + { + newProfileCreated = false; + ok = false; + } + } + else + { + enterdatamanually = true; + insertPage ( newprofilewizardfreeswanpage, "" + i18n ( "IPSec settings" ) + "", indexOf ( currentpage ) + 1 ); + insertPage ( newprofilewizardauthselectionpage, i18n ( "Authentication settings" ), indexOf ( currentpage ) + 1 ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "IPSec selection: enter data manually" ), KVpncConfig::debug ); + } + + } + else if ( currentpage == newprofilewizardracoonpage ) + { + if ( newprofilewizardracoonpagecontent->HashAlgoComboBox->currentText() == "SHA1" ) + { + profileData->setHashAlgo ( "sha1" ); + } + if ( newprofilewizardracoonpagecontent->HashAlgoComboBox->currentText() == "MD5" ) + { + profileData->setHashAlgo ( "md5" ); + } + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Hash algorithm (%1): %2" ).arg ( "racoon" ).arg ( profileData->getHashAlgo() ), KVpncConfig::debug ); + + if ( newprofilewizardtypeselectionpagecontent->RacoonRadioButton->isChecked() ) + { + profileData->setUseModeConfig ( newprofilewizardracoonpagecontent->UseModeConfigCheckBox->isChecked() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + { + if ( newprofilewizardracoonpagecontent->UseModeConfigCheckBox->isChecked() ) + GlobalConfig->appendLogEntry ( i18n ( "Use Mode Config: %1" ).arg ( i18n ( "yes" ) ), KVpncConfig::debug ); + else + GlobalConfig->appendLogEntry ( i18n ( "Use Mode Config: %1" ).arg ( i18n ( "no" ) ), KVpncConfig::debug ); + } + } + + profileData->setExchangeMode ( newprofilewizardracoonpagecontent->ExchangeModeComboBox->currentText() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Exchange mode (%1): %2" ).arg ( "racoon" ).arg ( newprofilewizardracoonpagecontent->ExchangeModeComboBox->currentText() ), KVpncConfig::debug ); + + profileData->setIkeGroup ( newprofilewizardracoonpagecontent->DHGroupComboBox->currentText() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "DH group (%1): %2" ).arg ( "racoon" ).arg ( newprofilewizardracoonpagecontent->DHGroupComboBox->currentText() ), KVpncConfig::debug ); + + profileData->setAuthenticationAlgorithm( newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->currentText() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Authentication algorithm (%1) (phase 2): %2" ).arg ( "racoon" ).arg ( newprofilewizardracoonpagecontent->AuthenticationAlgorithm2ComboBox->currentText() ),KVpncConfig::debug ); + + profileData->setIpsecIke(newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->currentText()); + profileData->setUseAuthenticationAlgorithm(true); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Encryption algorithm (%1) (phase 1): %2" ).arg ( "racoon" ).arg ( newprofilewizardracoonpagecontent->EncryptionAlgorithmComboBox->currentText() ), KVpncConfig::debug ); + + profileData->setLocalIDType ( newprofilewizardracoonpagecontent->LocalIdTypeCombobox->currentText() ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Type of local ID: %1" ).arg ( newprofilewizardracoonpagecontent->LocalIdTypeCombobox->currentText() ), KVpncConfig::debug ); + + profileData->setSpecialLocalID ( newprofilewizardracoonpagecontent->LocalIDLineEdit->text() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Local ID value: %1" ).arg ( newprofilewizardracoonpagecontent->LocalIDLineEdit->text() ), KVpncConfig::debug ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Type of remote ID: %1" ).arg ( newprofilewizardracoonpagecontent->RemoteIdTypeCombobox->currentText() ), KVpncConfig::debug ); + + profileData->setSpecialRemoteID ( newprofilewizardracoonpagecontent->RemoteIDLineEdit->text() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Remote ID value: %1" ).arg ( newprofilewizardracoonpagecontent->RemoteIDLineEdit->text() ), KVpncConfig::debug ); + + + if (newprofilewizardracoonpagecontent->UseXauthCheckBox->isChecked()) + { + profileData->setAuthWithUsernameAndPassword(true); + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Authenticate with username and password: %1" ).arg ( i18n ( "yes" ) ), KVpncConfig::debug ); + insertPage ( newprofilewizarduserpage, "" + i18n ( "User settings" ) + "", indexOf ( currentpage ) + 1 ); + insertPage ( newprofilewizardnetworkpage, "" + i18n ( "Network settings" ) + "", indexOf ( currentpage ) + 2 ); + insertPage ( newprofilewizardnatpage, "" + i18n ( "NAT settings" ) + "", indexOf ( currentpage ) + 3 ); + insertPage ( newprofilewizardnetworkroutepage, "" + i18n ( "Network routes" ) + "", indexOf ( currentpage ) +4 ); + + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Authenticate with username and password: %1" ).arg ( i18n ( "no" ) ), KVpncConfig::debug ); + insertPage ( newprofilewizardnetworkpage, "" + i18n ( "Network settings" ) + "", indexOf ( currentpage ) + 1 ); + insertPage ( newprofilewizardnatpage, "" + i18n ( "NAT settings" ) + "", indexOf ( currentpage ) + 2 ); + insertPage ( newprofilewizardnetworkroutepage, "" + i18n ( "Network routes" ) + "", indexOf ( currentpage ) +3 ); + } + } + else if ( currentpage == newprofilewizardopenvpnpage ) + { + msg = i18n ( "These fields must be filled in:\n" ); + profileData->setTunnelDeviceType ( newprofilewizardopenvpnpagecontent->TunnelDeviceTypeComboBox->currentText() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Tunnel device type (%1): %2" ).arg ( "OpenVPN" ).arg ( newprofilewizardopenvpnpagecontent->TunnelDeviceTypeComboBox->currentText() ), KVpncConfig::debug ); + + if ( newprofilewizardopenvpnpagecontent->NsCertTypeComboBox->currentText() == "client" ) + profileData->setNsCertType ( "client" ); + else + profileData->setNsCertType ( "server" ); + + profileData->setTunnelDeviceType ( newprofilewizardopenvpnpagecontent->TunnelDeviceTypeComboBox->currentText() ); + + insertPage ( newprofilewizardauthselectionpage, "" + i18n ( "Authentication settings" ) + "", indexOf ( currentpage ) + 1 ); + insertPage ( newprofilewizardnetworkpage, "" + i18n ( "Network settings" ) + "", indexOf ( currentpage ) + 2 ); + insertPage ( newprofilewizardnetworkroutepage, "" + i18n ( "Network routes" ) + "", indexOf ( currentpage ) + 3 ); + insertPage ( newprofilewizardnatpage, "" + i18n ( "NAT settings" ) + "", indexOf ( currentpage ) + 4 ); + + profileData->setUserdefiniedCipher ( newprofilewizardopenvpnpagecontent->UserdefiniedCipherComboBox->currentText() ); + profileData->setUseUserdefiniedCipher ( newprofilewizardopenvpnpagecontent->UseUserdefiniedCipherCheckBox->isChecked() ); + + profileData->setRemotePort ( newprofilewizardopenvpnpagecontent->UserdefinedPortSpinBox->value() ); + profileData->setUseRemotePort ( newprofilewizardopenvpnpagecontent->UseUserdefinedPortCheckBox->isChecked() ); + + if ( newprofilewizardopenvpnpagecontent->UseTlsAuthCheckBox->isChecked() ) + { + if ( newprofilewizardopenvpnpagecontent->TlsAuthURLRequester->url().isEmpty() ) + { + ok = false; + msg += i18n ( "TLS auth file" ) + "\n"; + } + else + { + profileData->setUseTlsAuth ( true ); + profileData->setTlsAuthFile ( newprofilewizardopenvpnpagecontent->TlsAuthURLRequester->url() ); + } + } + + if ( newprofilewizardopenvpnpagecontent->UseTlsRemoteHostCheckBox->isChecked() ) + { + if ( newprofilewizardopenvpnpagecontent->TlsRemoteHostLineEdit->text().isEmpty() ) + { + ok = false; + msg += i18n ( "TLS remote host" ) + "\n"; + } + else + { + profileData->setUseTlsRemoteHost ( newprofilewizardopenvpnpagecontent->UseTlsAuthCheckBox->isChecked() ); + profileData->setTlsRemoteHost ( newprofilewizardopenvpnpagecontent->TlsRemoteHostLineEdit->text() ); + } + } + + profileData->setDisableLzoCompression ( newprofilewizardopenvpnpagecontent->DisableLzoCompressionCheckBox->isChecked() ); + + if ( newprofilewizardopenvpnpagecontent->UseHttpProxyCheckBox->isChecked() ) + { + if ( newprofilewizardopenvpnpagecontent->HttpProxyLineEdit->text().isEmpty() ) + { + ok = false; + msg += i18n ( "HTTP proxy host" ) + "\n"; + } + else + { + profileData->setUseHttpProxy ( newprofilewizardopenvpnpagecontent->UseHttpProxyCheckBox->isChecked() ); + profileData->setHttpProxy ( newprofilewizardopenvpnpagecontent->HttpProxyLineEdit->text( ) ); + } + } + + if ( newprofilewizardopenvpnpagecontent->AllowIpAddressChangeOfPeerCheckBox->isChecked() ) + profileData->setAllowIpAddressChangeOfPeer ( true ); + else + profileData->setAllowIpAddressChangeOfPeer ( false ); + + profileData->setHttpProxyPort ( newprofilewizardopenvpnpagecontent->HttpProxyPortIntNumInput->value( ) ); + profileData->setHttpProxyTimeout ( newprofilewizardopenvpnpagecontent->HttpProxyTimeoutIntSpinBox->value() ); + + + } + else if ( currentpage == newprofilewizardauthselectionpage ) + { + if ( newprofilewizardauthselectioncontent->PskRadioButton->isChecked() ) + { + useCert = false; + + profileData->setAuthType ( VpnAccountData::psk ); + insertPage ( newprofilewizardpskpage, "" + i18n ( "PSK settings" ) + "", indexOf ( currentpage ) + 1 ); + + // racoon or freeswan + if ( profileData->getConnectionType() == VpnAccountData::freeswan || profileData->getConnectionType() == VpnAccountData::racoon || + profileData->getConnectionType() == VpnAccountData::l2tpd_freeswan || profileData->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { + newprofilewizardpskcontent->PSKLineEdit->setEnabled ( true ); + newprofilewizardfreeswanpagecontent->UseXauthCheckBox->setEnabled ( true ); + newprofilewizardracoonpagecontent->UseXauthCheckBox->setEnabled ( true ); + } + + else if ( profileData->getConnectionType() == VpnAccountData::openvpn ) + { + newprofilewizardpskcontent->PSKLineEdit->setEnabled ( true ); + newprofilewizardpskcontent->LabelPsk->setEnabled ( true ); + } + + else if ( profileData->getConnectionType() == VpnAccountData::ciscoorig ) + { + insertPage ( newprofilewizardciscomanuallypage, "" + i18n ( "Cisco settings" ) + "", indexOf ( currentpage ) + 1 ); + removePage( newprofilewizardpskpage); + } + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Auth selection: use PSK" ), KVpncConfig::debug ); + } + if ( newprofilewizardauthselectioncontent->CertificateRadioButton->isChecked() ) + { + useCert = true; + profileData->setAuthType ( VpnAccountData::cert ); + + newprofilewizardcertcontent->x509certURLRequester->show(); + newprofilewizardcertcontent->x509certURLRequester->sizeHint(); + newprofilewizardcertcontent->x509certComboBox->hide(); + + + if (profileData->getConnectionType() != VpnAccountData::ciscoorig) + insertPage ( newprofilewizardp12certselectionpage, "" + i18n ( "Certificate format" ) + "", indexOf ( currentpage ) + 1 ); + // racoon or freeswan + if ( profileData->getConnectionType() == VpnAccountData::freeswan || profileData->getConnectionType() == VpnAccountData::racoon || + profileData->getConnectionType() == VpnAccountData::l2tpd_freeswan || profileData->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { + newprofilewizardcertcontent->x509certURLRequester->setEnabled ( true ); + newprofilewizardcertcontent->LabelCertificate->setEnabled ( true ); + newprofilewizardcertcontent->certpathURLRequester->setEnabled ( true ); + newprofilewizardcertcontent->LabelCertificatePath->setEnabled ( true ); + + newprofilewizardfreeswanpagecontent->UseXauthCheckBox->setEnabled ( false ); + newprofilewizardracoonpagecontent->UseXauthCheckBox->setEnabled ( false ); + } + + else if ( profileData->getConnectionType() == VpnAccountData::openvpn ) + { + newprofilewizardcertcontent->CaCertpathURLRequester->setEnabled ( true ); + newprofilewizardcertcontent->certpathURLRequester->setEnabled ( true ); + newprofilewizardcertcontent->LabelCertificatePath->setEnabled ( true ); + + + if ( profileData->getUseOnlyCaCertAndUserAuth() ) + { + newprofilewizardcertcontent->x509certURLRequester->setEnabled ( false ); + newprofilewizardcertcontent->privkeypathURLRequester->setEnabled ( false ); + newprofilewizardcertcontent->PrivkeyPasswordEdit->setEnabled ( false ); + newprofilewizardcertcontent->LabelPrivateKeyPath->setEnabled ( false ); + newprofilewizardcertcontent->LabelCertificate->setEnabled ( false ); + newprofilewizardcertcontent->LabelPrivateKeyPassword->setEnabled ( false ); + + } + else + { + newprofilewizardcertcontent->x509certURLRequester->setEnabled ( true ); + newprofilewizardcertcontent->privkeypathURLRequester->setEnabled ( true ); + newprofilewizardcertcontent->PrivkeyPasswordEdit->setEnabled ( true ); + newprofilewizardcertcontent->LabelPrivateKeyPath->setEnabled ( true ); + newprofilewizardcertcontent->LabelCertificate->setEnabled ( true ); + newprofilewizardcertcontent->LabelPrivateKeyPassword->setEnabled ( true ); + } + } + + else if ( profileData->getConnectionType() == VpnAccountData::ciscoorig ) + { + newprofilewizardcertcontent->x509certURLRequester->setEnabled ( true ); + newprofilewizardcertcontent->LabelCertificate->setEnabled ( true ); + newprofilewizardcertcontent->certpathURLRequester->setEnabled ( false ); + newprofilewizardcertcontent->LabelCertificatePath->setEnabled ( false ); + newprofilewizardcertcontent->certpathURLRequester->hide(); + newprofilewizardcertcontent->LabelCertificatePath->hide(); + newprofilewizardcertcontent->UseSmartcardCheckBox->hide(); + newprofilewizardcertcontent->SmartcardGroupBox->hide(); + newprofilewizardcertcontent->UseSpecialServerCertificateCheckBox->hide(); + newprofilewizardcertcontent->SpecialServerCertificateURLRequester->hide(); + newprofilewizardcertcontent->CaCertpathURLRequester->hide(); + newprofilewizardcertcontent->LabelPrivateKeyPath->hide(); + newprofilewizardcertcontent->privkeypathURLRequester->hide(); + newprofilewizardcertcontent->LabelCaCertificatePath->hide(); + newprofilewizardcertcontent->CertificateGroupBox->resize(newprofilewizardcertcontent->CertificateGroupBox->sizeHint()); + + + insertPage ( newprofilewizardcertpage, "" + i18n ( "Certificate settings" ) + "", indexOf ( currentpage ) + 1 ); + + +// newprofilewizardciscomanuallypagecontent->AllowEmptyGroupPasswordCheckBox->hide(); +// newprofilewizardciscomanuallypagecontent->LabelPsk->hide(); +// newprofilewizardciscomanuallypagecontent->GroupPasswordLineEdit->hide(); +// newprofilewizardciscomanuallypagecontent->CheckSavePsk->hide(); + + if ( importCertificate() ) + { + // success :) + } + else + { + newProfileCreated = false; + } + newprofilewizardcertcontent->LabelPrivateKeyPassword->setText("Certificate password:"); + // newprofilewizardcertcontent->LabelCertificate->setText(i18n("Certificate (enter name here):")); + newprofilewizardcertcontent->x509certURLRequester->hide(); + newprofilewizardcertcontent->x509certComboBox->show(); + newprofilewizardcertcontent->x509certComboBox->sizeHint(); + newprofilewizardcertcontent->x509certComboBox->setCurrentItem(0); + + } + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Auth selection: use certificate" ), KVpncConfig::debug ); + } + if ( newprofilewizardauthselectioncontent->HybridRadioButton->isChecked() ) + { + useCert = false; + + profileData->setAuthType ( VpnAccountData::hybrid ); + insertPage ( newprofilewizardcertpage, "" + i18n ( "Certificate settings" ) + "", indexOf ( currentpage ) + 1 ); + + // racoon or freeswan + if ( profileData->getConnectionType() == VpnAccountData::racoon || profileData->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { + newprofilewizardpskcontent->PSKLineEdit->setEnabled ( true ); + newprofilewizardfreeswanpagecontent->UseXauthCheckBox->setEnabled ( true ); + newprofilewizardracoonpagecontent->UseXauthCheckBox->setEnabled ( true ); + + newprofilewizardcertpage->setEnabled(true); + newprofilewizardcertcontent->x509certComboBox->setEnabled(false); + newprofilewizardcertcontent->x509certURLRequester->setEnabled(false); + newprofilewizardcertcontent->CaCertpathURLRequester->setEnabled(true); + newprofilewizardcertcontent->certpathURLRequester->setURL("/etc/racoon/certs"); + newprofilewizardcertcontent->LabelCertificate->setEnabled(false); + newprofilewizardcertcontent->LabelPrivateKeyPath->setEnabled(false); + newprofilewizardcertcontent->LabelPrivateKeyPassword->setEnabled(false); + newprofilewizardcertcontent->SpecialServerCertificateURLRequester->setEnabled(false); + newprofilewizardcertcontent->PrivkeyPasswordEdit->setEnabled(false); + newprofilewizardcertcontent->UseSpecialServerCertificateCheckBox->setEnabled(false); + newprofilewizardcertcontent->privkeypathURLRequester->setEnabled(false); + newprofilewizardpskcontent->setEnabled(false); + + + } + else if ( profileData->getConnectionType() == VpnAccountData::ciscoorig ) + { + insertPage ( newprofilewizardciscomanuallypage, "" + i18n ( "Cisco settings" ) + "", indexOf ( currentpage ) + 1 ); + removePage( newprofilewizardpskpage); + } + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Auth selection: use Hybrid" ), KVpncConfig::debug ); + } + } + else if ( currentpage == newprofilewizardp12certselectionpage ) + { + insertPage ( newprofilewizardcertpage, "" + i18n ( "Certificate settings" ) + "", indexOf ( currentpage ) + 1 ); + + if ( newprofilewizardp12certselectioncontent->UseSmartcardCheckBox->isChecked() ) + { + profileData->setUseSmartcard ( true ); + newprofilewizardcertcontent->UseSmartcardCheckBox->setChecked ( true ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "P12 cert selection: use smartcard" ), KVpncConfig::debug ); + } + else + { + if ( newprofilewizardp12certselectioncontent->P12CertYesRadioButton->isChecked() ) + { + // yes we have p12 cert + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "P12 cert selection: cert type is PKCS12" ), KVpncConfig::debug ); + + if ( importCertificate() ) + { + // success :) + } + else + { + newProfileCreated = false; + } + } + else + { + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "P12 cert selection: cert type is other" ), KVpncConfig::debug ); + } + } + } + else if ( currentpage == newprofilewizardopenvpnselectionpage ) + { + if ( newprofilewizardopenvpnselectionpagecontent->OpenvpnImportRadioButton->isChecked() ) + { + enterdatamanually = false; + removePage ( newprofilewizardopenvpnpage ); + removePage ( newprofilewizardopenvpnauthpage ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "OpenVPN selection: import profile file" ), KVpncConfig::debug ); + + // removePage ( newprofilewizardgeneralpage ); + removePage ( newprofilewizardvirtualipaddresspage ); + + if ( importProfile ( VpnAccountData::openvpn ) == true ) + { + newProfileCreated = true; + newprofilewizardgeneralpagecontent->NameLineEdit->setText ( profileData->getName() ); + newprofilewizardgeneralpagecontent->gatewayLineEdit->setText ( profileData->getGateway() ); + newprofilewizardgeneralpagecontent->DescriptionLineEdit->setText ( profileData->getDescription() ); + + if ( profileData->getAuthWithUsernameAndPassword() ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "OpenVPN auth: authenticate with username and password" ), KVpncConfig::debug ); + insertPage ( newprofilewizarduserpage, "" + i18n ( "User settings" ) + "", indexOf ( currentpage ) + 1 ); + } + } + else + { + newProfileCreated = false; + ok = false; + } + } + else + { + enterdatamanually = true; + insertPage ( newprofilewizardopenvpnpage, "" + i18n ( "OpenVPN settings" ) + "", indexOf ( currentpage ) + 1 ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "OpenVPN selection: enter data manually" ), KVpncConfig::debug ); + } + + } + else if ( currentpage == newprofilewizardopenvpnauthpage ) + { + if ( newprofilewizardopenvpnauthpagecontent->AuthWithUsernameAndPasswordCheckBox->isChecked() ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "OpenVPN auth: authenticate with username and password" ), KVpncConfig::debug ); + insertPage ( newprofilewizarduserpage, "" + i18n ( "User settings" ) + "", indexOf ( currentpage ) + 1 ); + + profileData->setAuthWithUsernameAndPassword ( true ); + + if ( newprofilewizardopenvpnauthpagecontent->UseOnlyCaCertAndUserAuthCheckBox->isChecked() ) + { + profileData->setUseOnlyCaCertAndUserAuth ( true ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "OpenVPN auth: use only CA cert authenticate with username and password" ), KVpncConfig::debug ); + } + else + { + profileData->setUseOnlyCaCertAndUserAuth ( false ); + + } + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "OpenVPN auth: dont authenticate with username and password" ), KVpncConfig::debug ); + + profileData->setAuthWithUsernameAndPassword ( false ); + profileData->setUseOnlyCaCertAndUserAuth ( false ); + } + + if ( newprofilewizardopenvpnauthpagecontent->UseAuthenticationAlgorithmCheckBox->isChecked() ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "OpenVPN auth: use special authentication algorithm: %1" ).arg ( newprofilewizardopenvpnauthpagecontent->UserdefiniedDigestComboBox->currentText() ), KVpncConfig::debug ); + profileData->setUseAuthenticationAlgorithm ( true ); + profileData->setAuthenticationAlgorithm ( newprofilewizardopenvpnauthpagecontent->UserdefiniedDigestComboBox->currentText() ); + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "OpenVPN auth: dont use special authentication algorithm" ), KVpncConfig::debug ); + profileData->setUseAuthenticationAlgorithm ( false ); + } + + profileData->setAuthenticationAlgorithm ( newprofilewizardopenvpnauthpagecontent->UserdefiniedDigestComboBox->currentText() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "OpenVPN auth: use authentication method: %1" ).arg ( profileData->getAuthenticationAlgorithm() ), KVpncConfig::debug ); + + + } + else if ( currentpage == newprofilewizardpptppage ) + { + + msg = i18n ( "These fields must be filled in:\n" ); + profileData->setAllowStatefulMode( newprofilewizardpptppagecontent->AllowStatefulModeCheckbox->isChecked() ); + profileData->setUseNoIpDefault( newprofilewizardpptppagecontent->UseNoIpDefaultCheckbox->isChecked() ); + profileData->setDisableMPPEComp( newprofilewizardpptppagecontent->UseNoMPPECompressionCheckbox->isChecked() ); + profileData->setRequireMppe( newprofilewizardpptppagecontent->RequireMppeCheckbox->isChecked() ); + profileData->setRefuse128BitEncryption( newprofilewizardpptppagecontent->Refuse128BitEncryptionCheckbox->isChecked() ); + profileData->setRefuse40BitEncryption( newprofilewizardpptppagecontent->Refuse40BitEncryptionCheckbox->isChecked() ); + profileData->setDisableMPPEComp( newprofilewizardpptppagecontent->UseNoMPPECompressionCheckbox->isChecked() ); + profileData->setUseNoBsdComp( newprofilewizardpptppagecontent->UseNoBsdCompCheckbox->isChecked() ); + profileData->setUseNoDeflate( newprofilewizardpptppagecontent->UseNoDeflateCheckbox->isChecked() ); + profileData->setDisableHeaderCompression(newprofilewizardpptppagecontent->DisableHeaderCompressionCheckbox->isChecked()); + profileData->setDisableMagicNumberNegotiation(newprofilewizardpptppagecontent->DisableMagicNumberNegotiationCheckbox->isChecked()); + profileData->setDisableIpx(newprofilewizardpptppagecontent->DisableIpxCheckbox->isChecked()); + profileData->setDisableAdressControlCompression(newprofilewizardpptppagecontent->DisableAdressControlCompressionCheckbox->isChecked()); + profileData->setDisableProtocolFieldCompression(newprofilewizardpptppagecontent->DisableProtocolFieldCompressionCheckbox->isChecked()); + profileData->setRequireEap(newprofilewizardpptppagecontent->RequireEapCheckbox->isChecked()); + + if ( newprofilewizardpptppagecontent->DnsServerCheckbox->isChecked() ) + { + profileData->setUseDnsServer( true ); + profileData->setDnsServer( newprofilewizardpptppagecontent->DnsServerLineedit->text() ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Using custom DNS server: %1" ).arg ( profileData->getDnsServer() ), KVpncConfig::debug ); + } + else + { + profileData->setUseDnsServer( false ); + } + + if ( newprofilewizardpptppagecontent->UseSearchDomainInResolvConfCheckbox ->isChecked() ) + { + profileData->setUseSearchDomainInResolvConf(true); + profileData->setSearchDomainInResolvConf(newprofilewizardpptppagecontent->SearchDomainInResolvConfLineedit->text()); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Using custom DNS search domain: %1" ).arg ( profileData->getSearchDomainInResolvConf() ), KVpncConfig::debug ); + } + else + { + profileData->setUseSearchDomainInResolvConf(false); + } + + if ( newprofilewizardpptppagecontent->UseDomainInResolvConfCheckbox ->isChecked() ) + { + profileData->setUseDomainInResolvConf(true); + profileData->setDomainInResolvConf(newprofilewizardpptppagecontent->DomainInResolvConfLineedit->text()); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Using custom DNS domain: %1" ).arg ( profileData->getDomainInResolvConf() ), KVpncConfig::debug ); + } + else + { + profileData->setUseDomainInResolvConf(false); + } + + if ( newprofilewizardpptppagecontent->AuthMethodComboBox->currentItem() == 0 ) + profileData->setAuthMethod ( "chap" ); + if ( newprofilewizardpptppagecontent->AuthMethodComboBox->currentItem() == 1 ) + profileData->setAuthMethod ( "pap" ); + if ( newprofilewizardpptppagecontent->AuthMethodComboBox->currentItem() == 2 ) + profileData->setAuthMethod ( "mschap" ); + if ( newprofilewizardpptppagecontent->AuthMethodComboBox->currentItem() == 3 ) + profileData->setAuthMethod ( "mschap-v2" ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Using auth method: %1" ).arg ( profileData->getAuthMethod() ), KVpncConfig::debug ); + + newprofilewizardnetworkcontent->LabelRemoteNetwork->hide(); + newprofilewizardnetworkcontent->RemoteNetMaskComboBox->hide(); + newprofilewizardnetworkcontent->RemoteNetAddrLineEdit->hide(); + newprofilewizardnetworkcontent->RemoteNetDividetextLabel->hide(); + newprofilewizardnetworkcontent->UseRemoteNetworkCheckBox->hide(); + newprofilewizardnetworkcontent->RemoteNetworkGroupBox->hide(); + + insertPage ( newprofilewizarduserpage, "" + i18n ( "User settings" ) + "", indexOf ( currentpage ) + 1 ); + + } + else if ( currentpage == newprofilewizardvtunpage ) + { + msg = i18n ( "These fields must be filled in:\n" ); + profileData->setUseLocalPort ( newprofilewizardvtunpagecontent->PortCheckbox->isChecked() ); + profileData->setLocalPort ( newprofilewizardvtunpagecontent->PortSpinbox->value() ); + + if ( newprofilewizardvtunpagecontent->PortCheckbox->isChecked() ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Vtun: use userdefined port: %1" ).arg ( QString().setNum ( newprofilewizardvtunpagecontent->PortSpinbox->value() ) ), KVpncConfig::debug ); + } + + if ( newprofilewizardvtunpagecontent->VtunProfileLineEdit->text().isEmpty() ) + { + KMessageBox::error ( this, i18n ( "No profile name entered!" ), i18n ( "No profile name" ) ); + ok = false; + msg += "- " + i18n ( "Vtun profile name" ) + "\n"; + GlobalConfig->appendLogEntry ( i18n ( "No profile name entered!" ), GlobalConfig->error ); + } + else + profileData->setVtunProfile ( newprofilewizardvtunpagecontent->VtunProfileLineEdit->text() ); + } + else if ( currentpage == newprofilewizardsshpage ) + { + msg = i18n ( "These fields must be filled in:\n" ); + profileData->setUseRemotePort( newprofilewizardsshpagecontent->UseUserdefinedRemotePortCheckBox->isChecked() ); + profileData->setRemotePort ( newprofilewizardsshpagecontent->UserdefinedRemotePortSpinBox->value() ); + + if ( newprofilewizardsshpagecontent->UseUserdefinedRemotePortCheckBox->isChecked() ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "SSH: use userdefined port: %1" ).arg ( QString().setNum ( newprofilewizardsshpagecontent->UserdefinedRemotePortSpinBox->value() ) ), KVpncConfig::debug ); + } + + // password or key auth + if (newprofilewizardsshpagecontent->AuthPassRadioButton->isChecked()) + { + profileData->setAuthWithUsernameAndPassword(true); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "SSH: use user password authentication" ) , KVpncConfig::debug ); + } + else + { + profileData->setAuthWithUsernameAndPassword(false); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "SSH: use key authentication" ) , KVpncConfig::debug ); + } + + profileData->setPreSharedKeyFile(newprofilewizardsshpagecontent->CostumkeyURLRequester->url()); + + if (newprofilewizardsshpagecontent->CostumKeyRadioButton->isChecked()) + { + profileData->setPskIsInFile(newprofilewizardsshpagecontent->CostumKeyRadioButton->isChecked()); + profileData->setPreSharedKeyFile(newprofilewizardsshpagecontent->CostumkeyURLRequester->url()); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "SSH: use costum key: %1" ).arg(newprofilewizardsshpagecontent->CostumkeyURLRequester->url()) , KVpncConfig::debug ); + } + else + { + profileData->setPreSharedKey(newprofilewizardsshpagecontent->SshKeyComboBox->currentText()); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "SSH: use autotected key: %1" ).arg(newprofilewizardsshpagecontent->SshKeyComboBox->currentText()) , KVpncConfig::debug ); + } + + if (newprofilewizardsshpagecontent->UseSshConfigRemoteScriptCheckBox->isChecked() && !newprofilewizardsshpagecontent->SshConfigRemoteScriptLineEdit->text().isEmpty()) + { + profileData->setUseSshConfigRemoteScript(true); + profileData->setSshConfigRemoteScript(newprofilewizardsshpagecontent->SshConfigRemoteScriptLineEdit->text()); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "SSH: use ssh config remote script: %1" ).arg(newprofilewizardsshpagecontent->SshConfigRemoteScriptLineEdit->text()) , KVpncConfig::debug ); + + } + else + profileData->setUseSshConfigRemoteScript(false); + + if (newprofilewizardsshpagecontent->UseSshConfigRemoteScriptCheckBox->isChecked() && newprofilewizardsshpagecontent->SshConfigRemoteScriptLineEdit->text().isEmpty()) + { + ok = false; + msg += "- " + i18n ( "Special server certificate" ) + "\n"; + GlobalConfig->appendLogEntry( i18n( "%1 cant be empty!" ).arg(i18n("ssh config remote script")), GlobalConfig->error); + } + + } + else if ( currentpage == newprofilewizardvirtualipaddresspage ) + { + msg = i18n ( "These fields must be filled in:\n" ); + bool IPOk=true; + QString wrongAddress=""; + ok = true; + + if ( profilenetworkvirtualipoptionscontent->UseVirtualIPCheckBox->isChecked() && !profilenetworkvirtualipoptionscontent->LocalVirtualIpEdit->text().isEmpty() ) + { + QString LocalVirtualIp = profilenetworkvirtualipoptionscontent->LocalVirtualIpEdit->text(); + if ( Utils ( GlobalConfig ).isValidIPv4Address ( LocalVirtualIp ) == false ) + { + // KMessageBox::error ( this, i18n( "No valid IP address for local IP address entered!" ), i18n( "No Valid IP Address" ) ); + IPOk=false; + wrongAddress=i18n ( "local IP address" ); + ok=false; + } + else + { + profileData->setLocalVirtualIP ( LocalVirtualIp ); + } + } + else + { + msg += "- " + i18n ( "Local IP address for virtual IP" ) + "\n"; + ok =false; + IPOk=false; + } + + if ( profileData->getConnectionType() != VpnAccountData::openvpn || profileData->getConnectionType() != VpnAccountData::ssh ) + { + if(profileData->getTunnelDeviceType() == "tun") + { + if ( profilenetworkvirtualipoptionscontent->UseVirtualIPCheckBox->isChecked() && !profilenetworkvirtualipoptionscontent->RemoteVirtualIpLineEdit->text().isEmpty() ) + { + QString RemoteVirtualIp = profilenetworkvirtualipoptionscontent->RemoteVirtualIpLineEdit->text(); + if ( Utils ( GlobalConfig ).isValidIPv4Address ( RemoteVirtualIp ) == false ) + { + + IPOk=false; + ok=false; + if ( wrongAddress=="" ) + wrongAddress = i18n ( "remote IP address" ); + else + wrongAddress = i18n ( "local and remote IP address" ); + } + else + { + profileData->setRemoteVirtualIP ( RemoteVirtualIp ); + } + } + else + { + msg += "- " + i18n ( "Remote IP address for virtual IP" ) + "\n"; + ok =false; + IPOk=false; + + } + } + if (profileData->getTunnelDeviceType() == "tap") + { + QString RemoteVirtualIp = profilenetworkvirtualipoptionscontent->RemoteVirtualIpLineEdit->text(); + if (Utils( GlobalConfig ).isValidIPv4Netmask (RemoteVirtualIp) == false) + { + KMessageBox::error ( this, i18n( "No valid netmask entered!" ), i18n( "No valid netmask" ) ); + IPOk=false; + } + else + { + profileData->setRemoteVirtualIP( RemoteVirtualIp); + } + } + } + + + if ( profilenetworkvirtualipoptionscontent->UseVirtualIPCheckBox->isChecked() && IPOk ) + { + profileData->setUseVirtualIP ( profilenetworkvirtualipoptionscontent->UseVirtualIPCheckBox->isChecked() ); + + if ( profilenetworkvirtualipoptionscontent->UseVirtualIPCheckBox->isChecked() ) + { + + if (profileData->getTunnelDeviceType() == "tun") + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Using virtual IP addresses (local: %1, remote: %2): " ).arg ( profileData->getLocalVirtualIP() ).arg ( profileData->getRemoteVirtualIP() ), KVpncConfig::debug ); + } + if (profileData->getTunnelDeviceType() == "tap") + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Using virtual IP address (local: %1, netmask: %2): " ).arg ( profileData->getLocalVirtualIP() ).arg ( profileData->getRemoteVirtualIP() ), KVpncConfig::debug ); + } + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Not using virtual IP addresses" ), KVpncConfig::debug ); + } + } + else + { + if ( wrongAddress!= "" ) + KMessageBox::error ( this, i18n ( "No valid IP address for %1 entered!" ).arg ( wrongAddress ), i18n ( "No Valid IP Address" ) ); + profileData->setUseVirtualIP ( false ); + } + + if ( !profilenetworkvirtualipoptionscontent->UseVirtualIPCheckBox->isChecked() ) + ok=true; + + } + else if ( currentpage == newprofilewizardpskpage ) + { + msg = i18n ( "These fields must be filled in:\n" ); + if ( newprofilewizardpskcontent->CheckSavePsk->isChecked() ) + { + if ( !newprofilewizardpskcontent->PskInFileCheckBox->isChecked() ) + { + profileData->setSavePsk ( true ); + profileData->setPskIsInFile ( false ); + if ( !newprofilewizardpskcontent->PSKLineEdit->text().isEmpty() ) + { + profileData->setPreSharedKey ( newprofilewizardpskcontent->PSKLineEdit->text() ); + } + else + { + msg += "- " + i18n ( "Pre shared key" ) + "\n"; + ok = false; + } + } + else + { + profileData->setSavePsk ( true ); + profileData->setPskIsInFile ( true ); + if ( !newprofilewizardpskcontent->PSKFileURLRequester->url().isEmpty() ) + { + profileData->setPreSharedKey ( newprofilewizardpskcontent->PSKLineEdit->text() ); + } + else + { + ok = false; + msg += "- " + i18n ( "Pre shared key file" ) + "\n"; + } + } + + } + else + { + profileData->setSavePsk ( false ); + } + + if ( newprofilewizardpskcontent->PskInFileCheckBox->isChecked() ) + { + profileData->setSavePsk ( newprofilewizardpskcontent->CheckSavePsk->isChecked() ); + if ( !newprofilewizardpskcontent->PSKFileURLRequester->url().isEmpty() ) + { + profileData->setPreSharedKeyFile ( newprofilewizardpskcontent->PSKFileURLRequester->url() ); + } + else + { + ok = false; + msg += "- " + i18n ( "Pre shared key file" ) + "\n"; + } + } + if ( newprofilewizardpskcontent->CheckSavePsk->isChecked() ) + profileData->setPreSharedKey ( newprofilewizardpskcontent->PSKLineEdit->text( ) ); + else + profileData->setPreSharedKey ( "" ); + + profileData->setPreSharedKey ( newprofilewizardpskcontent->PSKLineEdit->text() ); + + } + else if ( currentpage == newprofilewizardcertpage ) + { + + profileData->setX509Certificate ( newprofilewizardcertcontent->x509certURLRequester->url() ); + profileData->setCaCertificate ( newprofilewizardcertcontent->CaCertpathURLRequester->url() ); + profileData->setCertPath ( newprofilewizardcertcontent->certpathURLRequester->url() ); + profileData->setPrivateKey ( newprofilewizardcertcontent->privkeypathURLRequester->url() ); + profileData->setPrivateKeyPass ( newprofilewizardcertcontent->PrivkeyPasswordEdit->text() ); + profileData->setX509Certificate ( newprofilewizardcertcontent->x509certURLRequester->url() ); + profileData->setCertPath ( newprofilewizardcertcontent->certpathURLRequester->url() ); + profileData->setUseSpecialServerCertificate ( newprofilewizardcertcontent->UseSpecialServerCertificateCheckBox->isChecked() ); + profileData->setSpecialServerCertificate ( newprofilewizardcertcontent->SpecialServerCertificateURLRequester->url() ); + + if ( !newprofilewizardcertcontent->PrivkeyPasswordEdit->text().isEmpty() ) + profileData->setSavePrivateKeyPassword ( true ); + else + profileData->setSavePrivateKeyPassword ( false ); + + msg = i18n ( "These fields must be filled in:\n" ); + + if ( newprofilewizardcertcontent->UseSpecialServerCertificateCheckBox->isChecked() ) + { + if ( newprofilewizardcertcontent->SpecialServerCertificateURLRequester->url().isEmpty() ) + { + ok = false; + msg += "- " + i18n ( "Special server certificate" ) + "\n"; + // KMessageBox::error ( this, i18n( "Special server certificate can't be empty!" ), i18n( "No Server Certificate" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Special server certificate can't be empty!" ) , GlobalConfig->error ); + } + } + + if ( newprofilewizardcertcontent->CaCertpathURLRequester->url().isEmpty() ) + { + ok = false; + msg += "- " + i18n ( "CA certificate" ) + "\n"; + GlobalConfig->appendLogEntry ( i18n ( "CA Certificate can't be empty!" ) , GlobalConfig->error ); + } + + if ( !newprofilewizardcertcontent->UseSmartcardCheckBox->isChecked() && !profileData->getAuthType() == VpnAccountData::hybrid) + { + if ( (!profileData->getUseOnlyCaCertAndUserAuth() && newprofilewizardcertcontent->x509certURLRequester->url().isEmpty()) || ( profileData->getConnectionType() == VpnAccountData::ciscoorig && newprofilewizardcertcontent->x509certURLRequester->url().isEmpty())) + { + ok = false; + msg += "- " + i18n ( "Certificate" ) + "\n"; + GlobalConfig->appendLogEntry ( i18n ( "Certificate can't be empty!" ) , GlobalConfig->error ); + } + + if ( !profileData->getUseOnlyCaCertAndUserAuth() && newprofilewizardcertcontent->privkeypathURLRequester->url().isEmpty() && !profileData->getAuthType() == VpnAccountData::hybrid) + { + ok = false; + msg += "- " + i18n ( "Path to private key" ) + "\n"; + GlobalConfig->appendLogEntry ( i18n ( "Path to private key can't be empty!" ) , GlobalConfig->error ); + } +// if ( ! ( profileData->getConnectionType() == VpnAccountData::racoon || profileData->getConnectionType() == VpnAccountData::l2tpd_racoon ) && !profileData->getUseOnlyCaCertAndUserAuth() && newprofilewizardcertcontent->PrivkeyPasswordEdit->text().isEmpty() ) +// { +// if ( Utils ( GlobalConfig ).getNeedsPassphrase ( newprofilewizardcertcontent->privkeypathURLRequester->url() ) ) +// { +// ok = false; +// msg += "- " + i18n ( "Private key password, private key needs passphrase" ) + "\n"; +// GlobalConfig->appendLogEntry ( i18n ( "Private key password can't be empty because private key is protected with a passphrase." ) , GlobalConfig->error ); +// } +// } + + } + else + { + if ( newprofilewizardcertcontent->Pkcs11SlotComboBox->currentText().isEmpty() || newprofilewizardcertcontent->Pkcs11IdComboBox->currentText().isEmpty() ) + nextButton()->setEnabled ( false ); + else + nextButton()->setEnabled ( true ); + } + + if ( newprofilewizardcertcontent->UseSmartcardCheckBox->isEnabled() && newprofilewizardcertcontent->UseSmartcardCheckBox->isChecked() ) + { + if ( !newprofilewizardcertcontent->Pkcs11SlotComboBox->currentText().isEmpty() ) + profileData->setPkcs11Slot ( newprofilewizardcertcontent->Pkcs11SlotComboBox->currentText() ); + else + { + KMessageBox::error ( this, i18n ( "Slot at smartcard can't be empty!" ), i18n ( "No smartcard slot" ) ); + // GlobalConfig->appendLogEntry( i18n( "Slot at smartcard can't be empty!" ) ,GlobalConfig->error); + ok = false; + } + if ( !newprofilewizardcertcontent->Pkcs11IdComboBox->currentText().isEmpty() ) + profileData->setPkcs11Id ( newprofilewizardcertcontent->Pkcs11IdComboBox->currentText() ); + else + { + KMessageBox::error ( this, i18n ( "ID for certificate at smartcard can't be empty!" ), i18n ( "No certificate ID" ) ); + // GlobalConfig->appendLogEntry( i18n( "ID for certificate at smartcard can't be empty!" ) ,GlobalConfig->error); + ok = false; + } + QString Pkcs11SlotType = newprofilewizardcertcontent->Pkcs11SlotTypeComboBox->currentText(); + if ( Pkcs11SlotType == i18n ( "ID" ) ) + profileData->setPkcs11SlotType ( "id" ); + else if ( Pkcs11SlotType == i18n ( "Name" ) ) + profileData->setPkcs11SlotType ( "name" ); + else + profileData->setPkcs11SlotType ( "label" ); + + QString Pkcs11IdType = newprofilewizardcertcontent->Pkcs11IdTypeComboBox->currentText(); + if ( Pkcs11IdType == i18n ( "ID" ) ) + profileData->setPkcs11IdType ( "id" ); + else if ( Pkcs11IdType == i18n ( "Label" ) ) + profileData->setPkcs11IdType ( "label" ); + else + profileData->setPkcs11IdType ( "subject" ); + + QString Pkcs11SignMode = newprofilewizardcertcontent->Pkcs11SignModeComboBox->currentText(); + if ( Pkcs11SignMode == i18n ( "auto" ) ) + profileData->setPkcs11SignMode ( "auto" ); + else if ( Pkcs11SignMode == i18n ( "sign" ) ) + profileData->setPkcs11SignMode ( "sign" ); + else if ( Pkcs11SignMode == i18n ( "recover" ) ) + profileData->setPkcs11SignMode ( "recover" ); + else + profileData->setPkcs11SignMode ( "any" ); + + if ( newprofilewizardcertcontent->UsePkcs11ProvidersCheckBox->isChecked() ) + { + if ( !newprofilewizardcertcontent->Pkcs11ProvidersURLRequester->url().isEmpty() ) + profileData->setPkcs11Providers ( newprofilewizardcertcontent->Pkcs11ProvidersURLRequester->url() ); + else + { + KMessageBox::error ( this, i18n ( "Library path to lib for use with smartcard can't be empty!" ), i18n ( "No providers lib" ) ); + // GlobalConfig->appendLogEntry( i18n( "Library path to lib for use with smartcard can't be empty!" ) ,GlobalConfig->error); + ok = false; + } + } + profileData->setUsePkcs11Providers ( newprofilewizardcertcontent->UsePkcs11ProvidersCheckBox->isChecked() ); + } + + } + else if ( currentpage == newprofilewizarduserpage ) + { + msg = i18n ( "These fields must be filled in:\n" ); + if ( newprofilewizarduserpagecontent->UsernameLineEdit->text().isEmpty() ) + { + ok = false; + msg += "- " + i18n ( "Username" ) + "\n"; + GlobalConfig->appendLogEntry ( i18n ( "Username is empty!" ), GlobalConfig->error ); + } + else + { + profileData->setUserName ( newprofilewizarduserpagecontent->UsernameLineEdit->text() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "User options: username: %1" ).arg ( profileData->getUserName() ), KVpncConfig::debug ); + } + + if ( !newprofilewizarduserpagecontent->PasswordEdit->text().isEmpty() ) + { + profileData->setUserPassword ( newprofilewizarduserpagecontent->PasswordEdit->text() ); + + } + else + { + if ( newprofilewizarduserpagecontent->CheckUserPass->isChecked() ) + { + ok = false; + msg += "- " + i18n ( "Password" ) + "\n"; + GlobalConfig->appendLogEntry ( i18n ( "Password is empty but you have checked to store it!" ), GlobalConfig->error ); + } + } + profileData->setUserPassword ( newprofilewizarduserpagecontent->PasswordEdit->text() ); + profileData->setSaveUserPassword ( newprofilewizarduserpagecontent->CheckUserPass->isChecked() ); + + profileData->setNtDomainName ( newprofilewizarduserpagecontent->NtDomainNameLineedit->text() ); + + + if ( profileData->getConnectionType () == VpnAccountData::cisco || profileData->getConnectionType() == VpnAccountData::pptp || + profileData->getConnectionType () == VpnAccountData::l2tpd_racoon || profileData->getConnectionType() == VpnAccountData::l2tpd_freeswan + ) + { + if ( newprofilewizarduserpagecontent->NtDomainNameCheckbox->isChecked() ) + { + if ( newprofilewizarduserpagecontent->NtDomainNameLineedit->text().isEmpty() ) + { + ok = false; + msg += "- " + i18n ( "NT domain name" ) + "\n"; + GlobalConfig->appendLogEntry ( i18n ( "NT domain name is empty but you have checked to specifiy one!" ), GlobalConfig->error ); + } + else + { + profileData->setNtDomainName ( newprofilewizarduserpagecontent->NtDomainNameLineedit->text() ); + profileData->setUseNtDomainName ( true ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "User options: NT domain name: %1" ).arg ( profileData->getNtDomainName() ), KVpncConfig::debug ); + } + } + else + { + profileData->setUseNtDomainName ( false ); + } + } + } + else if ( currentpage == newprofilewizardnetworkpage ) + { + msg = i18n ( "These fields must be filled in:\n" ); + bool validAddr = true; + if ( ( profileData->getConnectionType() == VpnAccountData::freeswan || profileData->getConnectionType() == VpnAccountData::racoon || + profileData->getConnectionType() == VpnAccountData::l2tpd_freeswan || profileData->getConnectionType() == VpnAccountData::l2tpd_racoon ) ) + { + if (newprofilewizardnetworkcontent->UseRemoteNetworkCheckBox->isChecked()) + { + if ( !newprofilewizardnetworkcontent->RemoteNetAddrLineEdit->text().isEmpty() ) + { + if ( newprofilewizardnetworkcontent->RemoteNetAddrLineEdit->text().contains ( '.' ) != 3 ) + { + KMessageBox::error ( this, i18n ( "No remote network entered!" ), i18n ( "No remote network" ) ); + validAddr = false; + return ; + } + else + { + QString addr = newprofilewizardnetworkcontent->RemoteNetAddrLineEdit->text(); + int part0 = addr.section ( '.', 0, 0 ).toInt(); + int part1 = addr.section ( '.', 1, 1 ).toInt(); + int part2 = addr.section ( '.', 2, 2 ).toInt(); + int part3 = addr.section ( '.', 3, 3 ).toInt(); + + /* + LogOutput->append ("part0: "+QString().setNum(part0)); + LogOutput->append ("part1: "+QString().setNum(part1)); + LogOutput->append ("part2: "+QString().setNum(part2)); + LogOutput->append ("part3: "+QString().setNum(part3)); + */ + + if ( ( part0 < 1 || part0 > 254 ) || ( part1 < 0 || part1 > 254 ) || ( part2 < 0 || part2 > 254 ) || ( part3 < 0 || part3 > 254 ) ) + { + KMessageBox::error ( this, i18n ( "Invalid values in IP address (remote net)!" ), i18n ( "Invalid Values in IP Address" ) ); + GlobalConfig->appendLogEntry ( i18n ( "Invalid values in IP address (remote net)!" ) , GlobalConfig->error ); + validAddr = false; + return ; + } + + if ( validAddr == true ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Use remote network: %1/%2" ).arg ( addr ).arg(newprofilewizardnetworkcontent->RemoteNetMaskComboBox->currentText()), KVpncConfig::debug ); + profileData->setUseRemoteNetwork(true); + profileData->setRemoteNetAddr ( addr ); + profileData->setRemoteNetMask ( newprofilewizardnetworkcontent->RemoteNetMaskComboBox->currentText() ); + } + + } + } + else + { + ok = false; + msg += "- " + i18n ( "Remote network" ) + "\n"; + GlobalConfig->appendLogEntry ( i18n ( "Remote network is empty!" ), GlobalConfig->error ); + } + } + } + profileData->setNetworkDevice ( newprofilewizardnetworkcontent->NetworkDeviceComboBox->currentText() ); + + profileData->setMtu ( newprofilewizardnetworkcontent->MtuSpinbox->value() ); + if ( newprofilewizardnetworkcontent->MtuCheckbox->isChecked() ) + { + profileData->setUseMtu ( true ); + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Network options: use own MTU size: %1" ).arg ( profileData->getMtu() ) , GlobalConfig->debug ); + } + else + profileData->setUseMtu ( false ); + + profileData->setMru ( newprofilewizardnetworkcontent->MruSpinbox->value() ); + if ( newprofilewizardnetworkcontent->MruCheckbox->isChecked() ) + { + profileData->setUseMru ( true ); + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Network options: use own MRU size: %1" ).arg ( profileData->getMtu() ) , GlobalConfig->debug ); + } + else + profileData->setUseMru ( false ); + + if ( profileData->getConnectionType() == VpnAccountData::ssh ) + { + profileData->setTunnelDeviceType(newprofilewizardnetworkcontent->TunnelDeviceTypeComboBox->currentText()); + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Network options: Tunnel device type: %1" ).arg ( profileData->getTunnelDeviceType() ) , GlobalConfig->debug ); + + tunnelDeviceTypeChanged(profileData->getTunnelDeviceType()); + } + + } + else if ( currentpage == newprofilewizardnetworkroutepage ) + { + msg = i18n ( "These fields must be filled in:\n" ); + + if ( newprofilewizardnetworkroutecontent->DefaultRouteComboBox->currentItem() == 1 ) + { + profileData->setReplaceDefaultRoute ( true ); + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Network route options: replace default route" ) , GlobalConfig->debug ); + } + else + { + profileData->setReplaceDefaultRoute ( false ); + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Network route options: dont replace default route" ) , GlobalConfig->debug ); + } + + profileData->setUseAdditionalNetworkRoutes ( newprofilewizardnetworkroutecontent->UseExtraNetworkRoutesCheckbox->isChecked() ); + + if ( newprofilewizardnetworkroutecontent->UseExtraNetworkRoutesCheckbox->isChecked() && newprofilewizardnetworkroutecontent->NetworkListView->childCount() > 0 ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Network route options: use additional network routes" ) , GlobalConfig->debug ); + + QStringList AdditionalNetworkRoutes; + QListViewItemIterator it ( newprofilewizardnetworkroutecontent->NetworkListView ); + for ( ; it.current(); ++it ) + { + // example entry: + // /# + QString network = QString ( it.current() ->text ( 0 ) + "/" + it.current() ->text ( 1 ) ); + network.append ( "#" ); + network.append ( it.current() ->text ( 2 ) ); // gateway + network.append ( "#" ); + network.append ( it.current() ->text ( 3 ) ); // interface + AdditionalNetworkRoutes.append ( network ); + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Network route options: additional network: %1/%2 gw %3 %4" ).arg ( it.current() ->text ( 0 ) ).arg ( it.current() ->text ( 1 ) ).arg ( it.current() ->text ( 2 ) ).arg ( it.current() ->text ( 3 ) ) , GlobalConfig->debug ); + } + profileData->setAdditionalNetworkRoutes ( AdditionalNetworkRoutes ); + } + + } + else if ( currentpage == newprofilewizardnatpage ) + { + profileData->setUseUdp ( newprofilewizardnatcontent->UseUdpCheckbox->isChecked() ); + profileData->setUseNat ( newprofilewizardnatcontent->UseNatCheckbox->isChecked() ); + profileData->setUseUdpPort ( newprofilewizardnatcontent->UdpPortCheckbox->isChecked() ); + profileData->setUdpPort ( newprofilewizardnatcontent->UdpPortSpinbox->value() ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + { + if ( profileData->getUseNat() ) + GlobalConfig->appendLogEntry ( i18n ( "NAT settings: use NAT" ), KVpncConfig::debug ); + else + GlobalConfig->appendLogEntry ( i18n ( "NAT settings: use no NAT" ), KVpncConfig::debug ); + if ( profileData->getUseUdp() ) + GlobalConfig->appendLogEntry ( i18n ( "NAT settings: use UDP" ), KVpncConfig::debug ); + else + GlobalConfig->appendLogEntry ( i18n ( "NAT settings: use UDP" ), KVpncConfig::debug ); + + if ( profileData->getUseUdpPort() ) + GlobalConfig->appendLogEntry ( i18n ( "NAT settings: use userdefined Port: %1" ).arg ( QString().setNum ( profileData->getUdpPort() ) ), KVpncConfig::debug ); + } + + + } + else if ( currentpage == newprofilewizardconnectoptionspage ) + { + connectaftercreating = newprofilewizardconnectoptionscontent->ConnectAfterCreatingProfileCheckBox->isChecked(); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + if ( connectaftercreating ) + GlobalConfig->appendLogEntry ( i18n ( "Connect options: connecting to profile \"%1\" after creating it." ).arg ( profileData->getName() ) , GlobalConfig->debug ); + + } + else if ( currentpage == newprofilewizardconnectionstatuscheckpage ) + { + msg = i18n ( "These fields must be filled in:\n" ); + if ( newprofilewizardconnectionstatuscheckcontent->UseConnectionStatusCheckCheckBox->isChecked() ) + { + profileData->setUseConnectionStatusCheck ( true ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Connection status check: use connection status check" ), KVpncConfig::debug ); + } + else + { + profileData->setUseConnectionStatusCheck ( false ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Connection status check: dont use connection status check" ), KVpncConfig::debug ); + } + + if ( newprofilewizardconnectionstatuscheckcontent->DoReconnectAfterConnectionLostCheckBox->isChecked() ) + { + profileData->setDoReconnectAfterConnectionLost ( true ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Connection status check: do reconnect after connection lost" ), KVpncConfig::debug ); + } + else + { + profileData->setDoReconnectAfterConnectionLost ( false ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Connection status check: dont reconnect after connection lost" ), KVpncConfig::debug ); + } + + if ( newprofilewizardconnectionstatuscheckcontent->PingUserdefiniedAddressCheckBox->isChecked() ) + { + profileData->setDoPingIP ( true ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Connection status check: ping userdefined IP address" ), KVpncConfig::debug ); + } + else + { + profileData->setDoPingIP ( false ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( i18n ( "Connection status check: dont ping userdefined IP address" ), KVpncConfig::debug ); + } + + profileData->setConnectionStatusInterval ( newprofilewizardconnectionstatuscheckcontent->ConnectionStatusCheckIntervalNumInput->value() ); + profileData->setConnectionStatusCheckSuccessCount ( newprofilewizardconnectionstatuscheckcontent->ConnectionStatusSuccessCountNumInput->value() ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + { + GlobalConfig->appendLogEntry ( i18n ( "Connection status check: use connection interval: %1" ).arg ( QString().setNum ( newprofilewizardconnectionstatuscheckcontent->ConnectionStatusCheckIntervalNumInput->value() ) ), KVpncConfig::debug ); + GlobalConfig->appendLogEntry ( i18n ( "Connection status check: success count: %1" ).arg ( QString().setNum ( newprofilewizardconnectionstatuscheckcontent->ConnectionStatusSuccessCountNumInput->value() ) ), KVpncConfig::debug ); + } + + if ( newprofilewizardconnectionstatuscheckcontent->UseConnectionStatusCheckCheckBox->isChecked() ) + { + if ( newprofilewizardconnectionstatuscheckcontent->PingUserdefiniedAddressCheckBox->isChecked() ) + { + if ( !newprofilewizardconnectionstatuscheckcontent->UserdefiniedPingIPLineEdit->text().isEmpty() ) + { + if ( Utils ( GlobalConfig ).isValidIPv4Address ( newprofilewizardconnectionstatuscheckcontent->UserdefiniedPingIPLineEdit->text() ) ) + profileData->setPingHostIP ( newprofilewizardconnectionstatuscheckcontent->UserdefiniedPingIPLineEdit->text() ); + else + { + ok = false; + msg = i18n ( "The value of userdefined IP address is not a valid IP address!" ); + } + } + else + { + ok = false; + msg += i18n ( "Userdefinied IP for ping" ) + "\n"; + } + } + } + } + else if ( currentpage == endpage ) + {} + if ( ok ) + { + previouspage = currentpage; + QWizard::next(); + } + else + { + KMessageBox::error ( this, msg ); + } +} + +void NewProfileWizard::back() +{ + /* + currentpage=previouspage; + // showPage(previouspage); + + if ( currentpage == page1 ) + { + // nothing here + } + else if ( currentpage == newprofilewizardgeneralpage ) + { + newprofilewizardgeneralpagecontent->NameLineEdit->setText(profileData->getName()); + newprofilewizardgeneralpagecontent->gatewayLineEdit->setText(profileData->getGateway()); + newprofilewizardgeneralpagecontent->DescriptionLineEdit->setText(profileData->getDescription()); + } + else if ( currentpage == newprofilewizardtypeselectionpage ) + { + if ( profileData->getConnectionType() == VpnAccountData::cisco ) + newprofilewizardtypeselectionpagecontent->CiscoRadioButton->setChecked(true); + else if ( profileData->getConnectionType() == VpnAccountData::freeswan || + profileData->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + newprofilewizardtypeselectionpagecontent->FreeswanRadioButton->setChecked(true); + else if ( profileData->getConnectionType() == VpnAccountData::racoon || profileData->getConnectionType() == VpnAccountData::l2tpd_racoon) + newprofilewizardtypeselectionpagecontent->FreeswanRadioButton->setChecked(true); + else if ( profileData->getConnectionType() == VpnAccountData::pptp ) + newprofilewizardtypeselectionpagecontent->PptpRadioButton->setChecked(true); + else if ( profileData->getConnectionType() == VpnAccountData::openvpn ) + newprofilewizardtypeselectionpagecontent->OpenvpnRadioButton->setChecked(true); + } + else if ( currentpage == newprofilewizardciscoselectionpage ) + {} + else if ( currentpage == newprofilewizardciscomanuallypage ) + { + newprofilewizardciscomanuallypagecontent->IDLineEdit->setText(profileData->getGateway()); + newprofilewizardciscomanuallypagecontent->AllowEmptyGroupPasswordCheckBox->setChecked(profileData->getAllowEmptyGroupPassword()); + newprofilewizardciscomanuallypagecontent->GroupPasswordLineEdit->setText(profileData->getPreSharedKey()); + profileData->setID(newprofilewizardciscomanuallypagecontent->IDLineEdit->text()); + + insertPage ( newprofilewizardciscoselectionpage, ""+ i18n("Cisco selection")+"", 2 ); + + } + else if ( currentpage == newprofilewizardracoonpage ) + { + newprofilewizardracoonpagecontent->HashAlgoComboBox->setCurrentText(profileData->getHashAlgo()); + + insertPage ( newprofilewizardciscoselectionpage,""+ i18n("Cisco selection")+"" , 2 ); + insertPage ( newprofilewizardciscomanuallypage, ""+ i18n("Cisco settings")+"", 3 ); + insertPage ( newprofilewizardopenvpnselectionpage, ""+ i18n("FreeS/WAN settings") , 4 ); + insertPage ( newprofilewizardopenvpnselectionpage, ""+ i18n("OpenVPN settings")+"" , 5 ); + insertPage ( newprofilewizardpptppage, ""+ i18n("PPTP settings")+"", 6 ); + } + else if ( currentpage == newprofilewizardfreeswanpage ) + { + insertPage ( newprofilewizardciscoselectionpage,""+ i18n("Cisco selection")+"" , 2 ); + insertPage ( newprofilewizardciscomanuallypage, ""+ i18n("Cisco settings")+"", 3 ); + insertPage ( newprofilewizardracoonpage, ""+ i18n("Racoon settings")+"" , 4 ); + insertPage ( newprofilewizardopenvpnselectionpage, ""+ i18n("FreeS/WAN settings") , 4 ); + insertPage ( newprofilewizardpptppage, ""+ i18n("PPTP settings")+"", 5 ); + } + else if ( currentpage == newprofilewizardopenvpnpage ) + { + newprofilewizardopenvpnpagecontent->TunnelDeviceTypeComboBox->setCurrentText(profileData->getTunnelDeviceType() ); + newprofilewizardopenvpnpagecontent->NsCertTypeComboBox->setCurrentText(profileData->getNsCertType()); + newprofilewizardopenvpnpagecontent->TunnelDeviceTypeComboBox->setCurrentText(profileData->getTunnelDeviceType() ); + newprofilewizardopenvpnpagecontent->UseRedirectGatewayCheckBox->setChecked(profileData->getUseRedirectGateway() ); + + newprofilewizardopenvpnpagecontent->UserdefiniedCipherComboBox->setCurrentText(profileData->getUserdefiniedCipher()); + newprofilewizardopenvpnpagecontent->UseUserdefiniedCipherCheckBox->setChecked(profileData->getUseUserdefiniedCipher()); + newprofilewizardopenvpnpagecontent->UseTlsAuthCheckBox->setChecked(profileData->getUseTlsAuth()); + newprofilewizardopenvpnpagecontent->TlsAuthURLRequester->setURL(profileData->getTlsAuthFile()); + + profileData->setUseTlsRemoteHost( newprofilewizardopenvpnpagecontent->UseTlsAuthCheckBox->isChecked()); + profileData->setTlsRemoteHost( newprofilewizardopenvpnpagecontent->TlsRemoteHostLineEdit->text()); + + profileData->setUseHttpProxy( newprofilewizardopenvpnpagecontent->UseHttpProxyCheckBox->isChecked() ); + profileData->setHttpProxy( newprofilewizardopenvpnpagecontent->HttpProxyLineEdit->text( ) ); + profileData->setHttpProxyPort( newprofilewizardopenvpnpagecontent->HttpProxyPortIntNumInput->value( ) ); + profileData->setHttpProxyTimeout( newprofilewizardopenvpnpagecontent->HttpProxyTimeoutIntSpinBox->value() ); + + insertPage ( newprofilewizardciscoselectionpage,""+ i18n("Cisco selection")+"" , 2 ); + insertPage ( newprofilewizardciscomanuallypage, ""+ i18n("Cisco settings")+"", 3 ); + insertPage ( newprofilewizardfreeswanpage, ""+ i18n("Ipsec settings") , 4 ); + insertPage ( newprofilewizardracoonpage, ""+ i18n("Racoon settings")+"" , 5 ); + insertPage ( newprofilewizardpptppage, ""+ i18n("PPTP settings")+"", 6 ); + } + else if ( currentpage == newprofilewizardpptppage ) + { + insertPage ( newprofilewizardciscoselectionpage,""+ i18n("Cisco selection")+"" , 2 ); + insertPage ( newprofilewizardciscomanuallypage, ""+ i18n("Cisco settings")+"", 3 ); + insertPage ( newprofilewizardfreeswanpage, ""+ i18n("IPsec settings") , 4 ); + insertPage ( newprofilewizardracoonpage, ""+ i18n("Racoon settings")+"" , 5 ); + insertPage ( newprofilewizardopenvpnpage, ""+i18n("OpenVPN settings")+"", 6 ); + } + else if ( currentpage == newprofilewizarduserpage ) + { + newprofilewizarduserpagecontent->UsernameLineEdit->setText(profileData->getUserName()); + newprofilewizarduserpagecontent->PasswordEdit->setText(profileData->getUserPassword() ); + newprofilewizarduserpagecontent->CheckUserPass->setChecked(profileData->getSaveUserPassword()); + } + else if ( currentpage == newprofilewizardnetworkpage ) + { + newprofilewizardnetworkcontent->RemoteNetAddrLineEdit->setText(profileData->getRemoteNetAddr() ); + newprofilewizardnetworkcontent->RemoteNetMaskComboBox->setCurrentText(profileData->getRemoteNetMask()); + newprofilewizardnetworkcontent->NetworkDeviceComboBox->setCurrentText(profileData->getNetworkDevice()); + } + else if ( currentpage == newprofilewizardnatpage ) + { + newprofilewizardnatcontent->UseUdpCheckbox->setChecked(profileData->getUseUdp()); + newprofilewizardnatcontent->UdpPortCheckbox->setChecked(profileData->getUseUdpPort ()); + newprofilewizardnatcontent->UdpPortSpinbox->setValue(profileData->getUdpPort()); + } + */ + QWizard::back(); +} + +QString NewProfileWizard::getName() +{ + return profileData->getName(); +} + +bool NewProfileWizard::getFinished() +{ + return finished; +} + +// void NewProfileDialog::reject() +// { +// +// } + +void NewProfileWizard::showPage ( QWidget* page ) +{ + currentpage = page; + QWizard::showPage ( page ); + + + // FIXME set currentpage at back() + //backButton()->setEnabled(false); + + helpButton() ->setEnabled ( false ); + + if ( page == endpage ) + { + finishButton() ->setEnabled ( TRUE ); + finishButton() ->setFocus(); + } +} + +void NewProfileWizard::dataChanged ( const QString & ) +{ + // if ( !firstName->text().isEmpty() && + // !lastName->text().isEmpty() && + // !email->text().isEmpty() ) + // nextButton()->setEnabled( TRUE ); + // else + // nextButton()->setEnabled( FALSE ); +} + +void NewProfileWizard::userdefinedOpenvpnPortToggeled ( bool ) +{ + if ( newprofilewizardopenvpnpagecontent->UseUserdefinedPortCheckBox->isChecked() ) + newprofilewizardopenvpnpagecontent->UserdefinedPortSpinBox->setEnabled ( true ); + else + newprofilewizardopenvpnpagecontent->UserdefinedPortSpinBox->setEnabled ( false ); +} + +void NewProfileWizard::nsCertTypeOpenvpnToggled ( bool ) +{ + if ( newprofilewizardopenvpnpagecontent->UseNsCertTypeCheckBox->isChecked() ) + newprofilewizardopenvpnpagecontent->NsCertTypeComboBox->setEnabled ( true ); + else + newprofilewizardopenvpnpagecontent->NsCertTypeComboBox->setEnabled ( false ); +} + +void NewProfileWizard::pskIsInFileToggled ( bool ) +{ + if ( newprofilewizardpskcontent->PskInFileCheckBox->isChecked() ) + { + newprofilewizardpskcontent->LabelPskFile->setEnabled ( TRUE ); + newprofilewizardpskcontent->PSKFileURLRequester->setEnabled ( TRUE ); + newprofilewizardpskcontent->LabelPsk->setEnabled ( FALSE ); + newprofilewizardpskcontent->PSKLineEdit->setEnabled ( FALSE ); + } + else + { + newprofilewizardpskcontent->LabelPskFile->setEnabled ( FALSE ); + newprofilewizardpskcontent->PSKFileURLRequester->setEnabled ( FALSE ); + newprofilewizardpskcontent->LabelPsk->setEnabled ( TRUE ); + newprofilewizardpskcontent->PSKLineEdit->setEnabled ( TRUE ); + } +} + +void NewProfileWizard::useNatToggled ( bool ) +{ + if ( newprofilewizardnatcontent->UseNatCheckbox->isChecked() ) + { + newprofilewizardnatcontent->UdpPortCheckbox->setEnabled ( TRUE ); + newprofilewizardnatcontent->UdpPortSpinbox->setEnabled ( FALSE ); + } + else + { + newprofilewizardnatcontent->UdpPortCheckbox->setEnabled ( FALSE ); + newprofilewizardnatcontent->UdpPortSpinbox->setEnabled ( FALSE ); + } +} + +void NewProfileWizard::udpPortToggled ( bool ) +{ + if ( newprofilewizardnatcontent->UdpPortCheckbox->isChecked() ) + { + newprofilewizardnatcontent->UdpPortSpinbox->setEnabled ( TRUE ); + } + else + { + newprofilewizardnatcontent->UdpPortSpinbox->setEnabled ( FALSE ); + } +} + +void NewProfileWizard::pingIpAfterConnectToggled ( bool ) +{ + if ( newprofilewizardconnectionstatuscheckcontent->PingUserdefiniedAddressCheckBox->isChecked() ) + newprofilewizardconnectionstatuscheckcontent->UserdefiniedPingIPLineEdit->setEnabled ( true ); + else + newprofilewizardconnectionstatuscheckcontent->UserdefiniedPingIPLineEdit->setEnabled ( false ); +} + +void NewProfileWizard::useUserdefiniedCipherToggled ( bool ) +{ + if ( newprofilewizardopenvpnpagecontent->UseUserdefiniedCipherCheckBox->isChecked() ) + newprofilewizardopenvpnpagecontent->UserdefiniedCipherComboBox->setEnabled ( true ); + else + newprofilewizardopenvpnpagecontent->UserdefiniedCipherComboBox->setEnabled ( false ); +} + +void NewProfileWizard::useSpecialServerCertificateToggled ( bool ) +{ + if ( newprofilewizardcertcontent->UseSpecialServerCertificateCheckBox->isChecked() ) + { + newprofilewizardcertcontent->SpecialServerCertificateURLRequester->setEnabled ( TRUE ); + } + else + { + newprofilewizardcertcontent->SpecialServerCertificateURLRequester->setEnabled ( FALSE ); + } +} + +void NewProfileWizard::useTlsAuthToggled ( bool ) +{ + if ( newprofilewizardopenvpnpagecontent->UseTlsAuthCheckBox ->isChecked() ) + { + newprofilewizardopenvpnpagecontent->TlsAuthURLRequester->setEnabled ( true ); + newprofilewizardopenvpnpagecontent->UseTlsRemoteHostCheckBox->setEnabled ( true ); + } + else + { + newprofilewizardopenvpnpagecontent->TlsAuthURLRequester->setEnabled ( false ); + newprofilewizardopenvpnpagecontent->UseTlsRemoteHostCheckBox->setEnabled ( false ); + } +} + +void NewProfileWizard::useHttpProxyToggeled ( bool ) +{ + if ( newprofilewizardopenvpnpagecontent->UseHttpProxyCheckBox->isChecked() ) + { + newprofilewizardopenvpnpagecontent->HostTextLabel->setEnabled ( true ); + newprofilewizardopenvpnpagecontent->HttpProxyLineEdit->setEnabled ( true ); + newprofilewizardopenvpnpagecontent->TimeoutTextLabel->setEnabled ( true ); + newprofilewizardopenvpnpagecontent->HttpProxyTimeoutIntSpinBox->setEnabled ( true ); + newprofilewizardopenvpnpagecontent->PortTextextLabel->setEnabled ( true ); + newprofilewizardopenvpnpagecontent->HttpProxyPortIntNumInput->setEnabled ( true ); + } + else + { + newprofilewizardopenvpnpagecontent->HostTextLabel->setEnabled ( false ); + newprofilewizardopenvpnpagecontent->HttpProxyLineEdit->setEnabled ( false ); + newprofilewizardopenvpnpagecontent->TimeoutTextLabel->setEnabled ( false ); + newprofilewizardopenvpnpagecontent->HttpProxyTimeoutIntSpinBox->setEnabled ( false ); + newprofilewizardopenvpnpagecontent->PortTextextLabel->setEnabled ( false ); + newprofilewizardopenvpnpagecontent->HttpProxyPortIntNumInput->setEnabled ( false ); + } +} + +void NewProfileWizard::useTlsRemoteHostToggled ( bool ) +{ + if ( newprofilewizardopenvpnpagecontent->UseTlsRemoteHostCheckBox->isChecked() ) + newprofilewizardopenvpnpagecontent->TlsRemoteHostLineEdit->setEnabled ( true ); + else + newprofilewizardopenvpnpagecontent->TlsRemoteHostLineEdit->setEnabled ( false ); +} + +void NewProfileWizard::connectionStatusCheckToggled ( bool ) +{ + if ( !newprofilewizardconnectionstatuscheckcontent->UseConnectionStatusCheckCheckBox->isChecked() ) + { + newprofilewizardconnectionstatuscheckcontent->ConnectionStatusCheckIntervalNumInput->setEnabled ( false ); + newprofilewizardconnectionstatuscheckcontent->ConnectionStatusSuccessCountNumInput->setEnabled ( false ); + } + else + { + newprofilewizardconnectionstatuscheckcontent->ConnectionStatusCheckIntervalNumInput->setEnabled ( true ); + newprofilewizardconnectionstatuscheckcontent->ConnectionStatusSuccessCountNumInput->setEnabled ( true ); + } +} + +bool NewProfileWizard::importProfile ( VpnAccountData::ConnectionType ConnType ) +{ + // FIXME make dlg dynamiclly + + bool success = true; + + if ( ConnType == VpnAccountData::cisco || ConnType == VpnAccountData::ciscoorig ) + { + ImportProfileDialog dlg ( GlobalConfig, this, i18n ( "Import Cisco PCF profile" ), "" ); + dlg.exec(); + importOK = dlg.importOk; + if ( importOK ) + { + profileData = dlg.acc; + KMessageBox::information ( 0, i18n ( "Import of \"%1\" was successful." ).arg ( profileData->getName() ) ); + GlobalConfig->appendLogEntry ( i18n ( "Import of \"%1\" (%2) was successful." ).arg ( profileData->getName() ).arg ( "PCF" ), GlobalConfig->info ); + } + else + { + KMessageBox::sorry ( 0, i18n ( "Import of \"%1\" has been failed." ).arg ( profileData->getName() ) ); + GlobalConfig->appendLogEntry ( i18n ( "Import of \"%1\" (%2) has been failed." ).arg ( profileData->getName() ).arg ( "PCF" ), GlobalConfig->error ); + success = false; + } + } + if ( ConnType == VpnAccountData::openvpn ) + { + ImportOpenvpnProfileDialog dlg ( GlobalConfig, this, i18n ( "Import OpenVPN profile" ), "" ); + dlg.exec(); + importOK = dlg.importOk; + if ( importOK ) + { + profileData = dlg.acc; + KMessageBox::information ( 0, i18n ( "Import of \"%1\" was successful." ).arg ( profileData->getName() ) ); + GlobalConfig->appendLogEntry ( i18n ( "Import of \"%1\" (%2) was successful." ).arg ( profileData->getName() ).arg ( "OpenVPN" ), GlobalConfig->info ); + } + else + { + KMessageBox::sorry ( 0, i18n ( "Import of \"%1\" has been failed." ).arg ( profileData->getName() ) ); + GlobalConfig->appendLogEntry ( i18n ( "Import of \"%1\" (%2) has been failed." ).arg ( profileData->getName() ).arg ( "OpenVPN" ), GlobalConfig->error ); + success = false; + } + } + if ( ConnType == VpnAccountData::freeswan ) + { + ImportIpsecProfileDialog dlg ( GlobalConfig, this, i18n ( "Import IPSec profile" ), "" ); + dlg.setCaption(i18n("Import IPSec config")); + dlg.exec(); + importOK = dlg.importOk; + if ( importOK ) + { + profileData = dlg.acc; + KMessageBox::information ( 0, i18n ( "Import of \"%1\" was successful." ).arg ( profileData->getName() ) ); + GlobalConfig->appendLogEntry ( i18n ( "Import of \"%1\" (%2) was successful." ).arg ( dlg.main->FilenameUrlrequester->url() ).arg ( "IPSec" ), GlobalConfig->info ); + } + else + { + KMessageBox::sorry ( 0, i18n ( "Import of \"%1\" has been failed." ).arg ( profileData->getName() ) ); + GlobalConfig->appendLogEntry ( i18n ( "Import of \"%1\" (%2) has been failed." ).arg ( dlg.main->FilenameUrlrequester->url() ).arg ( "IPsec" ), GlobalConfig->error ); + success = false; + } + } + + return success; + +} + +bool NewProfileWizard::importCertificate() +{ + bool success = true; + + newprofilewizardcertcontent->CaCertpathURLRequester->clear(); + newprofilewizardcertcontent->certpathURLRequester->clear(); + newprofilewizardcertcontent->PrivkeyPasswordEdit->clear(); + ImportCertificateDialog dlg ( this, i18n ( "Import Certificate..." ).ascii(), GlobalConfig ); + + if ( profileData->getConnectionType() == VpnAccountData::freeswan || + profileData->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { + dlg.main->ImporttypeComboBox->setCurrentItem ( ImportCertificateDialog::pkcs12_freeswan ); + dlg.typeToggeled ( ImportCertificateDialog::pkcs12_freeswan ); + } + else if ( profileData->getConnectionType() == VpnAccountData::racoon || profileData->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { + dlg.main->ImporttypeComboBox->setCurrentItem ( ImportCertificateDialog::pkcs12_racoon ); + dlg.main->PrivateKeyPassGroupBox->setEnabled ( false ); + dlg.main->UsePrivateKeyPasswordCheckBox->setChecked(false); + dlg.typeToggeled ( ImportCertificateDialog::pkcs12_racoon ); + } + else if ( profileData->getConnectionType() == VpnAccountData::openvpn ) + { + dlg.main->ImporttypeComboBox->setCurrentItem ( ImportCertificateDialog::pkcs12_openvpn ); + dlg.typeToggeled ( ImportCertificateDialog::pkcs12_openvpn ); + dlg.main->RacoonCertificatePathUrlrequester->setEnabled ( true ); + dlg.main->RacoonCertificatePathUrlrequester->setURL ( profileData->getCertPath() ); + dlg.main->PrivateKeyPassGroupBox->setEnabled ( true ); + dlg.main->PrivateKeyPasswordEdit->setEnabled ( true ); + dlg.main->PrivateKeyAgainPasswordEdit->setEnabled ( true ); + } + else if ( profileData->getConnectionType() == VpnAccountData::ciscoorig ) + { + dlg.main->ImporttypeComboBox->setCurrentItem ( ImportCertificateDialog::cisco ); + dlg.typeToggeled ( ImportCertificateDialog::cisco); + dlg.main->RacoonCertificatePathUrlrequester->setEnabled ( false ); +// dlg.main->RacoonCertificatePathUrlrequester->hide(); + dlg.main->PrivateKeyPassGroupBox->setEnabled ( true ); + dlg.main->PrivateKeyPasswordEdit->setEnabled ( true ); + dlg.main->PrivateKeyAgainPasswordEdit->setEnabled ( true ); + } + + + dlg.exec(); + importOK = dlg.importOk; + QString filename = dlg.filename; + if ( importOK ) + { + QString certpath = dlg.certpath; + QString CertFullPath = dlg.CertFullPath; + QString CaCertFullPath = dlg.CaCertFullPath; + QString importpassword = dlg.main->ImportPasswordEdit->text(); + QString privatekeypassword = dlg.main->PrivateKeyPasswordEdit->password(); + QString certificate = QString ( "mykeys_" + dlg.certName + ".pem" ); + QString privatekey = QString ( dlg.certName + ".pem" ); + + QString certpostfix = ""; + QString privatepostfix = ""; + if ( profileData->getConnectionType() == VpnAccountData::freeswan || + profileData->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { + certpostfix = "certs/"; + privatepostfix = "private/"; + } + + newprofilewizardcertcontent->CaCertpathURLRequester->setURL ( CaCertFullPath ); + + + if ( profileData->getConnectionType() == VpnAccountData::openvpn ) + newprofilewizardcertcontent->PrivkeyPasswordEdit->setText ( importpassword ); + else + newprofilewizardcertcontent->PrivkeyPasswordEdit->setText ( privatekeypassword ); + + if ( profileData->getConnectionType() == VpnAccountData::l2tpd_racoon || + profileData->getConnectionType() == VpnAccountData::racoon ) + newprofilewizardcertcontent->PrivkeyPasswordEdit->setEnabled ( false ); + + + newprofilewizardcertcontent->certpathURLRequester->setURL ( certpath ); + + if ( profileData->getConnectionType() == VpnAccountData::l2tpd_racoon || + profileData->getConnectionType() == VpnAccountData::racoon ) + { + newprofilewizardcertcontent->privkeypathURLRequester->setURL ( certpath + "/" + certpostfix + certificate ); + newprofilewizardcertcontent->LabelPrivateKeyPassword->setEnabled ( false ); + } + else + newprofilewizardcertcontent->privkeypathURLRequester->setURL ( certpath + "/" + privatepostfix + privatekey ); + newprofilewizardcertcontent->x509certURLRequester->setURL ( certpath + "/" + certpostfix + certificate ); + + KMessageBox::information ( 0, i18n ( "Import of \"%1\" was successful." ).arg ( filename ) ); + GlobalConfig->appendLogEntry ( i18n ( "Import of \"%1\" (%2) was successful." ).arg ( filename ).arg ( "P12 certificate" ), GlobalConfig->info ); + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "Import of \"%1\" (%2) has been failed." ).arg ( filename ).arg ( "P12 certificate" ), GlobalConfig->info ); + success = false; + } + return success; +} + +void NewProfileWizard::authenticateWithUsernameAndPasswordToggled ( bool ) +{ + if ( newprofilewizardopenvpnauthpagecontent->AuthWithUsernameAndPasswordCheckBox->isChecked() ) + newprofilewizardopenvpnauthpagecontent->UseOnlyCaCertAndUserAuthCheckBox->setEnabled ( true ); + else + newprofilewizardopenvpnauthpagecontent->UseOnlyCaCertAndUserAuthCheckBox->setEnabled ( false ); +} + +void NewProfileWizard::pskInputToggled ( const QString& ) +{ + if ( !newprofilewizardpskcontent->PSKLineEdit->text().isEmpty() ) + newprofilewizardpskcontent->CheckSavePsk->setChecked ( true ); + else + newprofilewizardpskcontent->CheckSavePsk->setChecked ( false ); +} + +void NewProfileWizard::userpassToggled ( const QString& ) +{ + if ( !newprofilewizarduserpagecontent->PasswordEdit->text().isEmpty() ) + newprofilewizarduserpagecontent->CheckUserPass->setChecked ( true ); + else + newprofilewizarduserpagecontent->CheckUserPass->setChecked ( false ); +} + +void NewProfileWizard::usernameToggled ( const QString& ) +{ + // if (newprofilewizarduserpagecontent->UsernameLineEdit->text().isEmpty()) + // newprofilewizarduserpagecontent->DontSaveUsernameCheckBox->setChecked(true); + // else + // newprofilewizarduserpagecontent->DontSaveUsernameCheckBox->setChecked(false); +} + +void NewProfileWizard::pskToggled ( const QString& ) +{ + if ( !newprofilewizardciscomanuallypagecontent->GroupPasswordLineEdit->text().isEmpty() ) + newprofilewizardciscomanuallypagecontent->CheckSavePsk->setChecked ( true ); + else + newprofilewizardciscomanuallypagecontent->CheckSavePsk->setChecked ( false ); +} + +void NewProfileWizard::useRightNextHopToggled ( bool ) +{ + if ( newprofilewizardfreeswanpagecontent->UseRightNextHopCheckBox->isChecked() ) + newprofilewizardfreeswanpagecontent->RightNextHopLineEdit->setEnabled ( true ); + else + newprofilewizardfreeswanpagecontent->RightNextHopLineEdit->setEnabled ( false ); +} + +void NewProfileWizard::useLeftNextHopToggled ( bool ) +{ + if ( newprofilewizardfreeswanpagecontent->UseLeftNextHopCheckBox->isChecked() ) + newprofilewizardfreeswanpagecontent->LeftNextHopLineEdit->setEnabled ( true ); + else + newprofilewizardfreeswanpagecontent->LeftNextHopLineEdit->setEnabled ( false ); +} + +void NewProfileWizard::additionalNetworkRoutesToggled ( bool ) +{ + if ( newprofilewizardnetworkroutecontent->UseExtraNetworkRoutesCheckbox->isChecked() ) + { + newprofilewizardnetworkroutecontent->NetworkListView->setEnabled ( TRUE ); + newprofilewizardnetworkroutecontent->DeleteNetworkRoutePushButton->setEnabled ( TRUE ); + newprofilewizardnetworkroutecontent->AddRoutePushButton->setEnabled ( TRUE ); + } + else + { + newprofilewizardnetworkroutecontent->NetworkListView->setEnabled ( FALSE ); + newprofilewizardnetworkroutecontent->DeleteNetworkRoutePushButton->setEnabled ( FALSE ); + newprofilewizardnetworkroutecontent->AddRoutePushButton->setEnabled ( FALSE ); + } +} + +void NewProfileWizard::delNetworkRouteClicked() +{ + if ( newprofilewizardnetworkroutecontent->NetworkListView->childCount() > 0 && newprofilewizardnetworkroutecontent->NetworkListView->currentItem() != 0 ) + { + QListViewItem * item = newprofilewizardnetworkroutecontent->NetworkListView->currentItem(); + QString Network = item->text ( 0 ); + QString Netmask = item->text ( 1 ); + int result = KMessageBox::questionYesNo ( this, i18n ( "Do you really want to delete the network \"%1/%2\"?" ).arg ( Network ).arg ( Netmask ), i18n ( "Delete?" ) ); + //LogOutput->append( "Result: "+ QString().setNum(result) ) ; + if ( result == 3 ) // Yes + { + newprofilewizardnetworkroutecontent->NetworkListView->removeItem ( item ); + } + } +} + +void NewProfileWizard::addNetworkRouteClicked() +{ + AddNetworkRouteDialog dlg ( this, i18n ( "Add Network Route..." ) ); + + + dlg.main->InterfaceComboBox->insertItem ( "default" ); // interface where default route points + + //FIXME + dlg.main->InterfaceComboBox->insertItem ( "eth0" ); + dlg.main->InterfaceComboBox->insertItem ( "eth1" ); + dlg.main->InterfaceComboBox->insertItem ( "eth2" ); + dlg.main->InterfaceComboBox->insertItem ( "ipsec0" ); + dlg.main->InterfaceComboBox->insertItem ( "tun0" ); + dlg.main->InterfaceComboBox->insertItem ( "ppp0" ); + + if ( dlg.exec() ) + { + QString gateway = dlg.getGateway(); + QString interface = dlg.getInterface(); + if ( !dlg.getUseGateway() ) + gateway = "-"; + if ( !dlg.getUseInterface() ) + interface = "-"; + newprofilewizardnetworkroutecontent->NetworkListView->insertItem ( new QListViewItem ( newprofilewizardnetworkroutecontent->NetworkListView, dlg.getNetwork(), dlg.getNetmask(), gateway, interface ) ); + } +} + +void NewProfileWizard::domainNameToggled ( bool ) +{ + if ( newprofilewizarduserpagecontent->NtDomainNameCheckbox->isChecked() ) + newprofilewizarduserpagecontent->NtDomainNameLineedit->setEnabled ( true ); + else + newprofilewizarduserpagecontent->NtDomainNameLineedit->setEnabled ( false ); +} + +void NewProfileWizard::useSmartcardToggled ( bool ) +{ + if ( newprofilewizardcertcontent->UseSmartcardCheckBox->isChecked() ) + { + newprofilewizardcertcontent->SmartcardGroupBox->setEnabled ( true ); + newprofilewizardcertcontent->x509certURLRequester->setEnabled ( false ); + newprofilewizardcertcontent->PrivkeyPasswordEdit->setEnabled ( false ); + newprofilewizardcertcontent->privkeypathURLRequester->setEnabled ( false ); + newprofilewizardcertcontent->LabelCertificate->setEnabled ( false ); + newprofilewizardcertcontent->LabelPrivateKeyPath->setEnabled ( false ); + newprofilewizardcertcontent->LabelPrivateKeyPassword->setEnabled ( false ); + newprofilewizardcertcontent->Pkcs11IdTypeComboBox->setEnabled ( false ); + +// newprofilewizardcertcontent->CertificateGroupBox->setEnabled(false); + + +// if ( profileData->getConnectionType() == VpnAccountData::freeswan || GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) +// { +// ToolInfo IpsecToolInfo( GlobalConfig->programsInPath , "ipsec" ); +// if ( GlobalConfig->programsInPath ) +// { +// IpsecToolInfo.addSearchPath( "/sbin" ); +// IpsecToolInfo.addSearchPath( "/usr/local/sbin" ); +// IpsecToolInfo.addSearchPath( "/usr/sbin" ); +// IpsecToolInfo.addSearchPath( "/bin" ); +// IpsecToolInfo.addSearchPath( "/usr/local/bin" ); +// IpsecToolInfo.addSearchPath( "/usr/bin" ); +// } +// IpsecToolInfo.collectToolInfo(); +// if (IpsecToolInfo.Version.contains("Openswan") || IpsecToolInfo.Version.contains("Free")) +// KMessageBox::information(0,i18n("%1 (IPSec) currently has no working smartcard support (pkcs11). Please use strongSwan instead with enabled smartcard support.").arg(IpsecToolInfo.Version.section(' ',0,0)),i18n("Unsupported IPSec version")); +// } + + } + else + { + newprofilewizardcertcontent->SmartcardGroupBox->setEnabled ( false ); + newprofilewizardcertcontent->x509certURLRequester->setEnabled ( true ); + newprofilewizardcertcontent->PrivkeyPasswordEdit->setEnabled ( true ); + newprofilewizardcertcontent->privkeypathURLRequester->setEnabled ( true ); + newprofilewizardcertcontent->LabelCertificate->setEnabled ( true ); + newprofilewizardcertcontent->LabelPrivateKeyPath->setEnabled ( true ); + newprofilewizardcertcontent->LabelPrivateKeyPassword->setEnabled ( true ); + +// newprofilewizardcertcontent->CertificateGroupBox->setEnabled(true); + } +} + +void NewProfileWizard::useSmartcardOnCertFormateToggled ( bool ) +{ + if ( newprofilewizardp12certselectioncontent->UseSmartcardCheckBox->isChecked() ) + { + newprofilewizardp12certselectioncontent->P12Group->setEnabled ( false ); +// if ( profileData->getConnectionType() == VpnAccountData::freeswan || GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) +// { +// ToolInfo IpsecToolInfo( GlobalConfig->programsInPath , "ipsec" ); +// if ( GlobalConfig->programsInPath ) +// { +// IpsecToolInfo.addSearchPath( "/sbin" ); +// IpsecToolInfo.addSearchPath( "/usr/local/sbin" ); +// IpsecToolInfo.addSearchPath( "/usr/sbin" ); +// IpsecToolInfo.addSearchPath( "/bin" ); +// IpsecToolInfo.addSearchPath( "/usr/local/bin" ); +// IpsecToolInfo.addSearchPath( "/usr/bin" ); +// } +// IpsecToolInfo.collectToolInfo(); +// if (IpsecToolInfo.Version.contains("Openswan") || IpsecToolInfo.Version.contains("Free")) +// KMessageBox::information(0,i18n("%1 (IPSec) currently has no working smartcard support (pkcs11). Please use strongSwan instead with enabled smartcard support.").arg(IpsecToolInfo.Version.section(' ',0,0)),i18n("Unsupported IPSec version")); +// } + } + else + { + newprofilewizardp12certselectioncontent->P12Group->setEnabled ( true ); + } +} + +void NewProfileWizard::usePkcs11ProvidersToggled ( bool ) +{ + if ( newprofilewizardcertcontent->UsePkcs11ProvidersCheckBox->isChecked() ) + newprofilewizardcertcontent->Pkcs11ProvidersURLRequester->setEnabled ( true ); + else + newprofilewizardcertcontent->Pkcs11ProvidersURLRequester->setEnabled ( false ); +} + +void NewProfileWizard::idTypeToggled() +{ + // if (newprofilewizardcertcontent->Pkcs11IdTypeComboBox->currentItem() == 0) + // newprofilewizardcertcontent->IdLabel->setText(i18n("ID")); + // else if (newprofilewizardcertcontent->Pkcs11IdTypeComboBox->currentItem() == 1) + // newprofilewizardcertcontent->IdLabel->setText(i18n("Label")); + // else + // newprofilewizardcertcontent->IdLabel->setText(i18n("Description")); +} + +void NewProfileWizard::detectPkcs11Ids() +{ + GlobalConfig->appPointer->setOverrideCursor ( QCursor ( Qt::WaitCursor ) ); + newprofilewizardcertcontent->Pkcs11IdComboBox->clear(); + + int Pkcs11IdType = newprofilewizardcertcontent->Pkcs11IdTypeComboBox->currentItem(); + QString Pkcs11IdTypeTmp; + if ( Pkcs11IdType == 0 ) + { + Pkcs11IdTypeTmp = "id"; + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Pkcs11IdType: %1" ).arg ( Pkcs11IdTypeTmp ), KVpncConfig::debug ); + } + else if ( Pkcs11IdType == 1 ) + { + Pkcs11IdTypeTmp = "label"; + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Pkcs11IdType: %1" ).arg ( Pkcs11IdTypeTmp ), KVpncConfig::debug ); + } + else + { + Pkcs11IdTypeTmp = "subject"; + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( i18n ( "Pkcs11IdType: %1" ).arg ( Pkcs11IdTypeTmp ), KVpncConfig::debug ); + } + + QString ProviderLib = ""; + if ( newprofilewizardcertcontent->UsePkcs11ProvidersCheckBox->isChecked() && !newprofilewizardcertcontent->Pkcs11ProvidersURLRequester->url().isEmpty() ) + ProviderLib = newprofilewizardcertcontent->Pkcs11ProvidersURLRequester->url(); + + // we have to split slot id and name ("0 : foobar") => 0 + QString Pkcs11Slot = newprofilewizardcertcontent->Pkcs11SlotComboBox->currentText().section ( ':', 0, 0 ).stripWhiteSpace(); + + QStringList Pkcs11Ids = Utils ( GlobalConfig ).getSmartcardCertsFromSlot ( Pkcs11Slot, Pkcs11IdTypeTmp, ProviderLib ); + for ( QStringList::Iterator it = Pkcs11Ids.begin(); it != Pkcs11Ids.end(); ++it ) + newprofilewizardcertcontent->Pkcs11IdComboBox->insertItem ( QString ( *it ) ); + + if ( newprofilewizardcertcontent->Pkcs11SlotComboBox->currentText() == "" || newprofilewizardcertcontent->Pkcs11IdComboBox->currentText() == "" ) + nextButton()->setEnabled ( false ); + else + nextButton()->setEnabled ( true ); + + GlobalConfig->appPointer->restoreOverrideCursor(); +} + +void NewProfileWizard::detectPkcs11Slots() +{ + GlobalConfig->appPointer->setOverrideCursor ( QCursor ( Qt::WaitCursor ) ); + newprofilewizardcertcontent->Pkcs11SlotComboBox->clear(); + QString ProviderLib = ""; + if ( newprofilewizardcertcontent->UsePkcs11ProvidersCheckBox->isChecked() && !newprofilewizardcertcontent->Pkcs11ProvidersURLRequester->url().isEmpty() ) + ProviderLib = newprofilewizardcertcontent->Pkcs11ProvidersURLRequester->url(); + QStringList Pkcs11Slots = Utils ( GlobalConfig ).getSmartcardSlots ( ProviderLib ); + for ( QStringList::Iterator it = Pkcs11Slots.begin(); it != Pkcs11Slots.end(); ++it ) + newprofilewizardcertcontent->Pkcs11SlotComboBox->insertItem ( QString ( *it ) ); + + if ( !Pkcs11Slots.isEmpty() ) + newprofilewizardcertcontent->Pkcs11IdTypeComboBox->setEnabled ( true ); + if ( newprofilewizardcertcontent->Pkcs11SlotComboBox->currentText() == "" || newprofilewizardcertcontent->Pkcs11IdComboBox->currentText() == "" ) + nextButton()->setEnabled ( false ); + else + nextButton()->setEnabled ( true ); + + GlobalConfig->appPointer->restoreOverrideCursor(); +} + +void NewProfileWizard::mtuToggled ( bool ) +{ + if ( newprofilewizardnetworkcontent->MtuCheckbox->isChecked() ) + newprofilewizardnetworkcontent->MtuSpinbox->setEnabled ( true ); + else + newprofilewizardnetworkcontent->MtuSpinbox->setEnabled ( false ); +} + +void NewProfileWizard::mruToggled ( bool ) +{ + if ( newprofilewizardnetworkcontent->MruCheckbox->isChecked() ) + newprofilewizardnetworkcontent->MruSpinbox->setEnabled ( true ); + else + newprofilewizardnetworkcontent->MruSpinbox->setEnabled ( false ); +} + +void NewProfileWizard::useVirtualIpAddressToggled ( bool ) +{ + if ( profilenetworkvirtualipoptionscontent->UseVirtualIPCheckBox->isChecked() ) + { + profilenetworkvirtualipoptionscontent->LocalVirtualIpEdit->setEnabled ( TRUE ); + profilenetworkvirtualipoptionscontent->RemoteVirtualIpLineEdit->setEnabled ( TRUE ); + } + else + { + profilenetworkvirtualipoptionscontent->LocalVirtualIpEdit->setEnabled ( FALSE ); + profilenetworkvirtualipoptionscontent->RemoteVirtualIpLineEdit->setEnabled ( FALSE ); + } +} + +void NewProfileWizard::usePortToggled ( bool ) +{ + if ( newprofilewizardvtunpagecontent->PortCheckbox->isChecked() ) + newprofilewizardvtunpagecontent->PortSpinbox->setEnabled ( true ); + else + newprofilewizardvtunpagecontent->PortSpinbox->setEnabled ( false ); +} + +void NewProfileWizard::useAuthenticationAlgorithmToggled ( bool ) +{ + if ( newprofilewizardopenvpnauthpagecontent->UseAuthenticationAlgorithmCheckBox->isChecked() ) + newprofilewizardopenvpnauthpagecontent->UserdefiniedDigestComboBox ->setEnabled ( true ); + else + newprofilewizardopenvpnauthpagecontent->UserdefiniedDigestComboBox->setEnabled ( false ); +} + +void NewProfileWizard::useRemoteNetworkToggled(bool) +{ + if ( newprofilewizardnetworkcontent->UseRemoteNetworkCheckBox->isChecked() ) + newprofilewizardnetworkcontent->RemoteNetworkGroupBox ->setEnabled ( true ); + else + newprofilewizardnetworkcontent->RemoteNetworkGroupBox->setEnabled ( false ); +} + +void NewProfileWizard::useIkeToggled(bool) +{ + if (newprofilewizardfreeswanpagecontent->UseCustomIkeCheckBox->isChecked()) + newprofilewizardfreeswanpagecontent->IkeGroupBox->setEnabled(true); + else + newprofilewizardfreeswanpagecontent->IkeGroupBox->setEnabled(false); +} + +void NewProfileWizard::useEspToogled(bool) +{ + if (newprofilewizardfreeswanpagecontent->UseCustomEspCheckBox->isChecked()) + newprofilewizardfreeswanpagecontent->EspGroupBox->setEnabled(true); + else + newprofilewizardfreeswanpagecontent->EspGroupBox->setEnabled(false); +} + +void NewProfileWizard::remoteIDTypeRacoonToggled(const QString& text) +{ + if (text == "asn1dn") + { + newprofilewizardracoonpagecontent->RemoteIDLineEdit->setDisabled(true); + newprofilewizardracoonpagecontent->RemoteIDLabel->setDisabled(true); + } + else + { + newprofilewizardracoonpagecontent->RemoteIDLineEdit->setDisabled(false); + newprofilewizardracoonpagecontent->RemoteIDLabel->setDisabled(false); + } +} + +void NewProfileWizard::localIDTypeRacoonToggled(const QString& text) +{ + if (text == "none") + { + newprofilewizardracoonpagecontent->LocalIDLineEdit->setDisabled(true); + newprofilewizardracoonpagecontent->LocalIDLabel->setDisabled(true); + } + else + { + newprofilewizardracoonpagecontent->LocalIDLineEdit->setDisabled(false); + newprofilewizardracoonpagecontent->LocalIDLabel->setDisabled(false); + } +} + +void NewProfileWizard::remoteIDTypeIpsecToggled(const QString& text) +{ + if (text == "asn1dn" || text == "none") + { + newprofilewizardfreeswanpagecontent->RemoteIDLineEdit->setDisabled(true); + newprofilewizardfreeswanpagecontent->RemoteIDLabel->setDisabled(true); + } + else + { + newprofilewizardfreeswanpagecontent->RemoteIDLineEdit->setDisabled(false); + newprofilewizardfreeswanpagecontent->RemoteIDLabel->setDisabled(false); + } + +} + +void NewProfileWizard::localIDTypeIpsecToggled(const QString& text) +{ + if (text == "asn1dn" || text == i18n("Certificate ID")) + { + newprofilewizardfreeswanpagecontent->LocalIDLineEdit->setDisabled(true); + newprofilewizardfreeswanpagecontent->LocalIDLabel->setDisabled(true); + } + else + { + newprofilewizardfreeswanpagecontent->LocalIDLineEdit->setDisabled(false); + newprofilewizardfreeswanpagecontent->LocalIDLabel->setDisabled(false); + } +} + +void NewProfileWizard::defaultRouteToggled(const QString&) +{ + + if (newprofilewizardnetworkroutecontent->DefaultRouteComboBox->currentText() == i18n("Keep default route") || newprofilewizardnetworkroutecontent->DefaultRouteComboBox->currentItem() == 0) + { + KMessageBox::information(0,i18n("Additional network route is needed:\n\nYou have selected to keep the default route. You have to add additional network routes to your remote network. Otherwise you probably dont have access to it."),i18n("Route needed")); + } + +} + +void NewProfileWizard::ikeGroupToggled(bool) +{ + if (newprofilewizardracoonpagecontent->IkeGroupCheckbox->isChecked()) + newprofilewizardracoonpagecontent->DHGroupComboBox->setEnabled(true); + else + newprofilewizardracoonpagecontent->DHGroupComboBox->setEnabled(false); +} + +void NewProfileWizard::useXauthFreeswanToggled(bool) +{ + if (newprofilewizardfreeswanpagecontent->UseXauthCheckBox->isChecked()) + { + newprofilewizarduserpagecontent->setEnabled(true); + newprofilewizardpskcontent->setEnabled(true); + newprofilewizardfreeswanpagecontent->LocalIdTypeCombobox->setEnabled(false); + newprofilewizardfreeswanpagecontent->LocalIDLineEdit->setEnabled(true); + newprofilewizardfreeswanpagecontent->LocalIdTypeCombobox->setCurrentText("keyid"); + } + else + { + newprofilewizarduserpagecontent->setEnabled(false); + newprofilewizardpskcontent->setEnabled(false); + newprofilewizardfreeswanpagecontent->LocalIdTypeCombobox->setEnabled(true); + newprofilewizardfreeswanpagecontent->LocalIDLineEdit->setEnabled(false); + newprofilewizardfreeswanpagecontent->LocalIdTypeCombobox->setCurrentText("asn1dn"); + } +} + +void NewProfileWizard::useXauthRacoonToggled(bool) +{ + if (newprofilewizardracoonpagecontent->UseXauthCheckBox->isChecked()) + { + newprofilewizarduserpagecontent->setEnabled(true); + newprofilewizardpskcontent->setEnabled(true); + newprofilewizardracoonpagecontent->LocalIdTypeCombobox->setEnabled(false); + newprofilewizardracoonpagecontent->LocalIDLineEdit->setEnabled(true); + newprofilewizardracoonpagecontent->LocalIdTypeCombobox->setCurrentText("keyid"); + } + else + { + newprofilewizarduserpagecontent->setEnabled(false); + newprofilewizardpskcontent->setEnabled(false); + newprofilewizardracoonpagecontent->LocalIdTypeCombobox->setEnabled(true); + newprofilewizardracoonpagecontent->LocalIDLineEdit->setEnabled(false); + newprofilewizardracoonpagecontent->LocalIdTypeCombobox->setCurrentText("asn1dn"); + } +} + +void NewProfileWizard::tunnelDeviceTypeChanged(const QString & string ) +{ + if ( profileData->getConnectionType() == VpnAccountData::openvpn || profileData->getConnectionType() == VpnAccountData::ssh) + { + if (string.lower() == "tun") + { + profilenetworkvirtualipoptionscontent->LabelRemoteVirtualIp->setText(i18n("Remote IP (virtual):")); + } + if (string.lower() == "tap") + { + profilenetworkvirtualipoptionscontent->LabelRemoteVirtualIp->setText(i18n("Netmask for local IP address:")); + } + } +} + +void NewProfileWizard::useDnsServerToggled(bool) +{ + if ( newprofilewizardpptppagecontent->DnsServerCheckbox->isChecked() ) + newprofilewizardpptppagecontent->DnsServerLineedit->setEnabled( true ); + else + newprofilewizardpptppagecontent->DnsServerLineedit->setEnabled( false ); +} + +void NewProfileWizard::useSearchDomainInResolvConfToggled(bool) +{ + if ( newprofilewizardpptppagecontent->UseSearchDomainInResolvConfCheckbox ->isChecked() ) + newprofilewizardpptppagecontent->SearchDomainInResolvConfLineedit->setEnabled( true ); + else + newprofilewizardpptppagecontent->SearchDomainInResolvConfLineedit->setEnabled( false ); +} + +void NewProfileWizard::useDomainInResolvConfToggled(bool) +{ + if ( newprofilewizardpptppagecontent->UseDomainInResolvConfCheckbox ->isChecked() ) + newprofilewizardpptppagecontent->DomainInResolvConfLineedit->setEnabled( true ); + else + newprofilewizardpptppagecontent->DomainInResolvConfLineedit->setEnabled( false ); +} + + diff --git a/src/newprofilewizard.h b/src/newprofilewizard.h new file mode 100644 index 0000000..770e66a --- /dev/null +++ b/src/newprofilewizard.h @@ -0,0 +1,249 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +//BEGIN INCLUDES +#ifndef NEWPROFILEWIZARD_H +#define NEWPROFILEWIZARD_H + +#include +#include +#include +#include +#include +#include +#include + + +#include "kvpncconfig.h" + +#include "newprofilewizardtypeselection.h" +#include "newprofilewizardgeneral.h" +#include "newprofilewizardciscoselection.h" +#include "newprofilewizardciscomanually.h" +#include "importprofiledialog.h" // PCF import +#include "importopenvpnprofiledialog.h" //< OpenVPN import +#include "importipsecprofiledialog.h" //< IPSec import +#include "newprofilewizardracoon.h" +#include "newprofilewizardfreeswan.h" +#include "newprofilewizardopenvpn.h" +#include "newprofilewizardopenvpnauth.h" +#include "newprofilewizardopenvpnselection.h" +#include "newprofilewizardpptp.h" +#include "profilevtunoptions.h" +#include "profilesshoptions.h" +#include "newprofilewizardauthselection.h" +#include "newprofilewizardpsk.h" +#include "newprofilewizardcert.h" +#include "newprofilewizardstart.h" +#include "newprofilewizarduser.h" +#include "newprofilewizardnetwork.h" +#include "newprofilewizardnetworkroute.h" +#include "newprofilewizardnat.h" +#include "newprofilewizardp12certselection.h" +#include "importcertificatedialog.h" +#include "newprofilewizardconnectoptions.h" +#include "newprofilewizardconnectionstatuscheck.h" +#include "profilenetworkvirtualipoptions.h" +#include "profilenetworkrouteoptions.h" + +//END INCLUDES + +/** +Provides a wizard for creating a new profile + +@author Christoph Thielecke +*/ +class NewProfileWizard : public QWizard +{ +Q_OBJECT +public: + NewProfileWizard(KVpncConfig* GlobalConfig); + + void dataChanged( const QString & ); + QString getName(); + QString getProfile(); + bool getFinished(); + bool newProfileCreated; + bool daemonavailable; //< true if required is found, used for connecting after creating + bool connectaftercreating; //< connect if successful created + VpnAccountData *profileData; + +public slots: + void showPage( QWidget* page ); + void next (); + void back(); + void accept(); + void reject(); + void userdefinedOpenvpnPortToggeled(bool); + void nsCertTypeOpenvpnToggled(bool); + void additionalNetworkRoutesToggled(bool); + void addNetworkRouteClicked(); + void delNetworkRouteClicked(); + void pskIsInFileToggled(bool); + void useNatToggled(bool); + void udpPortToggled(bool); + void pingIpAfterConnectToggled(bool); + void useSpecialServerCertificateToggled(bool); + void useUserdefiniedCipherToggled(bool); + void useHttpProxyToggeled(bool); + void useTlsAuthToggled(bool); + void useTlsRemoteHostToggled(bool); + void connectionStatusCheckToggled(bool); + void authenticateWithUsernameAndPasswordToggled(bool); + void pskInputToggled(const QString& str); + void userpassToggled(const QString& str); + void usernameToggled(const QString& str); + void pskToggled(const QString& str); + void useRightNextHopToggled(bool); + void useLeftNextHopToggled(bool); + void domainNameToggled(bool); + void idTypeToggled(); + void usePkcs11ProvidersToggled(bool); + void useSmartcardToggled(bool); + void useSmartcardOnCertFormateToggled(bool); + void detectPkcs11Ids(); + void detectPkcs11Slots(); + void mtuToggled(bool); + void mruToggled(bool); + void useVirtualIpAddressToggled(bool); + void usePortToggled(bool); + void useAuthenticationAlgorithmToggled(bool); + void useRemoteNetworkToggled(bool); + void useEspToogled(bool); + void useIkeToggled(bool); + void remoteIDTypeRacoonToggled(const QString&); + void localIDTypeRacoonToggled(const QString&); + void remoteIDTypeIpsecToggled(const QString&); + void localIDTypeIpsecToggled(const QString&); + void defaultRouteToggled(const QString&); + void ikeGroupToggled(bool); + void useXauthFreeswanToggled(bool); + void useXauthRacoonToggled(bool); + void tunnelDeviceTypeChanged(const QString &); + void useDnsServerToggled(bool); + void useSearchDomainInResolvConfToggled(bool); + void useDomainInResolvConfToggled(bool); + //void reject(); + +protected: + QString ConnectionType; + QString Gateway; + QString ID; + QString Username; + QString UserPassword; + QString PreSharedKey; + QString ApplicationVersion; + QString NtDomainName; + QString PerfectForwardSecrecy; + QString IkeGroup; + QString DnsServer; //< userdefined DNS server for pptp + QString Name; + QString Description; + bool saveUserPassword; + bool savePsk; + bool useApplicationVersion; + bool useGlobalIpsecSecret; + bool useIkeGroup; + bool useLocalPort; + bool useNtDomainName; + bool useSingleDes; + bool useAdvancedSettings; + bool usePerfectSecrecy; + bool useUdp; //< True if NAT-T should be used + bool useUdpPort; //< True if userdefined UDP port should be used + bool useDnsServer; //< True if userdefined DNS server should be used + bool useGetDnsFromPeer; //< True if DNS servers should be retrieved from peer (pptp)bool + bool refuse40BitEncryption; //< True if 40 bit encryption is refused (pptp) + bool refuse128BitEncryption; //< True if 128 bit encryption is refused (pptp) + bool allowStatefulMode; + bool useNoBsdComp; + bool useNoDeflate; + bool requireMppe; //< True if MPPE is required (pptp) + bool refuseEap; //< True if EAP is refused (pptp) + int Port; + int UdpPort; //< Port number of UDP port + +private: + void setupPages(); + bool importProfile(VpnAccountData::ConnectionType ConnType); + bool importCertificate(); + QHBox *page1; + QHBox *newprofilewizardtypeselectionpage; + QHBox *newprofilewizardgeneralpage; + QHBox *newprofilewizardciscoselectionpage; + QHBox *newprofilewizardciscomanuallypage; + QHBox *newprofilewizardracoonpage; + QHBox *newprofilewizardfreeswanpage; + QHBox *newprofilewizardfreeswanselectionpage; + QHBox *newprofilewizardopenvpnpage; + QHBox *newprofilewizardopenvpnselectionpage; + QHBox *newprofilewizardopenvpnauthpage; + QHBox *newprofilewizardpptppage; + QHBox *newprofilewizardvtunpage; + QHBox *newprofilewizardsshpage; + QHBox *newprofilewizardauthselectionpage; + QHBox *newprofilewizardpskpage; + QHBox *newprofilewizardcertpage; + QHBox *newprofilewizardp12certselectionpage; + QHBox *newprofilewizarduserpage; + QHBox *newprofilewizardnetworkpage; + QHBox *newprofilewizardvirtualipaddresspage; + QHBox *newprofilewizardnetworkroutepage; + QHBox *newprofilewizardnatpage; + QHBox *newprofilewizardconnectionstatuscheckpage; + QHBox *newprofilewizardconnectoptionspage; + QHBox *endpage; + NewProfileWizardTypeSelection *newprofilewizardtypeselectionpagecontent; + NewProfileWizardGeneral *newprofilewizardgeneralpagecontent; + NewProfileWizardCiscoSelection *newprofilewizardciscoselectionpagecontent; + NewProfileWizardCiscoManually *newprofilewizardciscomanuallypagecontent; + NewProfileWizardRacoon *newprofilewizardracoonpagecontent; + NewProfileWizardFreeswan *newprofilewizardfreeswanpagecontent; + NewProfileWizardOpenvpnSelection *newprofilewizardfreeswanselectionpagecontent; + NewProfileWizardOpenvpn *newprofilewizardopenvpnpagecontent; + NewProfileWizardOpenvpnAuth *newprofilewizardopenvpnauthpagecontent; + NewProfileWizardOpenvpnSelection *newprofilewizardopenvpnselectionpagecontent; + NewProfileWizardPptp *newprofilewizardpptppagecontent; + ProfileVtunOptions *newprofilewizardvtunpagecontent; + ProfileSshOptions *newprofilewizardsshpagecontent; + NewProfileWizardAuthSelection *newprofilewizardauthselectioncontent; + NewProfileWizardPsk *newprofilewizardpskcontent; + NewProfileWizardCert *newprofilewizardcertcontent; + NewProfileWizardStart *newprofilewizardstartcontent; + NewProfileWizardP12CertSelection *newprofilewizardp12certselectioncontent; + NewProfileWizardUser *newprofilewizarduserpagecontent; + NewProfileWizardNetwork *newprofilewizardnetworkcontent; + ProfileNetworkRouteOptions *newprofilewizardnetworkroutecontent; + NewProfileWizardNat *newprofilewizardnatcontent; + NewProfileWizardConnectionStatusCheck *newprofilewizardconnectionstatuscheckcontent; + NewProfileWizardConnectOptions *newprofilewizardconnectoptionscontent; + ProfileNetworkVirtualIpOptions *profilenetworkvirtualipoptionscontent; + KVpncConfig* GlobalConfig; //< pointer to global config class + QWidget* currentpage; // pointer to current page + QWidget* previouspage; //< pointer to previous page + bool finished; + bool enterdatamanually; //< enter data manually + bool useCert; //< use certificate for authentication + bool importOK; //< import was successful + QPixmap *SetupPixmap; + QPixmap *SetupPixmapFinal; + +}; + +#endif diff --git a/src/newprofilewizard.png b/src/newprofilewizard.png new file mode 100644 index 0000000..eaf387c Binary files /dev/null and b/src/newprofilewizard.png differ diff --git a/src/newprofilewizard_final.png b/src/newprofilewizard_final.png new file mode 100644 index 0000000..6b5b655 Binary files /dev/null and b/src/newprofilewizard_final.png differ diff --git a/src/newprofilewizardauthselection.ui b/src/newprofilewizardauthselection.ui new file mode 100644 index 0000000..455a964 --- /dev/null +++ b/src/newprofilewizardauthselection.ui @@ -0,0 +1,108 @@ + +NewProfileWizardAuthSelection + + + NewProfileWizardAuthSelection + + + + 0 + 0 + 399 + 196 + + + + Authentication selection + + + + unnamed + + + + buttonGroup2 + + + Authentication method + + + + unnamed + + + + PskRadioButton + + + Pre-shared ke&y (shared secret) + + + Alt+Y + + + true + + + + + CertificateRadioButton + + + &Certificate + + + Alt+C + + + + + HybridRadioButton + + + &Hybrid + + + Alt+H + + + + + + + spacer5 + + + Horizontal + + + Expanding + + + + 71 + 20 + + + + + + spacer6 + + + Vertical + + + Expanding + + + + 20 + 51 + + + + + + + diff --git a/src/newprofilewizardcert.ui b/src/newprofilewizardcert.ui new file mode 100644 index 0000000..8e06fad --- /dev/null +++ b/src/newprofilewizardcert.ui @@ -0,0 +1,732 @@ + +NewProfileWizardCert + + + NewProfileWizardCert + + + + 0 + 0 + 783 + 549 + + + + Certificate settings + + + + unnamed + + + + layout47 + + + + unnamed + + + + layout46 + + + + unnamed + + + + layout76 + + + + unnamed + + + + UseSmartcardCheckBox + + + Enable PKCS&11 smartcard support + + + Alt+1 + + + + + + + + spacer68 + + + Horizontal + + + Expanding + + + + 221 + 20 + + + + + + + + CertificateGroupBox + + + Certificate + + + + unnamed + + + + privkeypathURLRequester + + + Path to the private key file + + + + + SpecialServerCertificateURLRequester + + + false + + + Special certificate file + + + + + PrivkeyPasswordEdit + + + Password + + + Passphrase to decrypt the private key + + + + + + + + certpathURLRequester + + + Global certificates path used if no absolute path is given + + + In this directory certificates will be searched <br>if no absolute path is given. + + + + + CaCertpathURLRequester + + + CA certificate path + + + + + layout45 + + + + unnamed + + + + x509certURLRequester + + + + 250 + 0 + + + + Path to the certificate file + + + + + x509certComboBox + + + + + + + layout28 + + + + unnamed + + + + LabelCertificate + + + Certificate: + + + + + spacer17 + + + Horizontal + + + Expanding + + + + 172 + 20 + + + + + + + + layout29 + + + + unnamed + + + + LabelCertificatePath + + + Certificate path: + + + + + spacer21 + + + Horizontal + + + Expanding + + + + 134 + 20 + + + + + + + + layout30 + + + + unnamed + + + + LabelCaCertificatePath + + + CA certificate: + + + + + spacer21_2 + + + Horizontal + + + Expanding + + + + 109 + 20 + + + + + + + + layout32 + + + + unnamed + + + + UseSpecialServerCertificateCheckBox + + + &Use special server certificate + + + Alt+U + + + + + + + + spacer25_2 + + + Horizontal + + + Expanding + + + + 34 + 20 + + + + + + + + layout33 + + + + unnamed + + + + LabelPrivateKeyPath + + + Private key path: + + + + + spacer22 + + + Horizontal + + + Expanding + + + + 134 + 20 + + + + + + + + layout34 + + + + unnamed + + + + LabelPrivateKeyPassword + + + Private key passphrase: + + + + + spacer19 + + + Horizontal + + + Expanding + + + + 84 + 20 + + + + + + + + + + SmartcardGroupBox + + + false + + + PKCS11 smartcard + + + + unnamed + + + + layout90 + + + + unnamed + + + + layout31 + + + + unnamed + + + + UsePkcs11ProvidersCheckBox + + + Use token provider &library: + + + Alt+L + + + + + Pkcs11ProvidersURLRequester + + + false + + + + + + + layout55 + + + + unnamed + + + + DetectPkcs11IdPushButton + + + Detect + + + + + textLabel3 + + + Slot + + + + + IdLabel + + + ID + + + + + Pkcs11SlotComboBox + + + + 3 + 0 + 0 + 0 + + + + 5 + + + 15 + + + false + + + + + DetectPkcs11SlotsPushButton + + + Detect + + + + + Pkcs11IdComboBox + + + + 3 + 0 + 0 + 0 + + + + true + + + 50 + + + false + + + + + + + layout24 + + + + unnamed + + + + layout23 + + + + unnamed + + + + Pkcs11SlotTypeLabel + + + Slot type + + + + + + auto + + + + + sign + + + + + recover + + + + + any + + + + Pkcs11SignModeComboBox + + + + + + ID + + + + + Name + + + + + Label + + + + Pkcs11SlotTypeComboBox + + + + + textLabel5 + + + Sign mode + + + + + + + layout22 + + + + unnamed + + + + spacer20 + + + Horizontal + + + Expanding + + + + 241 + 21 + + + + + + + ID + + + + + Label + + + + + Subject + + + + Pkcs11IdTypeComboBox + + + + + textLabel2 + + + ID type + + + + + + + + + + + + + spacer36 + + + Vertical + + + Expanding + + + + 20 + 44 + + + + + + + + + + + x509certURLRequester + certpathURLRequester + CaCertpathURLRequester + UseSpecialServerCertificateCheckBox + SpecialServerCertificateURLRequester + privkeypathURLRequester + PrivkeyPasswordEdit + + + useSmartcardToggled(bool) + usePkcs11ProvidersToggled(bool) + idTypeToggled() + + + + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + kcombobox.h + kurlrequester.h + klineedit.h + kpushbutton.h + kpushbutton.h + kcombobox.h + kpushbutton.h + kcombobox.h + kcombobox.h + kcombobox.h + kcombobox.h + + diff --git a/src/newprofilewizardciscomanually.ui b/src/newprofilewizardciscomanually.ui new file mode 100644 index 0000000..bb3aeb0 --- /dev/null +++ b/src/newprofilewizardciscomanually.ui @@ -0,0 +1,234 @@ + +NewProfileWizardCiscoManually + + + NewProfileWizardCiscoManually + + + + 0 + 0 + 373 + 181 + + + + New profile wizard cisco + + + + unnamed + + + + spacer25 + + + Vertical + + + Expanding + + + + 20 + 71 + + + + + + layout24 + + + + unnamed + + + + spacer37 + + + Horizontal + + + Expanding + + + + 171 + 20 + + + + + + CheckSavePsk + + + Save group &password + + + Alt+P + + + Save the group password in config file (or in KWallet if available) + + + + + spacer38 + + + Horizontal + + + Expanding + + + + 111 + 21 + + + + + + textLabel3 + + + Cisco specific settings + + + + + AllowEmptyGroupPasswordCheckBox + + + A&llow empty group password (insecure!) + + + Alt+L + + + Allow an empty group password (not recommended, insecure) + + + + + layout12 + + + + unnamed + + + + IDLineEdit + + + IPSec ID of the remote side + + + + + + + + LabelID + + + IPSec ID: + + + + + GroupPasswordLineEdit + + + Password + + + Group password for remote side + + + + + spacer18 + + + Horizontal + + + Expanding + + + + 70 + 20 + + + + + + spacer15 + + + Horizontal + + + Expanding + + + + 70 + 20 + + + + + + LabelPsk + + + true + + + Group password: + + + + + + + + + spacer24_2 + + + Horizontal + + + Expanding + + + + 20 + 20 + + + + + + + IDLineEdit + GroupPasswordLineEdit + CheckSavePsk + AllowEmptyGroupPasswordCheckBox + + + + klineedit.h + klineedit.h + + diff --git a/src/newprofilewizardciscopcfimport.ui b/src/newprofilewizardciscopcfimport.ui new file mode 100644 index 0000000..858b467 --- /dev/null +++ b/src/newprofilewizardciscopcfimport.ui @@ -0,0 +1,20 @@ + +Form1 + + + Form1 + + + + 0 + 0 + 600 + 480 + + + + Form1 + + + + diff --git a/src/newprofilewizardciscoselection.ui b/src/newprofilewizardciscoselection.ui new file mode 100644 index 0000000..2771220 --- /dev/null +++ b/src/newprofilewizardciscoselection.ui @@ -0,0 +1,97 @@ + +NewProfileWizardCiscoSelection + + + NewProfileWizardCiscoSelection + + + + 0 + 0 + 571 + 420 + + + + Cisco selection + + + + unnamed + + + + buttonGroup2 + + + Import or configure manually + + + + unnamed + + + + PcfImportRadioButton + + + &Import PCF file + + + Alt+I + + + true + + + + + EnterManuallyRadioButton + + + Enter data manuall&y + + + Alt+Y + + + + + + + spacer15 + + + Vertical + + + Expanding + + + + 31 + 311 + + + + + + spacer16 + + + Horizontal + + + Expanding + + + + 351 + 20 + + + + + + + diff --git a/src/newprofilewizardconnectionstatuscheck.ui b/src/newprofilewizardconnectionstatuscheck.ui new file mode 100644 index 0000000..fa23589 --- /dev/null +++ b/src/newprofilewizardconnectionstatuscheck.ui @@ -0,0 +1,317 @@ + +NewProfileWizardConnectionStatusCheck + + + NewProfileWizardConnectionStatusCheck + + + + 0 + 0 + 361 + 218 + + + + Connection status check + + + + unnamed + + + + layout8 + + + + unnamed + + + + layout6 + + + + unnamed + + + + UseConnectionStatusCheckCheckBox + + + true + + + Use connection status c&heck + + + Alt+H + + + true + + + Test if the connection is allive by pinging the gateway + + + If checked, the connection status check will be enabled. The parameters below <br>control how often the gateway will be pinged. It must be minimal success in a count.<br>Example: interval: 1, success count: 4, means that 4 pings will be done and minimal one <br>must be success for keep the connection alive. The delay between the pings are 1 second. + + + + + spacer8_2 + + + Horizontal + + + Expanding + + + + 241 + 20 + + + + + + + + layout5 + + + + unnamed + + + + ConnectionStatusSuccessCountNumInput + + + 4 + + + 1 + + + 10 + + + + + ConnectionStatusCheckIntervalNumInput + + + 1 + + + 120 + + + + + spacer9 + + + Horizontal + + + Expanding + + + + 180 + 20 + + + + + + kActiveLabel1 + + + Success count: + + + + + spacer8 + + + Horizontal + + + Expanding + + + + 290 + 20 + + + + + + kActiveLabel2 + + + Interval: + + + + + + + layout7 + + + + unnamed + + + + DoReconnectAfterConnectionLostCheckBox + + + true + + + Reconnect after connection &lost + + + Alt+L + + + true + + + Reconnect automatically after the connection is lost + + + + + + + + spacer9_2 + + + Horizontal + + + Expanding + + + + 201 + 20 + + + + + + + + layout4 + + + + unnamed + + + + PingUserdefiniedAddressCheckBox + + + WidgetOrigin + + + Use specified &address to ping: + + + Alt+A + + + Use specified address instead the gateway address <br>to test the connection status + + + + + UserdefiniedPingIPLineEdit + + + false + + + Normal + + + IP address for ping test + + + This is the IP address which should be tested. + + + + + + + + + spacer14 + + + Horizontal + + + Expanding + + + + 201 + 41 + + + + + + spacer15 + + + Vertical + + + Expanding + + + + 20 + 121 + + + + + + + UseConnectionStatusCheckCheckBox + kActiveLabel2 + ConnectionStatusCheckIntervalNumInput + kActiveLabel1 + ConnectionStatusSuccessCountNumInput + DoReconnectAfterConnectionLostCheckBox + PingUserdefiniedAddressCheckBox + UserdefiniedPingIPLineEdit + + + + knuminput.h + knuminput.h + knuminput.h + knuminput.h + kactivelabel.h + kactivelabel.h + klineedit.h + + diff --git a/src/newprofilewizardconnectoptions.ui b/src/newprofilewizardconnectoptions.ui new file mode 100644 index 0000000..e10f45a --- /dev/null +++ b/src/newprofilewizardconnectoptions.ui @@ -0,0 +1,165 @@ + +NewProfileWizardConnectOptions + + + NewProfileWizardConnectOptions + + + + 0 + 0 + 382 + 85 + + + + Connect options + + + + unnamed + + + + layout37 + + + + unnamed + + + + layout36 + + + + unnamed + + + + ConnectAfterCreatingProfileCheckBox + + + Connect after creating ne&w profile + + + Alt+W + + + + + spacer34 + + + Horizontal + + + Expanding + + + + 181 + 21 + + + + + + + + layout12 + + + + unnamed + + + + DoAutoConnectCheckBox + + + &Connect automatically at startup: + + + Alt+C + + + false + + + Connect after start to a selected profile + + + Enable this to let kvpnc connect to given profile at startup + + + + + spacer24_2_2 + + + Horizontal + + + Expanding + + + + 59 + 20 + + + + + + AutoConnectProfileComboBox + + + Select profile to use + + + + + + + + + spacer35 + + + Horizontal + + + Expanding + + + + 61 + 20 + + + + + + spacer36 + + + Vertical + + + Expanding + + + + 20 + 91 + + + + + + + + kcombobox.h + + diff --git a/src/newprofilewizardfreeswan.ui b/src/newprofilewizardfreeswan.ui new file mode 100644 index 0000000..cd3adeb --- /dev/null +++ b/src/newprofilewizardfreeswan.ui @@ -0,0 +1,887 @@ + +NewProfileWizardFreeswan + + + NewProfileWizardFreeswan + + + + 0 + 0 + 494 + 649 + + + + Setup FreeS/WAN + + + + + + + unnamed + + + + layout64 + + + + unnamed + + + + layout63 + + + + unnamed + + + + layout90_2 + + + + unnamed + + + + UseXauthCheckBox + + + Authenticate &with username and password (XAUTH) + + + Alt+W + + + enable this if you want enable the XAUTh extension + + + + + spacer6_2_2 + + + Horizontal + + + Expanding + + + + 100 + 20 + + + + + + + + layout160 + + + + unnamed + + + + UseModeConfigCheckBox + + + Use &Mode Configuration + + + Alt+M + + + + + spacer113 + + + Horizontal + + + Expanding + + + + 20 + 20 + + + + + + PerfectForwardSecurityCheckbox + + + Use Perfect for&ward secrecy (PFS) + + + Alt+W + + + Use perfect forward secrety (PFS) + + + + + + + RemoteIdentifierGroupBox + + + Remote identifier + + + + unnamed + + + + layout74_2 + + + + unnamed + + + + layout73_2 + + + + unnamed + + + + HashAlgoTextLabel_2_2_2 + + + ID type + + + + + spacer72_2_3_2 + + + Horizontal + + + Expanding + + + + 51 + 20 + + + + + + + + RemoteIDLineEdit + + + false + + + Normal + + + Value for the local ID + + + + + layout72_2_2 + + + + unnamed + + + + RemoteIDLabel + + + ID value + + + + + spacer72_2_2_2 + + + Horizontal + + + Expanding + + + + 51 + 20 + + + + + + + + RemoteIdTypeCombobox + + + false + + + This is the type of the local ID (default: asn1dn)<br> +<ul> +<li>asn1dn - the type is an ASN.1 distinguished name. Use 'use email address as identifier' in certificate settings if it should be the mail address. If this option is not checked, the DN from the Subject field in the certificate will be used.</li> +<li>address - the type is the IP address.</li> +<li>fqdn - the type is a FQDN (fully-qualified domain name).</li> +<li>keyid - the type is a KEY_ID (file)</li> +<li>user_fqdn - the type is a USER_FQDN (user fully-qualified domain name).</li> +</ul> + Automatic keying has a property called perfect forward secrecy. This is the Diffie Helman group for PFS. + + + This is the type of the local ID (default: asn1dn)<br> +<ul> +<li>asn1dn - the type is an ASN.1 distinguished name. Use 'use email address as identifier' in certificate settings if it should be the mail address. If this option is not checked, the DN from the Subject field in the certificate will be used.</li> +<li>address - the type is the IP address.</li> +<li>fqdn - the type is a FQDN (fully-qualified domain name).</li> +<li>keyid - the type is a KEY_ID (file)</li> +<li>user_fqdn - the type is a USER_FQDN (user fully-qualified domain name).</li> +</ul> + + + + + + + + + layout158 + + + + unnamed + + + + layout155 + + + + unnamed + + + + UseCustomIkeCheckBox + + + Use custom IKE + + + + + IkeGroupBox + + + false + + + IKE + + + + unnamed + + + + IkeAes256Sha1CheckBox + + + aes25&6-sha1 + + + Alt+6 + + + + + IkeAes128Sha1CheckBox + + + aes&128-sha1 + + + Alt+1 + + + + + IkeDesSha1Modp2048CheckBox + + + 3des-sha1-modp20&48 + + + Alt+4 + + + + + IkeDesSha1CheckBox + + + 3des-sha1 + + + + + + + + IkeDesMd5CheckBox + + + &3des-md5 + + + Alt+3 + + + + + layout52 + + + + unnamed + + + + textLabel1 + + + other: + + + + + OtherIkeLineEdit + + + + + + + + + + + layout156 + + + + unnamed + + + + UseCustomEspCheckBox + + + Use custom ESP + + + + + + + + EspGroupBox + + + false + + + ESP + + + + unnamed + + + + EspAes256Sha1CheckBox + + + aes2&56-sha1 + + + Alt+5 + + + + + EspAes128Sha1CheckBox + + + aes12&8-sha1 + + + Alt+8 + + + + + EspDesSha1CheckBox + + + 3des-sha1 + + + + + + + + Esp3desMd5CheckBox + + + 3des-md5 + + + + + layout53 + + + + unnamed + + + + textLabel2 + + + other: + + + + + OtherEspLineEdit + + + + + + + + + + + + + layout9 + + + + unnamed + + + + UseRightNextHopCheckBox + + + &Use right next hop: + + + Alt+U + + + + + RightNextHopLineEdit + + + false + + + + + UseLeftNextHopCheckBox + + + Use &left next hop: + + + Alt+L + + + + + LeftNextHopLineEdit + + + false + + + + + + + + + + LocalIdentifierGroupBox + + + Local identifier + + + + unnamed + + + + layout74 + + + + unnamed + + + + layout73 + + + + unnamed + + + + HashAlgoTextLabel_2_2 + + + ID type + + + + + spacer72_2 + + + Horizontal + + + Expanding + + + + 51 + 20 + + + + + + + + LocalIDLineEdit + + + false + + + Normal + + + Value for the local ID + + + + + layout72_2 + + + + unnamed + + + + LocalIDLabel + + + ID value + + + + + spacer72_2_2 + + + Horizontal + + + Expanding + + + + 51 + 20 + + + + + + + + LocalIdTypeCombobox + + + false + + + This is the type of the local ID (default: asn1dn)<br> +<ul> +<li>asn1dn - the type is an ASN.1 distinguished name. Use 'use email address as identifier' in certificate settings if it should be the mail address. If this option is not checked, the DN from the Subject field in the certificate will be used.</li> +<li>address - the type is the IP address.</li> +<li>fqdn - the type is a FQDN (fully-qualified domain name).</li> +<li>keyid - the type is a KEY_ID (file)</li> +<li>user_fqdn - the type is a USER_FQDN (user fully-qualified domain name).</li> +</ul> + Automatic keying has a property called perfect forward secrecy. This is the Diffie Helman group for PFS. + + + This is the type of the local ID (default: asn1dn)<br> +<ul> +<li>asn1dn - the type is an ASN.1 distinguished name. Use 'use email address as identifier' in certificate settings if it should be the mail address. If this option is not checked, the DN from the Subject field in the certificate will be used.</li> +<li>address - the type is the IP address.</li> +<li>fqdn - the type is a FQDN (fully-qualified domain name).</li> +<li>keyid - the type is a KEY_ID (file)</li> +<li>user_fqdn - the type is a USER_FQDN (user fully-qualified domain name).</li> +</ul> + + + + + + + + + layout90 + + + + unnamed + + + + DisableOpportunisticEncryptionCheckBox + + + Disable opportunistic encr&yption + + + Alt+Y + + + + + spacer6_2 + + + Horizontal + + + Expanding + + + + 100 + 20 + + + + + + + + spacer3 + + + Vertical + + + Expanding + + + + 20 + 198 + + + + + + layout16 + + + + unnamed + + + + ExchangeModeComboBox + + + Internet Key Exchange mode + + + + + layout150 + + + + unnamed + + + + IPsecVpnModeTextLabel + + + IPsec VPN mode: + + + + + spacer72_2_3 + + + Horizontal + + + Expanding + + + + 28 + 20 + + + + + + + + layout72 + + + + unnamed + + + + HashAlgoTextLabel_2 + + + Exchange mode: + + + + + spacer72 + + + Horizontal + + + Expanding + + + + 91 + 21 + + + + + + + + IpsecVpnModeCombobox + + + false + + + This is the type of the local ID (default: asn1dn)<br> +<ul> +<li>asn1dn - the type is an ASN.1 distinguished name. Use 'use email address as identifier' in certificate settings if it should be the mail address. If this option is not checked, the DN from the Subject field in the certificate will be used.</li> +<li>address - the type is the IP address.</li> +<li>fqdn - the type is a FQDN (fully-qualified domain name).</li> +<li>keyid - the type is a KEY_ID (file)</li> +<li>user_fqdn - the type is a USER_FQDN (user fully-qualified domain name).</li> +</ul> + Automatic keying has a property called perfect forward secrecy. This is the Diffie Helman group for PFS. + + + This is the type of the local ID (default: asn1dn)<br> +<ul> +<li>asn1dn - the type is an ASN.1 distinguished name. Use 'use email address as identifier' in certificate settings if it should be the mail address. If this option is not checked, the DN from the Subject field in the certificate will be used.</li> +<li>address - the type is the IP address.</li> +<li>fqdn - the type is a FQDN (fully-qualified domain name).</li> +<li>keyid - the type is a KEY_ID (file)</li> +<li>user_fqdn - the type is a USER_FQDN (user fully-qualified domain name).</li> +</ul> + + + + + + + + + spacer10 + + + Horizontal + + + Expanding + + + + 53 + 31 + + + + + + + + + + klineedit.h + kcombobox.h + klineedit.h + klineedit.h + klineedit.h + klineedit.h + klineedit.h + kcombobox.h + kcombobox.h + + diff --git a/src/newprofilewizardgeneral.ui b/src/newprofilewizardgeneral.ui new file mode 100644 index 0000000..544c69a --- /dev/null +++ b/src/newprofilewizardgeneral.ui @@ -0,0 +1,168 @@ + +NewProfileWizardGeneral + + + NewProfileWizardGeneral + + + + 0 + 0 + 313 + 254 + + + + New profile wizard general + + + + unnamed + + + + layout29 + + + + unnamed + + + + textLabel2 + + + General settings + + + + + layout28 + + + + unnamed + + + + DescriptionLineEdit + + + Description of the new profile + + + + + LabelGateway_2 + + + Description: + + + + + gatewayLineEdit + + + Hostname or IP address of the VPN gateway to connect + + + + + + + + LabelGateway + + + VPN gateway: + + + + + NameLineEdit + + + Name for the new profile + + + + + + + + LabelGateway_3 + + + Profile name: + + + + + + + spacer18 + + + Vertical + + + Expanding + + + + 21 + 43 + + + + + + + + spacer31 + + + Horizontal + + + Expanding + + + + 41 + 20 + + + + + + spacer32 + + + Vertical + + + Expanding + + + + 20 + 41 + + + + + + + NameLineEdit + DescriptionLineEdit + gatewayLineEdit + + + + klineedit.h + klineedit.h + klineedit.h + + diff --git a/src/newprofilewizardnat.ui b/src/newprofilewizardnat.ui new file mode 100644 index 0000000..719bbb5 --- /dev/null +++ b/src/newprofilewizardnat.ui @@ -0,0 +1,201 @@ + +NewProfileWizardNat + + + NewProfileWizardNat + + + + 0 + 0 + 289 + 128 + + + + NAT settings + + + + unnamed + + + + layout10 + + + + unnamed + + + + layout9 + + + + unnamed + + + + layout8 + + + + unnamed + + + + UseUdpCheckbox + + + Use UDP + + + + + + For IPSec use UDP encapsulation (NAT-T). For openvpn <br>use UDP instead of TCP protocol. + + + For openvpn this causes using UDP instead of TCP protocol <br>(peer have to use the same protocol). + + + + + spacer39 + + + Horizontal + + + Expanding + + + + 50 + 20 + + + + + + UseNatCheckbox + + + Use NAT + + + Enable NAT support + + + You should enable this if you behind a firewall + + + + + + + layout9 + + + + unnamed + + + + UdpPortCheckbox + + + false + + + &UDP Encapsulation Port: + + + Alt+U + + + Use specified port number for IPSec NAT-T + + + + + UdpPortSpinbox + + + false + + + 65535 + + + 1 + + + 10000 + + + UDP port for NAT-T + + + + + spacer7_2 + + + Horizontal + + + Expanding + + + + 46 + 21 + + + + + + + + spacer27 + + + Vertical + + + Expanding + + + + 20 + 150 + + + + + + + + spacer26 + + + Horizontal + + + Expanding + + + + 201 + 21 + + + + + + + + + diff --git a/src/newprofilewizardnetwork.ui b/src/newprofilewizardnetwork.ui new file mode 100644 index 0000000..2720385 --- /dev/null +++ b/src/newprofilewizardnetwork.ui @@ -0,0 +1,507 @@ + +NewProfileWizardNetwork + + + NewProfileWizardNetwork + + + + 0 + 0 + 461 + 267 + + + + Network settings + + + + unnamed + + + + layout28 + + + + unnamed + + + + layout27 + + + + unnamed + + + + layout11 + + + + unnamed + + + + spacer169 + + + Horizontal + + + Expanding + + + + 252 + 20 + + + + + + LabelNetworkDevice + + + true + + + Network device + + + + + NetworkDeviceComboBox + + + true + + + Network device for use with tunnel + + + This the the network device which should be used for the tunnel. <br>Its only active if needed. If no selection made, <br>"default" is set for using the device where the defaultroute points to. + + + + + + + UseRemoteNetworkCheckBox + + + &Use remote network + + + Alt+U + + + + + RemoteNetworkGroupBox + + + false + + + Remote network + + + + unnamed + + + + LabelRemoteNetwork + + + false + + + Remote network: + + + + + layout77 + + + + unnamed + + + + RemoteNetAddrLineEdit + + + Remote network address + + + This is the remote network where the connection should going to. Use this at a PPTP connection for set another network than the retrieved IP is located. + + + + + RemoteNetDividetextLabel + + + / + + + + + + 8 + + + + + 9 + + + + + 10 + + + + + 11 + + + + + 12 + + + + + 13 + + + + + 14 + + + + + 15 + + + + + 16 + + + + + 17 + + + + + 18 + + + + + 19 + + + + + 20 + + + + + 21 + + + + + 22 + + + + + 23 + + + + + 24 + + + + + 25 + + + + + 26 + + + + + 27 + + + + + 28 + + + + + 29 + + + + + 30 + + + + + 31 + + + + + 32 + + + + RemoteNetMaskComboBox + + + 16 + + + + + + + + + layout58 + + + + unnamed + + + + MtuCheckbox + + + Userdefined &MTU: + + + Alt+M + + + Check this to set a custom MTU size + + + If you enable this you can set a own MTU size. + + + + + MtuSpinbox + + + false + + + 1500 + + + 1200 + + + 1492 + + + The MTU size for the ppp connection + + + Here you can specify the MTU size for use with pppd. + + + + + spacer54 + + + Horizontal + + + Expanding + + + + 71 + 20 + + + + + + MruCheckbox + + + Userdefined M&RU: + + + Alt+R + + + Check this to set a custom MTU size + + + If you enable this you can set a own MTU size. + + + + + MruSpinbox + + + false + + + 1500 + + + 1200 + + + 1492 + + + The MTU size for the ppp connection + + + Here you can specify the MTU size for use with pppd. + + + + + + + layout57 + + + + unnamed + + + + TunnelDeviceTypeLabel + + + false + + + Tunnel device type: + + + + + layout22 + + + + unnamed + + + + spacer15 + + + Horizontal + + + Expanding + + + + 181 + 21 + + + + + + TunnelDeviceTypeComboBox + + + false + + + + + + + + + spacer14 + + + Vertical + + + Expanding + + + + 20 + 30 + + + + + + + + spacer13 + + + Horizontal + + + Expanding + + + + 16 + 20 + + + + + + + + + NetworkDeviceComboBox + + + useRemoteNetworkToggled(bool) + + + + kcombobox.h + klineedit.h + klineedit.h + kcombobox.h + kcombobox.h + + diff --git a/src/newprofilewizardnetworkroute.ui b/src/newprofilewizardnetworkroute.ui new file mode 100644 index 0000000..65e1150 --- /dev/null +++ b/src/newprofilewizardnetworkroute.ui @@ -0,0 +1,258 @@ + +NewProfileWizardNetworkRoute + + + NewProfileWizardNetworkRoute + + + + 0 + 0 + 402 + 403 + + + + + 3 + 3 + 0 + 0 + + + + New profile wizard Network Route Options + + + + unnamed + + + + layout17 + + + + unnamed + + + + layout14 + + + + unnamed + + + + + Keep default route + + + + + Replace default route + + + + DefaultRouteComboBox + + + + + spacer12 + + + Horizontal + + + Expanding + + + + 278 + 21 + + + + + + + + UseExtraNetworkRoutesCheckbox + + + true + + + &Use additional network routes + + + Alt+U + + + + + + Network + + + true + + + true + + + + + Netmask + + + true + + + true + + + + + Gateway + + + true + + + true + + + + + Device + + + true + + + true + + + + NetworkListView + + + false + + + + 0 + 150 + + + + List of additional network routes + + + + + layout52 + + + + unnamed + + + + spacer31_2 + + + Horizontal + + + Expanding + + + + 241 + 20 + + + + + + AddRoutePushButton + + + false + + + Add &route... + + + Alt+R + + + Add new route + + + + + DeleteNetworkRoutePushButton + + + false + + + De&lete + + + Alt+L + + + Delete route + + + + + + + + + + + AddRoutePushButton + clicked() + NewProfileWizardNetworkRoute + addNetworkRouteClicked() + + + DeleteNetworkRoutePushButton + clicked() + NewProfileWizardNetworkRoute + delNetworkRouteClicked() + + + UseExtraNetworkRoutesCheckbox + toggled(bool) + NewProfileWizardNetworkRoute + additionalNetworkRoutesToggled(bool) + + + + UseExtraNetworkRoutesCheckbox + NetworkListView + AddRoutePushButton + DeleteNetworkRoutePushButton + + + additionalNetworkRoutesToggled(bool) + addNetworkRouteClicked() + delNetworkRouteClicked() + + + + kcombobox.h + klistview.h + kpushbutton.h + kpushbutton.h + + diff --git a/src/newprofilewizardopenvpn.ui b/src/newprofilewizardopenvpn.ui new file mode 100644 index 0000000..009a8fd --- /dev/null +++ b/src/newprofilewizardopenvpn.ui @@ -0,0 +1,707 @@ + +NewProfileWizardOpenvpn +Christoph Thielecke + + + NewProfileWizardOpenvpn + + + + 0 + 0 + 518 + 536 + + + + New profile wizard OpenVPN + + + + unnamed + + + + layout50 + + + + unnamed + + + + textLabel3 + + + OpenVPN specific settings + + + + + layout49 + + + + unnamed + + + + TlsRemoteHostLineEdit + + + false + + + Common name, X509 name or common name prefix + + + + + TunnelDeviceTypeComboBox + + + Type of tunnel device for virtual network. Use tun for routed network, and tap for ethernet bridging. + + + This is the type of your tunnel device. It can be tun (virtual Point-to-Point network device) or tap (virtual ethernet network device). Your administrator will tell you which you have to use. Default is to use the tun device. + + + + + UserdefiniedCipherComboBox + + + false + + + Cipher algorithm + + + + + layout47 + + + + unnamed + + + + UseTlsAuthCheckBox + + + Use TLS auth: + + + + + + Add an additional TLS authentication + + + + + spacer38 + + + Horizontal + + + Expanding + + + + 101 + 20 + + + + + + + + layout44 + + + + unnamed + + + + UseUserdefinedPortCheckBox + + + Use specified remote port: + + + Use non standard TCP/UDP port + + + + + spacer6 + + + Horizontal + + + Expanding + + + + 119 + 20 + + + + + + + + NsCertTypeComboBox + + + Certificate type + + + + + TlsAuthURLRequester + + + false + + + File name of the static key or passphrase file + + + + + layout48 + + + + unnamed + + + + UseTlsRemoteHostCheckBox + + + Accept onl&y peer with common name: + + + Alt+Y + + + Accept connections only from a host with X509 name <br>or common name equal to specified name + + + + + spacer39 + + + Horizontal + + + Expanding + + + + 31 + 20 + + + + + + + + layout18_2 + + + + unnamed + + + + AllowIpAddressChangeOfPeerCheckBox + + + Allow IP address change of peer (for DHCP) + + + + + + + + + + + spacer6_2_2 + + + Horizontal + + + Expanding + + + + 191 + 20 + + + + + + + + UserdefinedPortSpinBox + + + 65535 + + + 1 + + + 1194 + + + Port number + + + + + layout18 + + + + unnamed + + + + DisableLzoCompressionCheckBox + + + Disable L&ZO compression + + + Alt+Z + + + + + + + + spacer6_2 + + + Horizontal + + + Expanding + + + + 191 + 20 + + + + + + + + layout46 + + + + unnamed + + + + UseUserdefiniedCipherCheckBox + + + Use specified cipher: + + + Use non standard cipher algorithm + + + + + spacer7_3 + + + Horizontal + + + Expanding + + + + 119 + 20 + + + + + + + + layout45 + + + + unnamed + + + + TunnelDeviceTypeLabel + + + Tunnel device type: + + + + + + + + spacer5 + + + Horizontal + + + Expanding + + + + 119 + 21 + + + + + + + + layout43 + + + + unnamed + + + + UseNsCertTypeCheckBox + + + Re&quire peer ns cert type: + + + Alt+Q + + + Require that peer certificate was signed with an explicit nsCertType destination of "client" or "server" + + + + + spacer7 + + + Horizontal + + + Expanding + + + + 119 + 20 + + + + + + + + + + groupBox1 + + + HTTP proxy + + + + unnamed + + + + layout11 + + + + unnamed + + + + HttpProxyLineEdit + + + false + + + Name or IP address of the proxy server + + + + + layout10 + + + + unnamed + + + + TimeoutTextLabel + + + false + + + Timeout + + + Timeout in seconds + + + + + spacer13 + + + Horizontal + + + Expanding + + + + 101 + 21 + + + + + + HttpProxyTimeoutIntSpinBox + + + false + + + 5 + + + Timeout in seconds + + + + + + + PortTextextLabel + + + false + + + Port + + + Proxy server port number + + + + + UseHttpProxyCheckBox + + + Use &HTTP proxy + + + Alt+H + + + Connect via HTTP proxy + + + + + HostTextLabel + + + false + + + Host + + + Name or IP address of the proxy server + + + + + spacer7_2_2_2 + + + Horizontal + + + Expanding + + + + 220 + 20 + + + + + + spacer14 + + + Horizontal + + + Expanding + + + + 221 + 20 + + + + + + layout9_2 + + + + unnamed + + + + spacer12 + + + Horizontal + + + Expanding + + + + 110 + 21 + + + + + + HttpProxyPortIntNumInput + + + false + + + 65535 + + + 1 + + + 8080 + + + Proxy server port number + + + + + + + + + + + spacer57 + + + Vertical + + + Expanding + + + + 20 + 117 + + + + + + + + + TunnelDeviceTypeComboBox + UseUserdefinedPortCheckBox + UserdefinedPortSpinBox + UseNsCertTypeCheckBox + NsCertTypeComboBox + UseUserdefiniedCipherCheckBox + UserdefiniedCipherComboBox + UseTlsAuthCheckBox + TlsAuthURLRequester + UseTlsRemoteHostCheckBox + TlsRemoteHostLineEdit + DisableLzoCompressionCheckBox + UseHttpProxyCheckBox + HttpProxyLineEdit + HttpProxyPortIntNumInput + HttpProxyTimeoutIntSpinBox + + + userdefinedOpenvpnPortToggeled(bool) + useUserdefiniedCipherToggled(bool) + useTlsAuthToggled(bool) + useTlsRemoteHostToggled(bool) + useHttpProxyToggeled(bool) + authenticateWithUsernameAndPasswordToggled(bool) + + + + kcombobox.h + kcombobox.h + kcombobox.h + kurlrequester.h + klineedit.h + kpushbutton.h + knuminput.h + knuminput.h + + diff --git a/src/newprofilewizardopenvpnauth.ui b/src/newprofilewizardopenvpnauth.ui new file mode 100644 index 0000000..9950816 --- /dev/null +++ b/src/newprofilewizardopenvpnauth.ui @@ -0,0 +1,245 @@ + +NewProfileWizardOpenvpnAuth +Christoph Thielecke + + + NewProfileWizardOpenvpnAuth + + + + 0 + 0 + 518 + 183 + + + + New profile wizard OpenVPN + + + + unnamed + + + + layout66 + + + + unnamed + + + + layout65 + + + + unnamed + + + + textLabel3 + + + OpenVPN authentication settings + + + + + layout17 + + + + unnamed + + + + AuthWithUsernameAndPasswordCheckBox + + + Authenticate &with username and password + + + Alt+W + + + Authenticate with server using username and password + + + + + spacer7_2 + + + Horizontal + + + Expanding + + + + 191 + 20 + + + + + + + + layout98 + + + + unnamed + + + + UseOnlyCaCertAndUserAuthCheckBox + + + false + + + Use onl&y CA cert and authenticate with username and password + + + Alt+Y + + + + + + + + spacer7_2_2_4 + + + Horizontal + + + Expanding + + + + 46 + 20 + + + + + + + + layout64 + + + + unnamed + + + + layout63 + + + + unnamed + + + + UseAuthenticationAlgorithmCheckBox + + + Use authentication method: + + + Use non standard authentication algorithm + + + + + spacer7_3_2 + + + Horizontal + + + Expanding + + + + 233 + 20 + + + + + + + + UserdefiniedDigestComboBox + + + false + + + Cipher algorithm + + + + + + + spacer57 + + + Vertical + + + Expanding + + + + 20 + 16 + + + + + + + + spacer43 + + + Horizontal + + + Expanding + + + + 494 + 20 + + + + + + + + + AuthWithUsernameAndPasswordCheckBox + + + useUserdefiniedCipherToggled(bool) + useTlsAuthToggled(bool) + useTlsRemoteHostToggled(bool) + useHttpProxyToggeled(bool) + userdefinedOpenvpnPortToggeled(bool) + + + + kcombobox.h + + diff --git a/src/newprofilewizardopenvpnselection.ui b/src/newprofilewizardopenvpnselection.ui new file mode 100644 index 0000000..d064772 --- /dev/null +++ b/src/newprofilewizardopenvpnselection.ui @@ -0,0 +1,97 @@ + +NewProfileWizardOpenvpnSelection + + + NewProfileWizardOpenvpnSelection + + + + 0 + 0 + 275 + 176 + + + + OpenVPN selection + + + + unnamed + + + + buttonGroup2 + + + Import or configure manually + + + + unnamed + + + + OpenvpnImportRadioButton + + + Import &OpenVPN config file + + + Alt+O + + + true + + + + + EnterManuallyRadioButton + + + Enter data &manually + + + Alt+M + + + + + + + spacer15 + + + Vertical + + + Expanding + + + + 31 + 311 + + + + + + spacer16 + + + Horizontal + + + Expanding + + + + 351 + 20 + + + + + + + diff --git a/src/newprofilewizardp12certselection.ui b/src/newprofilewizardp12certselection.ui new file mode 100644 index 0000000..2868ab1 --- /dev/null +++ b/src/newprofilewizardp12certselection.ui @@ -0,0 +1,134 @@ + +NewProfileWizardP12CertSelection + + + NewProfileWizardP12CertSelection + + + + 0 + 0 + 280 + 158 + + + + P12 certificate selection + + + + unnamed + + + + layout81 + + + + unnamed + + + + layout80 + + + + unnamed + + + + UseSmartcardCheckBox + + + Enable PKCS11 s&martcard support + + + Alt+M + + + + + + + + P12Group + + + Certificate in PKCS12 format? + + + Choose yes, if you have a file named: *.p12. It will be converted for use with KVpnc. + + + + unnamed + + + + P12CertNoRadioButton + + + &No + + + Alt+N + + + + + P12CertYesRadioButton + + + &Yes + + + Alt+Y + + + true + + + + + + + spacer73 + + + Vertical + + + Expanding + + + + 20 + 160 + + + + + + + + spacer72 + + + Horizontal + + + Expanding + + + + 111 + 20 + + + + + + + + + diff --git a/src/newprofilewizardpptp.ui b/src/newprofilewizardpptp.ui new file mode 100644 index 0000000..08485fc --- /dev/null +++ b/src/newprofilewizardpptp.ui @@ -0,0 +1,537 @@ + +NewProfileWizardPptp + + + NewProfileWizardPptp + + + + 0 + 0 + 557 + 494 + + + + New profile wizard PPTP + + + + unnamed + + + + layout14 + + + + unnamed + + + + layout13 + + + + unnamed + + + + DnsGroupBox + + + DNS options + + + + unnamed + + + + DnsServerCheckbox + + + Use specified DNS server: + + + Use specified DNS server instead of retrieved from peer + + + + + SearchDomainInResolvConfLineedit + + + false + + + + + + IP address of the DNS server (no hostname) + + + + + UseSearchDomainInResolvConfCheckbox + + + Use specified DNS search domain: + + + Use specified DNS server instead of retrieved from peer + + + + + DnsServerLineedit + + + false + + + + + + IP address of the DNS server (no hostname) + + + + + DomainInResolvConfLineedit + + + false + + + + + + IP address of the DNS server (no hostname) + + + + + UseDomainInResolvConfCheckbox + + + Use specified DNS domain: + + + Use specified DNS server instead of retrieved from peer + + + + + + + PppOptionsGroupBox + + + PPP options + + + + unnamed + + + + DisableCcpCheckbox + + + Disable CCP negotiation + + + + + + Disable Compression Control Protocol negotiation + + + Check to disabe CCP (Compression Control Protocol) negotiation. This option should only be required if the peer is buggy and gets confused by requests from pppd for CCP negotiation. + + + + + UseNoDeflateCheckbox + + + Do not use deflate met&hod + + + Alt+H + + + Do not use deflate decompression method (disabled by default) + + + + + DisableProtocolFieldCompressionCheckbox + + + Disable protocol field compression + + + + + + Disable protocol field compression negotiation + + + Disable protocol field compression negotiation in both the receive and the transmit direction + + + + + DisableAdressControlCompressionCheckbox + + + Disable adress control compression + + + + + + Disable Address/Control compression in both directions + + + Disable Address/Control compression in both directions (send and receive). + + + + + UseNoBsdCompCheckbox + + + Do not use BSD compression + + + + + + Do not use BSD compression (disabled by default) + + + + + UseNoIpDefaultCheckbox + + + Use no IP b&y default + + + Alt+Y + + + + + DisableMagicNumberNegotiationCheckbox + + + Disable magic number negotiation + + + + + + Disables the magic number negotiation + + + Disable magic number negotiation. With this option, pppd cannot detect a looped-back line. This option should only be needed if the peer is buggy. + + + + + DisableHeaderCompressionCheckbox + + + Disable TCP/IP header compression + + + + + + Disables the Van Jacobson style TCP/IP header compression + + + Disables the Van Jacobson style TCP/IP header compression in both the transmit and the receive direction. + + + + + DisableIpxCheckbox + + + Disable IPX + + + + + + Disables the IPXCP and IPX protocols + + + Disables the IPXCP and IPX protocols. This option should only be required if the peer is buggy and gets confused by requests from pppd for IPXCP negotiation. + + + + + + + MppeOptionsGroupBox + + + MPPE options + + + + unnamed + + + + RequireMppeCheckbox + + + Re&quire MPPE + + + Alt+Q + + + Require Microsoft Point-To-Point Encrpytion (enabled by default) + + + + + Refuse40BitEncryptionCheckbox + + + Refuse &40 bit encryption + + + Alt+4 + + + Refuse 40 bit length encryption of MPPE + + + + + Refuse128BitEncryptionCheckbox + + + Refuse 1&28 bit encryption + + + Alt+2 + + + Refuse 128 bit length encryption of MPPE + + + + + AllowStatefulModeCheckbox + + + Allo&w MPPE stateful mode + + + Alt+W + + + Check this for allow stateful mode of MPPE + + + + + UseNoMPPECompressionCheckbox + + + Do not use &MPPC compression + + + Alt+M + + + Do not use the Microsoft Poit-To-Point Compression protocol. <br>I.e. for compatibility with watchguard firebox (disabled by default) + + + Check this for disable Microsoft Point-to-Point Compression (MPPC) (i.e. for compatibility with watchguard firebox). + + + + + + + AuthGroupBox + + + Authentication + + + + unnamed + + + + layout8 + + + + unnamed + + + + layout7 + + + + unnamed + + + + textLabel1 + + + Authorization method: + + + + + AuthMethodComboBox + + + + + + + RequireEapCheckbox + + + Re&quire EAP + + + Alt+Q + + + Require EAP (disabled by default), should be disabled + + + + + + + + + layout7_2 + + + + unnamed + + + + layout6 + + + + unnamed + + + + L2tpdDaemonLabel + + + L2TP daemon + + + + + spacer4 + + + Horizontal + + + Expanding + + + + 111 + 21 + + + + + + + + + l2tpd/xl2tpd + + + + + openl2tp + + + + L2tpDaemonComboBox + + + + + + + spacer3 + + + Vertical + + + Expanding + + + + 20 + 165 + + + + + + + + spacer11 + + + Horizontal + + + Expanding + + + + 49 + 31 + + + + + + + + + useNtDomainNameToggled(bool) + + + + klineedit.h + klineedit.h + klineedit.h + kcombobox.h + kcombobox.h + + diff --git a/src/newprofilewizardpsk.ui b/src/newprofilewizardpsk.ui new file mode 100644 index 0000000..e6d3462 --- /dev/null +++ b/src/newprofilewizardpsk.ui @@ -0,0 +1,257 @@ + +NewProfileWizardPsk + + + NewProfileWizardPsk + + + + 0 + 0 + 449 + 249 + + + + PSK settings + + + + unnamed + + + + layout4 + + + + unnamed + + + + layout3 + + + + unnamed + + + + LabelPsk + + + true + + + Pre-shared key: + + + + + CheckSavePsk + + + Sa&ve PSK + + + Alt+V + + + Save Pre-shared key in config file (or in KWallet if available) + + + + + LabelPskFile + + + false + + + Pre shared key file: + + + + + spacer38 + + + Horizontal + + + Expanding + + + + 130 + 20 + + + + + + spacer30 + + + Horizontal + + + Expanding + + + + 174 + 20 + + + + + + PSKFileURLRequester + + + false + + + + 250 + 0 + + + + File which contains Pre-shared key (shared secret) + + + + + spacer18 + + + Horizontal + + + Expanding + + + + 165 + 20 + + + + + + PSKLineEdit + + + true + + + Password + + + Pre-shared key for authentication (shared secret) + + + + + spacer37 + + + Horizontal + + + Expanding + + + + 147 + 20 + + + + + + PskInFileCheckBox + + + &Load PSK from file + + + Alt+L + + + Pre-shared key (shared secret) is stored in a file (e.g. on a usbstick) + + + + + + + spacer21 + + + Vertical + + + Expanding + + + + 20 + 301 + + + + + + + + spacer57 + + + Horizontal + + + Expanding + + + + 51 + 20 + + + + + + spacer58 + + + Vertical + + + Expanding + + + + 20 + 41 + + + + + + + PskInFileCheckBox + CheckSavePsk + PSKFileURLRequester + PSKLineEdit + + + + kurlrequester.h + klineedit.h + kpushbutton.h + klineedit.h + + diff --git a/src/newprofilewizardracoon.ui b/src/newprofilewizardracoon.ui new file mode 100644 index 0000000..39cd4e2 --- /dev/null +++ b/src/newprofilewizardracoon.ui @@ -0,0 +1,779 @@ + +NewProfileWizardRacoon + + + NewProfileWizardRacoon + + + + 0 + 0 + 449 + 539 + + + + New profile wizard racoon + + + + unnamed + + + + layout66 + + + + unnamed + + + + layout65 + + + + unnamed + + + + InfoLabel + + + racoon + ipsec-tools specific settings (Linux &2.6 native or BSD) + + + + + layout62 + + + + unnamed + + + + EncryptionAlgorithm2ComboBox + + + + + + + + EncryptionAlgorithmComboBox + + + + + + + + AuthenticationAlgorithm2ComboBox + + + + + + + + layout61 + + + + unnamed + + + + PerfectForwardSecurityCheckbox + + + Perfect forward secrec&y (PFS): + + + Alt+Y + + + Use perfect forward secrety (PFS) + + + + + spacer34_2 + + + Horizontal + + + Expanding + + + + 101 + 20 + + + + + + + + layout71_2 + + + + unnamed + + + + EncryptionAlgorithm2TextLabel_2 + + + Encryption algorithm phase 2: + + + + + spacer71_2 + + + Horizontal + + + Expanding + + + + 101 + 21 + + + + + + + + ExchangeModeComboBox + + + Internet Key Exchange mode + + + + + layout69 + + + + unnamed + + + + HashAlgoTextLabel + + + Authentication algorithm phase 1: + + + Use specified hash algorithm for IKE phase 1 + + + + + spacer69 + + + Horizontal + + + Expanding + + + + 101 + 21 + + + + + + + + DHGroupComboBox + + + false + + + Diffie Hellman group + + + This define the group used for the Diffie-Hellman exponentiations. The following assignment is used: +dh1 = modp768 +dh2 = modp1024 +dh5 = modp1536 +d14 = modp2048 (only racoon) +dh15 = modp3072 (only racoon) +dh16 = modp4096 (only racoon) +dh17 = modp6144 (only racoon) +dh18 = modp8192 (only racoon) + + + + + HashAlgoComboBox + + + Use specified hash algorithm for IKE phase 1 + + + + + layout71 + + + + unnamed + + + + EncryptionAlgorithm2TextLabel + + + Encryption algorithm phase 1: + + + + + spacer71 + + + Horizontal + + + Expanding + + + + 101 + 21 + + + + + + + + layout37 + + + + unnamed + + + + IkeGroupCheckbox + + + &IKE DH group: + + + Alt+I + + + Use special Diffie Hellman group + + + + + spacer33_2 + + + Horizontal + + + Expanding + + + + 61 + 21 + + + + + + + + PerfectForwardSecrecyCombobox + + + false + + + Diffie Helman group for Perfect Forward Secrecy + Automatic keying has a property called perfect forward secrecy. This is the Diffie Helman group for PFS. + + + This is the Diffie Helman group for PFS. +The following assignment will is used: +server = DH group is recieved from server (cisco only) +nopfs = no pfs is used +dh1 = modp768 +dh2 = modp1024 +dh5 = modp1536 +d14 = modp2048 (racoon only) +dh15= modp3072 (racoon only) +dh16 = modp4096 (racoon only) +dh17 = modp6144 (racoon only) +dh18 = modp8192 (racoon only) + + + + + layout72 + + + + unnamed + + + + HashAlgoTextLabel_2 + + + Exchange mode: + + + + + spacer72 + + + Horizontal + + + Expanding + + + + 91 + 21 + + + + + + + + layout70_2 + + + + unnamed + + + + AuthenticationAlgorithm2TextLabel_2 + + + Authentication algorithm phase 2: + + + + + spacer70_2 + + + Horizontal + + + Expanding + + + + 81 + 21 + + + + + + + + + + layout75 + + + + unnamed + + + + UseModeConfigCheckBox + + + &Use Mode Configuration + + + Alt+U + + + + + + + layout90_2 + + + + unnamed + + + + UseXauthCheckBox + + + Authenticate &with username and password (XAUTH) + + + Alt+W + + + enable this if you want enable the XAUTh extension + + + + + spacer6_2_2 + + + Horizontal + + + Expanding + + + + 100 + 20 + + + + + + + + RemoteIdentifierGroupBox + + + Remote identifier + + + + unnamed + + + + layout74_2 + + + + unnamed + + + + layout73_2 + + + + unnamed + + + + HashAlgoTextLabel_2_2_2 + + + ID type + + + + + spacer72_2_3 + + + Horizontal + + + Expanding + + + + 51 + 20 + + + + + + + + RemoteIDLineEdit + + + false + + + Normal + + + Value for the local ID + + + + + layout72_2 + + + + unnamed + + + + RemoteIDLabel + + + ID value + + + + + spacer72_2_2_2 + + + Horizontal + + + Expanding + + + + 51 + 20 + + + + + + + + RemoteIdTypeCombobox + + + false + + + + Automatic keying has a property called perfect forward secrecy. This is the Diffie Helman group for PFS. + + + + + + + + + + + + LocalIdentifierGroupBox + + + Local identifier + + + + unnamed + + + + layout74 + + + + unnamed + + + + layout73 + + + + unnamed + + + + HashAlgoTextLabel_2_2 + + + ID type + + + + + spacer72_2 + + + Horizontal + + + Expanding + + + + 51 + 20 + + + + + + + + LocalIDLineEdit + + + false + + + Normal + + + Value for the local ID + + + + + layout72_3 + + + + unnamed + + + + LocalIDLabel + + + ID value + + + + + spacer72_2_2 + + + Horizontal + + + Expanding + + + + 51 + 20 + + + + + + + + LocalIdTypeCombobox + + + false + + + + Automatic keying has a property called perfect forward secrecy. This is the Diffie Helman group for PFS. + + + + + + + + + + + + spacer3 + + + Vertical + + + Expanding + + + + 20 + 20 + + + + + + + + spacer44 + + + Horizontal + + + Expanding + + + + 51 + 20 + + + + + + + + + + LocalIdTypeCombobox + activated(const QString&) + NewProfileWizardRacoon + localIDTypeToggled(const QString&) + + + RemoteIdTypeCombobox + activated(const QString&) + NewProfileWizardRacoon + remoteIDTypeToggled(const QString&) + + + + useLeftNextHopToggled(bool) + useRightNextHopToggled(bool) + remoteIDTypeToggled(const QString&) + localIDTypeToggled(const QString&) + + + + kcombobox.h + kcombobox.h + klineedit.h + kcombobox.h + klineedit.h + kcombobox.h + + diff --git a/src/newprofilewizardstart.ui b/src/newprofilewizardstart.ui new file mode 100644 index 0000000..a43b5e2 --- /dev/null +++ b/src/newprofilewizardstart.ui @@ -0,0 +1,69 @@ + +NewProfileWizardStart + + + NewProfileWizardStart + + + + 0 + 0 + 410 + 146 + + + + Welcome + + + + unnamed + + + + textLabel1 + + + Welcome to this wizard which will help you to create a new profile. + +Click "Next" to continue. + + + + + spacer66 + + + Vertical + + + Expanding + + + + 20 + 31 + + + + + + spacer67 + + + Horizontal + + + Expanding + + + + 61 + 20 + + + + + + + diff --git a/src/newprofilewizardtypeselection.ui b/src/newprofilewizardtypeselection.ui new file mode 100644 index 0000000..a1d9b04 --- /dev/null +++ b/src/newprofilewizardtypeselection.ui @@ -0,0 +1,213 @@ + +NewProfileWizardTypeSelection + + + NewProfileWizardTypeSelection + + + + 0 + 0 + 355 + 440 + + + + New profile wizard type selection + + + + unnamed + + + + layout25 + + + + unnamed + + + + layout24 + + + + unnamed + + + + textLabel1 + + + Select the type of your VPN: + + + + + buttonGroup1 + + + Type + + + + unnamed + + + + CiscoRadioButton + + + &Cisco (free) + + + Alt+C + + + true + + + + + L2tpFreeswanRadioButton + + + &L2TP over IPSec (Free/SWAN or Openswan) + + + Alt+L + + + + + L2tpRacoonRadioButton + + + L2TP over IPSec (Linux 2.&6 native or BSD) + + + Alt+6 + + + + + PptpRadioButton + + + &Microsoft PPTP + + + Alt+M + + + + + OpenvpnRadioButton + + + Open&VPN + + + Alt+V + + + + + RacoonRadioButton + + + IPSec (Linux &2.6 native or BSD) + + + Alt+2 + + + + + FreeswanRadioButton + + + &IPSec (Free/SWAN or Openswan) + + + Alt+I + + + + + CiscoVpncRadioButton + + + Cisco (propritar&y) + + + Alt+Y + + + + + VtunRadioButton + + + &Vtun + + + Alt+V + + + + + SshRadioButton + + + &SSH + + + Alt+S + + + + + + + spacer65 + + + Vertical + + + Expanding + + + + 20 + 105 + + + + + + + + spacer64 + + + Horizontal + + + Expanding + + + + 16 + 20 + + + + + + + + + diff --git a/src/newprofilewizarduser.ui b/src/newprofilewizarduser.ui new file mode 100644 index 0000000..73387ff --- /dev/null +++ b/src/newprofilewizarduser.ui @@ -0,0 +1,224 @@ + +NewProfileWizardUser + + + NewProfileWizardUser + + + + 0 + 0 + 363 + 192 + + + + User settings + + + + unnamed + + + + layout57 + + + + unnamed + + + + layout56 + + + + unnamed + + + + NtDomainNameLineedit + + + false + + + NT domain name for authentication + + + + + NtDomainNameCheckbox + + + false + + + N&T domain name for authentication: + + + Alt+T + + + Use NT domain for authentication + + + + + UsernameLineEdit + + + Username for authentication + + + + + PasswordEdit + + + Password + + + Password for authentication + + + + + layout54 + + + + unnamed + + + + LabelUsername + + + Username: + + + + + spacer61 + + + Horizontal + + + Expanding + + + + 211 + 21 + + + + + + + + layout55 + + + + unnamed + + + + LabelPassword + + + Password: + + + + + spacer62 + + + Horizontal + + + Expanding + + + + 211 + 21 + + + + + + + + + + layout52 + + + + unnamed + + + + CheckUserPass + + + Save &user password + + + Alt+U + + + Save user password in config file (or in KWallet if available) + + + + + DontSaveUsernameCheckBox + + + Dont sa&ve username + + + Alt+V + + + Do not save the username in config nor KWallet + + + + + + + spacer2 + + + Vertical + + + Expanding + + + + 20 + 48 + + + + + + + + + domainNameToggled(bool) + + + + klineedit.h + klineedit.h + + diff --git a/src/openvpnmanagementhandler.cpp b/src/openvpnmanagementhandler.cpp new file mode 100644 index 0000000..02e73f8 --- /dev/null +++ b/src/openvpnmanagementhandler.cpp @@ -0,0 +1,925 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* contains some code from openvpn-kde-dialogs.pl which is * +* written by Alon Bar-Lev * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +//BEGIN INCLUDES +#include "openvpnmanagementhandler.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include "kvpncconfig.h" +#include "utils.h" +#include "enterxauthinteractivepasscodedialog.h" +//END INCLUDES + +OpenvpnManagementHandler::OpenvpnManagementHandler( QObject *, KVpncConfig *GlobalConfig ) +{ + this->GlobalConfig = GlobalConfig; + fInHold = false; + gotGreeting=false; + connectedToManagementPort=false; + errormsg=""; + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: start", GlobalConfig->debug ); + +} + +OpenvpnManagementHandler::~OpenvpnManagementHandler() +{} + +void OpenvpnManagementHandler::closeConnection() +{ + if (socket) + { + //disconnect( socket, SIGNAL( connected() ), this, SLOT( socketConnected() ) ); + disconnect( socket, SIGNAL( connectionClosed() ), this, SLOT( socketConnectionClosed() ) ); + disconnect( socket, SIGNAL( readyRead() ), this, SLOT( socketReadyRead() ) ); + disconnect( socket, SIGNAL( error( int ) ), this, SLOT( socketError( int ) ) ); + disconnect( socket, SIGNAL( hostFound() ), this, SLOT( hostFound() ) ); + + socket->clearPendingData(); + socket->close(); + if ( socket->state() == QSocket::Closing ) + { + // We have a delayed close. + connect( socket, SIGNAL( delayedCloseFinished() ), this, SLOT( socketClosed() ) ); + } + else + { + // The socket is closed. + socketClosed(); + } + } +} + +void OpenvpnManagementHandler::socketConnectionClosed() +{ + + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "Disconnected to the OpenVPN manage port (%1)." ).arg( QString().setNum( GlobalConfig->OpenvpnManagementPort ) ), GlobalConfig->debug ); +} + +void OpenvpnManagementHandler::socketClosed() +{ + socketReallyClosed = false; + disconnect( socket, SIGNAL( delayedCloseFinished() ), this, SLOT( socketClosed() ) ); + delete socket; + greetingtimer.stop(); + disconnect ( &greetingtimer, SIGNAL ( timeout() ), this, SLOT ( greetingTimedOut() ) ); + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "Socket to the OpenVPN manage port (%1) closed." ).arg( QString().setNum( GlobalConfig->OpenvpnManagementPort ) ), GlobalConfig->debug ); + socketReallyClosed = true; +// emit terminate_openvpn(); +} + +void OpenvpnManagementHandler::socketConnected() +{ + + connect( socket, SIGNAL( connectionClosed() ), this, SLOT( socketConnectionClosed() ) ); + connect( socket, SIGNAL( readyRead() ), this, SLOT( socketReadyRead() ) ); + +// KMessageBox::error ( 0, QString("bar"), QString("foo") ); + connectedToManagementPort=true; + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "Connected to the OpenVPN manage port (%1)." ).arg( QString().setNum( GlobalConfig->OpenvpnManagementPort ) ), GlobalConfig->debug ); + + + socketReadyRead(); + +} + +void OpenvpnManagementHandler::socketError( int e ) +{ + // infoText->append( tr("Error number %1 occurred\n").arg(e) ); + if ( e != 0 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + QString().setNum( e ) , GlobalConfig->error ); +} + +void OpenvpnManagementHandler::greetingTimedOut() +{ + disconnect ( &greetingtimer, SIGNAL ( timeout() ), this, SLOT ( greetingTimedOut() ) ); + greetingtimer.stop(); + + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n("Got no greeting within %1 seconds from management interface, retrying.").arg("3"), GlobalConfig->error ); + + + closeConnection(); + while( ! socketReallyClosed ) + { + if (GlobalConfig->appPointer->hasPendingEvents()) + GlobalConfig->appPointer->processEvents(); + usleep(500); + } + doConnect(); +} + +void OpenvpnManagementHandler::sendToServer( QString cmd ) +{ + // write to the server + QTextStream os( socket ); + os << cmd << "\n"; +} + +void OpenvpnManagementHandler::socketReadyRead() +{ + bool abort=false; + if (socket) + { + if (socket->state() != QSocket::Closing && socket->state() != QSocket::Idle) + { + while ( !abort && socket->canReadLine() ) + { + QString line = socket->readLine(); + + // { + // QCString s; + // s.resize( socket->bytesAvailable() + 1 ); + // socket->readBlock( s.data(), socket->bytesAvailable() ); + // QString line( s ); + // { + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler raw: " + line, GlobalConfig->debug ); + + // if ( line.find( "NOOP", 0, FALSE ) > -1 ) + // { + // // NOOP + // } + // else if ( line.find( ">HOLD:", 0, FALSE ) > -1 ) { + // + // if ( GlobalConfig->KvpncDebugLevel > 2 ) + // GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "got %1 message." ).arg("'hold'"), GlobalConfig->debug ); + // + // fInHold = true; + // int ret = 0; + // do { + // ret = KMessageBox::questionYesNo ( 0, i18n( "Release hold?" ), i18n( "OpenVPN" ) ); + // } while ( ret != 0 ); + // + // sendToServer( "hold release\n" ); + // + // if ( GlobalConfig->KvpncDebugLevel > 2 ) + // GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "hold release sent." ), GlobalConfig->debug ); + // + // socket->close(); + // fInHold = false; + // } + + + if ( line.find( "INFO:OpenVPN Management Interface", 0, FALSE ) > -1 ) + { + gotGreeting=true; + disconnect ( &greetingtimer, SIGNAL ( timeout() ), this, SLOT ( greetingTimedOut() ) ); + greetingtimer.stop (); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n("Got greeting from management interface."), GlobalConfig->debug ); + + } + else if ( line.find( "> NEED - OK:", 0, FALSE ) > -1 ) + { + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "got %1 message" ).arg("'need ok'"), GlobalConfig->debug ); + + QString req = line.section( QRegExp( ".*'(.*)'. * MSG:( .* )" ), 0, 0 ); // $1; + QString msg = line.section( QRegExp( ".*'(.*)'. * MSG:( .* )" ), 1, 1 ); // $2; + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( QString("OpenvpnManagementHandler: req: ")+req+QString(", msg: ")+msg , GlobalConfig->debug ); + + //TODO: look for possible messages, msg2 is the translatable msg + QString msg2 = msg; + + int ret = KMessageBox::questionYesNo ( 0, msg2, i18n( "OpenVPN" ) ); + + + if ( ret == 0 ) + { + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( QString("OpenvpnManagementHandler: ") + QString("'needok': ok") , GlobalConfig->debug ); + + sendToServer( "needok \"" + req + "\" ok\n" ); + } + else + { + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( QString("OpenvpnManagementHandler: ") +QString( "'needok': cancel") , GlobalConfig->debug ); + + sendToServer( "needok \"" + req + "\" cancel\n" ); + } + if (socket) + socket->close(); + // if ( line.find( " >PASSWORD:", 0, FALSE ) > -1 ) { + // + // if ( GlobalConfig->KvpncDebugLevel > 2 ) + // GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "got %1 message" ).arg("'password'"), GlobalConfig->debug ); + // + // QString req = line.section( QRegExp( ".*'(.*)'.*" ), 0, 0 ); // $1; + // QCString password; + // QString pass = ""; + // int result = KPasswordDialog::getPassword( password, QString( req + i18n( " password:" ) ) ); + // QTextStream os( socket ); + // // os.setEncoding( QTextStream::UnicodeUTF8 ); + // if ( result == KPasswordDialog::Accepted ) { + // if ( GlobalConfig->KvpncDebugLevel > 2 ) + // GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "password got from user" ), GlobalConfig->debug ); + // pass = QString( password ); + // + // pass = pass.remove( '\r' ); + // pass = pass.remove( '\n' ); + // } else { + // pass = ""; + // } + // sendToServer( "password \"" + req + "\" \"" + pass + "\"\n" ); + } + else if ( line.find( "PASSWORD:Need 'Auth' username/password", 0, FALSE ) > -1 ) + { + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "got %1 message" ).arg("'need username/password'"), GlobalConfig->debug ); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "Send username..." ), GlobalConfig->debug ); + GlobalConfig->appendLogEntry( i18n( "Send username..." ), GlobalConfig->info ); + + if ( !GlobalConfig->currentProfile->getUserName().isEmpty() /* && !GlobalConfig->currentProfile->getDontSaveUsername() */ ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: username: " + GlobalConfig->currentProfile->getUserName(), GlobalConfig->debug ); + + sendToServer( "username Auth " + GlobalConfig->currentProfile->getUserName() + "\n" ); + } + else + { + if ( GlobalConfig->TmpUsername.isEmpty() ) + { + bool ok = false; + QString username = KInputDialog::getText ( i18n( "User name" ), i18n( "Enter username:" ), "", &ok ); + QTextStream os( socket ); + os.setEncoding( QTextStream::UnicodeUTF8 ); + if ( ok == true && !username.isEmpty() ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "username got from user" ), GlobalConfig->debug ); + GlobalConfig->TmpUsername = username; + + if ( GlobalConfig->KvpncDebugLevel > 5 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: username: " + GlobalConfig->TmpUsername, GlobalConfig->debug ); + + sendToServer( "username Auth " + GlobalConfig->TmpUsername + "\n" ); + } + else + { + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: username dialog canceled and username empty, stop.", GlobalConfig->info ); + abort = true; + } + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 5 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: username: " + GlobalConfig->TmpUsername, GlobalConfig->debug ); + sendToServer( "username Auth " + GlobalConfig->TmpUsername + "\n" ); + } + } + } + else if ( line.find( "SUCCESS: 'Auth' username entered", 0, FALSE ) > -1 ) + { + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "got %1 message" ).arg("SUCCESS: 'Auth' username entered"), GlobalConfig->debug ); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "Send password..." ), GlobalConfig->debug ); + GlobalConfig->appendLogEntry( i18n( "Send password..." ), GlobalConfig->info ); + + if ( !GlobalConfig->currentProfile->getUserPassword().isEmpty() /* && GlobalConfig->currentProfile->getSaveUserPassword() */ ) + { + // if ( GlobalConfig->KvpncDebugLevel > 5 ) + // GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: password: " +GlobalConfig->currentProfile->getUserPassword(), GlobalConfig->debug ); + + sendToServer( "password Auth " + GlobalConfig->currentProfile->getUserPassword() + "\n" ); + } + else + { + if ( GlobalConfig->TmpPassword.isEmpty() ) + { + QCString password; + QString pass = ""; + int result = KPasswordDialog::getPassword( password, QString( i18n( " password:" ) ) ); + QTextStream os( socket ); + // os.setEncoding( QTextStream::UnicodeUTF8 ); + if ( result == KPasswordDialog::Accepted ) + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "password got from user" ), GlobalConfig->debug ); + GlobalConfig->TmpPassword = QString( password ); + + + // if ( GlobalConfig->KvpncDebugLevel > 5 ) + // GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: password: "+GlobalConfig->TmpPassword, GlobalConfig->debug ); + + sendToServer( "password Auth " + GlobalConfig->TmpPassword + "\n" ); + } + else + { + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: password dialog canceled and password empty, stop.", GlobalConfig->info ); + abort = true; + } + } + else + { + // if ( GlobalConfig->KvpncDebugLevel > 5 ) + // GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: password: "+GlobalConfig->TmpPassword, GlobalConfig->debug ); + sendToServer( "password Auth " + GlobalConfig->TmpPassword + "\n" ); + + } + } + } + + // else if ( line.find( "SUCCESS: 'Auth' username entered", 0, FALSE ) > -1 ) { + // + // if ( GlobalConfig->KvpncDebugLevel > 2 ) + // GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "got %1 message, 2. step" ).arg("'need username/password'"), GlobalConfig->debug ); + // + // if ( GlobalConfig->KvpncDebugLevel > 2 ) + // GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "Send password..." ), GlobalConfig->debug ); + // + // if ( GlobalConfig->currentProfile->getUserPassword().isEmpty() ) + // sendToServer( "password Auth " + GlobalConfig->TmpPassword + "\"\n" ); + // else + // sendToServer( "password Auth " + GlobalConfig->currentProfile->getUserPassword() + "\"\n" ); + // + // } + + else if ( line.find( "PASSWORD:Need 'HTTP Proxy' username/password", 0, FALSE ) > -1 ) + { + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "got %1 message" ).arg("'HTTP Proxy password'"), GlobalConfig->debug ); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "Send HTTP Proxy username..." ), GlobalConfig->debug ); + GlobalConfig->appendLogEntry( i18n( "Send HTTP Proxy username..." ), GlobalConfig->info ); + + if ( !GlobalConfig->currentProfile->getHttpProxyUser().isEmpty() ) + { + if ( GlobalConfig->KvpncDebugLevel > 5 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: HTTP proxy user: " + GlobalConfig->currentProfile->getHttpProxyUser() , GlobalConfig->debug ); + + sendToServer( "username \"HTTP Proxy\"" + GlobalConfig->currentProfile->getHttpProxyUser() + "\n" ); + } + } + + else if ( line.find( "SUCCESS: 'HTTP Proxy' username entered", 0, FALSE ) > -1 ) + { + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "got %1 message" ).arg("SUCCESS: 'HTTP Proxy' username entered"), GlobalConfig->debug ); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "Send HTTP Proxy password..." ), GlobalConfig->debug ); + GlobalConfig->appendLogEntry( i18n( "Send HTTP Proxy password..." ), GlobalConfig->info ); + + if ( !GlobalConfig->currentProfile->getHttpProxyPass().isEmpty() ) + { + if ( GlobalConfig->KvpncDebugLevel > 5 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: HTTP proxy auth password: " + GlobalConfig->currentProfile->getHttpProxyPass(), GlobalConfig->debug ); + sendToServer( "password \"HTTP Proxy\"" + GlobalConfig->currentProfile->getHttpProxyPass() + "\n" ); + } + else + { + if ( GlobalConfig->TmpHttpProxyPassword.isEmpty() ) + { + QCString password; + QString pass = ""; + + QTextStream os( socket ); + os.setEncoding( QTextStream::UnicodeUTF8 ); + + GlobalConfig->TmpHttpProxyPassword = ""; + EnterXauthInteractivePasscodeDialog dlg( 0); + dlg.setCaption(i18n( "Enter HTTP proxy auth password" ) ); + dlg.main->DescriptionLabel->setText( i18n( "Enter HTTP proxy auth password:" ) ); + dlg.main->LabelPassword->setText( i18n( "HTTP proxy auth password:" ) ); + dlg.main->SavePasswordCheckBox->setText( i18n( "Save HTTP proxy auth password" ) ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[openvpn] " + i18n( "HTTP proxy auth password requested...\n" ), GlobalConfig->debug ); + if ( dlg.exec() ) + { + + pass = dlg.main->PasswordEdit->text(); + if ( !pass.isEmpty() ) + { + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "HTTP proxy auth password got from user" ), GlobalConfig->debug ); + + if ( dlg.main->SavePasswordCheckBox->isChecked() ) + { + // GlobalConfig->currentProfile->setSavePrivateKeyPassword(true); + GlobalConfig->currentProfile->setHttpProxyPass ( QString( pass ) ); + } + + GlobalConfig->TmpHttpProxyPassword = QString( pass ); + + if ( GlobalConfig->KvpncDebugLevel > 5 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: HTTP proxy auth password: " + GlobalConfig->TmpHttpProxyPassword, GlobalConfig->debug ); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "Send HTTP proxy auth password..." ), GlobalConfig->debug ); + + sendToServer( "password \"HTTP Proxy\"" + GlobalConfig->TmpHttpProxyPassword + "\n" ); + } + else + { + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: HTTP proxy auth password empty, stop.", GlobalConfig->error ); + abort = true; + } + } + else + { + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: password dialog canceled and HTTP proxy auth password empty, stop.", GlobalConfig->info ); + abort = true; + } + } + else + { + sendToServer( "password \"HTTP Proxy\"" + GlobalConfig->TmpHttpProxyPassword + "\n" ); + if ( GlobalConfig->KvpncDebugLevel > 5 ) + { + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: HTTP proxy auth password: " + GlobalConfig->TmpHttpProxyPassword, GlobalConfig->debug ); + GlobalConfig->appendLogEntry( QString( "OpenvpnManagementHandler: HTTP proxy auth password string: " ) + QString( "password \"HTTP Proxy\" " + GlobalConfig->TmpHttpProxyPassword + "\n" ), GlobalConfig->debug ); + } + } + } + } + + else if ( line.find( "PASSWORD:Need 'Private Key' password", 0, FALSE ) > -1 ) + { + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "got %1 message" ).arg("'private key password'"), GlobalConfig->debug ); + + if ( !GlobalConfig->currentProfile->getPrivateKeyPass().isEmpty() ) + { + // if ( GlobalConfig->KvpncDebugLevel > 5 ) + // GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: password: " + GlobalConfig->TmpPrivateKeyPass, GlobalConfig->debug ); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "Send private key password..." ), GlobalConfig->debug ); + GlobalConfig->appendLogEntry( i18n( "Send private key password..." ), GlobalConfig->info ); + + sendToServer( "password \"Private Key\" " + GlobalConfig->currentProfile->getPrivateKeyPass() + "\n" ); + } + else + { + if ( ( Utils(GlobalConfig).getNeedsPassphrase(GlobalConfig->TmpPrivateKeyPass) && GlobalConfig->TmpPrivateKeyPass.isEmpty() ) || GlobalConfig->currentProfile->getPrivateKeyPass().isEmpty() ) + { + GlobalConfig->TmpPassword = ""; + QCString password; + QString pass = ""; + + QTextStream os( socket ); + // os.setEncoding( QTextStream::UnicodeUTF8 ); + + GlobalConfig->TmpPrivateKeyPass = ""; + EnterXauthInteractivePasscodeDialog dlg( 0); + dlg.setCaption( i18n( "Enter private key password" ) ); + dlg.main->DescriptionLabel->setText( i18n( "Enter private key password to unlock private key:" ) ); + dlg.main->LabelPassword->setText( i18n( "Private key password:" ) ); + dlg.main->SavePasswordCheckBox->setText( i18n( "Save private key password" ) ); + dlg.resize(600,200); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[openvpn] " + i18n( "Password for private key requested...\n" ), GlobalConfig->debug ); + if ( dlg.exec() ) + { + + pass = dlg.main->PasswordEdit->text(); + if ( !pass.isEmpty() ) + { + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "private key password got from user" ), GlobalConfig->debug ); + + if ( dlg.main->SavePasswordCheckBox->isChecked() ) + { + GlobalConfig->currentProfile->setSavePrivateKeyPassword( true ); + GlobalConfig->currentProfile->setPrivateKeyPass( QString( pass ) ); + } + + GlobalConfig->TmpPrivateKeyPass = QString( pass ); + + // if ( GlobalConfig->KvpncDebugLevel > 5 ) + // GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: private key password: " + GlobalConfig->TmpPrivateKeyPass, GlobalConfig->debug ); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "Send private key password..." ), GlobalConfig->debug ); + + sendToServer( "password \"Private Key\" " + GlobalConfig->TmpPrivateKeyPass + "\n" ); + } + else + { + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: password empty, stop.", GlobalConfig->error ); + abort = true; + } + } + else + { + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: password dialog canceled and password empty, stop.", GlobalConfig->info ); + abort = true; + } + } + else + { + sendToServer( "password \"Private Key\" " + GlobalConfig->TmpPrivateKeyPass + "\n" ); + // if ( GlobalConfig->KvpncDebugLevel > 5 ) + // { + // GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: private key password: " + GlobalConfig->TmpPrivateKeyPass, GlobalConfig->debug ); + // GlobalConfig->appendLogEntry( QString("OpenvpnManagementHandler: private key password string: ") + QString("password \"Private Key\" " + GlobalConfig->TmpPrivateKeyPass + "\n"),GlobalConfig->debug); + // } + } + } + } + + else if ( line.find( "PASSWORD:Verification Failed: 'Private Key'", 0, FALSE ) > -1 ) + { + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "wrong private key password" ), GlobalConfig->debug ); + + GlobalConfig->TmpPassword = ""; + QCString password; + QString pass = ""; + + QTextStream os( socket ); + // os.setEncoding( QTextStream::UnicodeUTF8 ); + + GlobalConfig->TmpPrivateKeyPass = ""; + EnterXauthInteractivePasscodeDialog dlg( 0); + dlg.setCaption(i18n( "Enter private key password" ) ); + dlg.main->DescriptionLabel->setText( i18n( "Enter private key password to unlock private key:" ) ); + dlg.main->LabelPassword->setText( i18n( "Private key password:" ) ); + dlg.main->SavePasswordCheckBox->setText( i18n( "Save private key password" ) ); + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry ( "[openvpn] " + i18n( "Password for private key requested...\n" ), GlobalConfig->debug ); + if ( dlg.exec() ) + { + pass = dlg.main->PasswordEdit->text(); + + if ( !pass.isEmpty() ) + { + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "private key password got from user" ), GlobalConfig->debug ); + + if ( dlg.main->SavePasswordCheckBox->isChecked() ) + { + GlobalConfig->currentProfile->setSavePrivateKeyPassword( true ); + GlobalConfig->currentProfile->setPrivateKeyPass( QString( pass ) ); + } + + GlobalConfig->TmpPrivateKeyPass = QString( pass ); + + // if ( GlobalConfig->KvpncDebugLevel > 5 ) + // GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: private key password: " + GlobalConfig->TmpPrivateKeyPass, GlobalConfig->debug ); + + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "Send private key password..." ), GlobalConfig->info ); + + sendToServer( "password \"Private Key\" " + GlobalConfig->TmpPrivateKeyPass + "\n" ); + } + else + { + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: password empty, stop.", GlobalConfig->error ); + abort = true; + } + } + else + { + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: password dialog canceled and password empty, stop.", GlobalConfig->info ); + abort = true; + } + } + + else if ( line.find( "FATAL:script failed: shell command exited with error status", 0, FALSE ) > -1 ) + { + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: script exited with wrong status" , GlobalConfig->error ); + + abort = true; + } + + else if ( line.find( "PASSWORD:Verification Failed: 'Auth'", 0, FALSE ) > -1 ) + { + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: password verification failed!" , GlobalConfig->error ); + + GlobalConfig->appendLogEntry( i18n( "Authentication failed (%1)!" ).arg( i18n( "user password" ) ) , GlobalConfig->error ); + + abort = true; + } + + else if ( line.find( "FATAL:Cannot load CA certificate file", 0, FALSE ) > -1 ) + { + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( i18n("OpenvpnManagementHandler: CA certifcate file could not be loaded! Please check your CA certificate file.") , GlobalConfig->error ); + + GlobalConfig->appendLogEntry( i18n( "Certificate load failed (%1)!" ).arg( i18n( "CA certificate" ) ) , GlobalConfig->error ); + + abort = true; + } + + else if ( line.find( "FATAL:Message hash algorithm", 0, FALSE ) > -1 && line.find( "not found", 0, FALSE ) > -1 ) + { + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( i18n("OpenvpnManagementHandler: Hash algorithm %1 could not found! Please check your OpenVPN settings.").arg(line.section(' ',3,3).remove('\'')) , GlobalConfig->error ); + + GlobalConfig->appendLogEntry( i18n( "Hash algorithm not found (%1)!" ).arg(line.section(' ',3,3).remove('\'') ) , GlobalConfig->error ); + + abort = true; + } + + else if ( line.find( "PASSWORD:Need 'eToken token' password", 0, FALSE ) > -1) + { + GlobalConfig->TmpPassword = ""; + QCString password; + QString pass = ""; + + QTextStream os( socket ); + // os.setEncoding( QTextStream::UnicodeUTF8 ); + + GlobalConfig->TmpPrivateKeyPass = ""; + EnterXauthInteractivePasscodeDialog dlg( 0); + dlg.setCaption( i18n( "Enter token pin" ) ); + dlg.main->DescriptionLabel->setText( i18n( "Enter eToken pin for unlocking token \"%1\":" ).arg(GlobalConfig->currentProfile->getPkcs11Id()) ); + dlg.main->LabelPassword->setText( i18n( "eToken pin:" ) ); + dlg.main->SavePasswordCheckBox->hide(); + dlg.main->adjustSize(); + dlg.adjustSize(); + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( "[openvpn] " + i18n( "eToken pin for unlocking token requested...\n" ), GlobalConfig->debug ); + if ( dlg.exec() ) + { + + pass = dlg.main->PasswordEdit->text(); + if ( !pass.isEmpty() ) + { + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "token password got from user" ), GlobalConfig->debug ); + + + GlobalConfig->TmpPrivateKeyPass = QString( pass ); + + // if ( GlobalConfig->KvpncDebugLevel > 5 ) + // GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: token password: " + GlobalConfig->TmpPrivateKeyPass, GlobalConfig->debug ); + + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "Send token password..." ), GlobalConfig->debug ); + GlobalConfig->appendLogEntry( i18n( "Send token password..." ), GlobalConfig->info ); + sendToServer( "password \"eToken token\" " + GlobalConfig->TmpPrivateKeyPass + "\n" ); + } + else + { + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: token password empty, stop.", GlobalConfig->error ); + abort = true; + } + } + else + { + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: password dialog canceled and password empty, stop.", GlobalConfig->info ); + abort = true; + } + } + + else if ( line.find( "SUCCESS: 'eToken token' password entered, but not yet verified", 0, FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "got %1 message" ).arg("SUCCESS for 'eToken token' password"), GlobalConfig->debug ); + } + + else if ( line.find( ">PASSWORD:Need '", 0, FALSE) > -1 && line.find( "token' password", 0, FALSE ) > -1) + { + GlobalConfig->TmpPassword = ""; + QCString password; + QString pass = ""; + QString TokenName = line.section('\'',1,1); + if ( GlobalConfig->KvpncDebugLevel > 4 ) + { + GlobalConfig->appendLogEntry ( "[openvpn] " + i18n( "token name detected: %1\n" ).arg(TokenName), GlobalConfig->debug ); + } + + QTextStream os( socket ); + // os.setEncoding( QTextStream::UnicodeUTF8 ); + + GlobalConfig->TmpPrivateKeyPass = ""; + EnterXauthInteractivePasscodeDialog dlg( 0); + dlg.setCaption( i18n( "Enter token pin" ) ); + dlg.main->DescriptionLabel->setText( i18n( "Enter pin for unlocking token \"%1\":" ).arg(GlobalConfig->currentProfile->getPkcs11Id()) ); + dlg.main->LabelPassword->setText( i18n( "PIN:" ) ); + dlg.main->SavePasswordCheckBox->hide(); + dlg.main->adjustSize(); + dlg.adjustSize(); + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry ( "[openvpn] " + i18n( "PIN for unlocking token requested...\n" ), GlobalConfig->debug ); + if ( dlg.exec() ) + { + + pass = dlg.main->PasswordEdit->text(); + if ( !pass.isEmpty() ) + { + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "token password got from user" ), GlobalConfig->debug ); + + + GlobalConfig->TmpPrivateKeyPass = QString( pass ); + + // if ( GlobalConfig->KvpncDebugLevel > 5 ) + // GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: token password: " + GlobalConfig->TmpPrivateKeyPass, GlobalConfig->debug ); + + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "Send token password..." ), GlobalConfig->debug ); + GlobalConfig->appendLogEntry( i18n( "Send token password..." ), GlobalConfig->info ); + sendToServer( "password \""+TokenName+"\" " + GlobalConfig->TmpPrivateKeyPass + "\n" ); + } + else + { + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: token password empty, stop.", GlobalConfig->error ); + abort = true; + } + } + else + { + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: password dialog canceled and password empty, stop.", GlobalConfig->info ); + abort = true; + } + } + + else if ( line.find( "SUCCESS: '", 0, FALSE ) > -1 && line.find( "token' password entered, but not yet verified", 0, FALSE ) > -1 ) + { + QString TokenName = line.section('\'',1,1); + if ( GlobalConfig->KvpncDebugLevel > 4 ) + { + GlobalConfig->appendLogEntry ( "[openvpn] " + i18n( "token name detected: %1\n" ).arg(TokenName), GlobalConfig->debug ); + } + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "got %1 message" ).arg("SUCCESS for '%1' password").arg(TokenName), GlobalConfig->debug ); + } + + else if ( line.find( "SUCCESS: 'Auth' password entered, but not yet verified", 0, FALSE ) > -1 ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "got %1 message" ).arg("SUCCESS for user password"), GlobalConfig->debug ); + } + + else if ( line.find( "Need 'token-insertion-request'", 0, FALSE ) > -1 ) + { + // if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "got %1 message" ).arg("token-insertion-request"), GlobalConfig->debug ); + KMessageBox::error ( 0, i18n("Token \"%1\" is not inserted!").arg(GlobalConfig->currentProfile->getPkcs11Id()), i18n("Token missing") ); + abort = true; + } + + else if ( line.find( "SUCCESS: 'Private Key' password entered, but not yet verified", 0, FALSE ) > -1 ) + { + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "got %1 message" ).arg("SUCCESS for 'Private Key' password"), GlobalConfig->debug ); + } + else if ( line.find( "external program fork failed", 0, FALSE ) > -1 ) + { + + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "External program fork failed, need security parameter." ), GlobalConfig->debug ); + GlobalConfig->OpenvpnNeedSecurityParameter=true; + abort = true; + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "got other management message: %1" ).arg(line), GlobalConfig->debug ); + } + if (abort) + { + if (socket) + { + disconnect( socket, SIGNAL( connected() ), this, SLOT( socketConnected() ) ); + disconnect( socket, SIGNAL( connectionClosed() ), this, SLOT( socketConnectionClosed() ) ); + disconnect( socket, SIGNAL( readyRead() ), this, SLOT( socketReadyRead() ) ); + disconnect( socket, SIGNAL( error( int ) ), this, SLOT( socketError( int ) ) ); + disconnect( socket, SIGNAL( hostFound() ), this, SLOT( hostFound() ) ); + socket->close(); + if ( socket->state() == QSocket::Closing ) + { + // We have a delayed close. + connect( socket, SIGNAL(delayedCloseFinished()), this, SLOT(socketClosed()) ); + } + else + { + // The socket is closed. + socketClosed(); + emit terminate_openvpn(); + } + } + } + } + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 4 ) + { + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "Socket state is strange: %1" ).arg( QString().setNum( socket->state() ) ), GlobalConfig->debug ); + } + } + } +} + +bool OpenvpnManagementHandler::isConnectedToManagementPort() +{ + return connectedToManagementPort; +} + +bool OpenvpnManagementHandler::doConnect() +{ + + socket = 0L; + socket = new QSocket( this ); + if (socket) + { + connect( socket, SIGNAL( connected() ), this, SLOT( socketConnected() ) ); + connect( socket, SIGNAL( hostFound() ), this, SLOT( hostFound() ) ); + connect( socket, SIGNAL( error( int ) ), this, SLOT( socketError( int ) ) ); + + + if ( socket->state() == QSocket::Idle ) + { + if ( GlobalConfig->KvpncDebugLevel > 1 ) + { + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "Connecting to the OpenVPN manage port (%1)..." ).arg( QString().setNum( GlobalConfig->OpenvpnManagementPort ) ), GlobalConfig->debug ); + } + socket->connectToHost( "127.0.0.1", GlobalConfig->OpenvpnManagementPort ); + + connect ( &greetingtimer, SIGNAL ( timeout() ), this, SLOT ( greetingTimedOut() ) ); + greetingtimer.start ( 3 * 1000, TRUE ); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler " + i18n("Management greeting timer started."), GlobalConfig->debug ); + + return true; + } + else + { + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler " + i18n("connection already in progress, skipping connect"), GlobalConfig->debug ); + + return false; + } + } + else + { + return false; + } +} + +void OpenvpnManagementHandler::hostFound() +{ +// KMessageBox::error ( 0, QString("bar"), QString("foo") ); + if ( GlobalConfig->KvpncDebugLevel > 1 ) + { + GlobalConfig->appendLogEntry( "OpenvpnManagementHandler: " + i18n( "Connecting to the OpenVPN manage port (%1)... host found" ).arg( QString().setNum( GlobalConfig->OpenvpnManagementPort ) ), GlobalConfig->debug ); + } + +} diff --git a/src/openvpnmanagementhandler.h b/src/openvpnmanagementhandler.h new file mode 100644 index 0000000..7f553ec --- /dev/null +++ b/src/openvpnmanagementhandler.h @@ -0,0 +1,69 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef OPENVPNMANAGEMENTHANDLER_H +#define OPENVPNMANAGEMENTHANDLER_H + +#include +#include +#include +#include "kvpncconfig.h" + + +class QSocket; + +/** + @author Christoph Thielecke +*/ +class OpenvpnManagementHandler : public QObject { + Q_OBJECT + public: + OpenvpnManagementHandler(QObject *parent, KVpncConfig *GlobalConfig ); + ~OpenvpnManagementHandler(); + void closeConnection(); + bool isConnectedToManagementPort(); + bool doConnect(); + QTimer greetingtimer; + bool socketReallyClosed; + + protected slots: + void socketConnected(); + void socketConnectionClosed(); + void socketError( int ); + void socketReadyRead(); + void socketClosed(); + void hostFound(); + void greetingTimedOut(); + + public slots: + void sendToServer(QString cmd); + + private: + KVpncConfig *GlobalConfig; + bool fInHold; + bool gotGreeting; + bool connectedToManagementPort; + QSocket *socket; + QString errormsg; + signals: + void terminate_openvpn(); + +}; +#endif + diff --git a/src/ovpn.protocol b/src/ovpn.protocol new file mode 100644 index 0000000..f65a3fb --- /dev/null +++ b/src/ovpn.protocol @@ -0,0 +1,11 @@ +[Protocol] +exec=kdesu kvpnc --openvpnimport %u +protocol=pcf +input=none +output=none +helper=true +listing=false +reading=false +writing=false +makedir=false +deleting=false diff --git a/src/pcf.protocol b/src/pcf.protocol new file mode 100644 index 0000000..45ab48a --- /dev/null +++ b/src/pcf.protocol @@ -0,0 +1,11 @@ +[Protocol] +exec=kdesu kvpnc --ciscoimport %u +protocol=pcf +input=none +output=none +helper=true +listing=false +reading=false +writing=false +makedir=false +deleting=false diff --git a/src/ping_check.sh b/src/ping_check.sh new file mode 100755 index 0000000..77ee7d7 --- /dev/null +++ b/src/ping_check.sh @@ -0,0 +1,96 @@ +#!/bin/sh +############################################################## +# Copyright (C) 2004 by Christoph Thielecke +# crissi99@gmx.de +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA +# +# checks if the ping answer was sucessful within given times +# +# syntax: ping_check.sh +# example: ping_check.sh +# device can be also default then no device is supplied to ping +# +############################################################## + +if [ $# -ne 6 ]; then +echo "help:" +echo "-----" +echo "PING " +echo "DEVICE " +echo "PINGHOST " +echo "INTERVAL " +echo "TEST_PING_COUNT " +echo "QUIET [0|1]" +echo "" +echo "parameters count: $#" +exit 1 +fi + +PING=$1 +DEVICE=$2 +PINGHOST=$3 +INTERVAL=$4 +TEST_PING_COUNT=$5 +QUIET=$6 + +DEVICECMD="" + +if [ $DEVICE != "default" ]; then + DEVICECMD="-I $DEVICE" +fi + +if [ $QUIET -eq '1' ]; then +echo "Configuration:" +echo "Host: "$PINGHOST +echo "Device: "$DEVICE +echo "PING count: "$TEST_PING_COUNT +echo "Interval: "$INTERVAL +echo "- - - - -" +echo +fi + +while true; do +fails=0 +count=0 +while [ $count -lt $TEST_PING_COUNT ]; do + if [ $QUIET -eq '1' ]; then + echo -n "Ping sequence "$count": " + fi + if [ "x" = "x$(ping -c 1 -w 5 $DEVICECMD $PINGHOST 2>&1 | grep '1 received')" ]; then + fails=`expr $fails + 1` + if [ $QUIET -eq '1' ]; then + echo "failed!" + fi + else + if [ $QUIET -eq '1' ]; then + echo "ok." + fi + fi + count=`expr $count + 1` + sleep $INTERVAL + done + + if [ $QUIET -eq '1' ]; then + echo -n "PING failitures: "$fails" => " + fi + if [ $fails -gt $(expr $TEST_PING_COUNT - 1) ]; then + echo "PING failed!" + else + echo "PING ok." + fi +done + diff --git a/src/preferencesdialog.cpp b/src/preferencesdialog.cpp new file mode 100644 index 0000000..4c80e95 --- /dev/null +++ b/src/preferencesdialog.cpp @@ -0,0 +1,7147 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* Contains parts of code of the konversation project (konvisettingsdialog.cpp) +* http://konversation.kde.org/ * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +//BEGIN INCLUDES +#include "preferencesdialog.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "networkinterface.h" +#include "utils.h" +#include "importcertificatedialog.h" +#include "newprofiledialog.h" + +#include +//END INCLUDES + +PreferencesDialog::PreferencesDialog( QWidget *parent, QApplication *app, QTextEdit *LogOutput, KVpncConfig *GlobalConfig, bool showOnlyProfiles ) : KDialogBase ( KDialogBase::TreeList, i18n( "Preferences..." ), + KDialogBase::Ok | KDialogBase::Apply | KDialogBase::Cancel | KDialogBase::Help, KDialogBase::Ok, + parent, "configdialog" ) +{ + GlobalConfig->appPointer->setOverrideCursor( QCursor(Qt::WaitCursor) ); + GlobalConfig->prefDlgOpen = true; + //main = new PreferencesDialogBase(this); + + //setMainWidget(main); + //main->setMinimumSize(main->sizeHint()) + + this->AccountList = GlobalConfig->AccountList; + this->LogOutput = LogOutput; + this->currentProfile = GlobalConfig->currentProfile; + this->KvpncDebugLevel = GlobalConfig->KvpncDebugLevel; + this->app = app; + this->GlobalConfig = GlobalConfig; + + lastProfileName = ""; + profileHasChanged=false; + prev_page=0; + current_page=0; + + this->showOnlyProfiles = showOnlyProfiles; + if ( showOnlyProfiles ) + { + setCaption( i18n( "Manage Profiles" ) ); + } + setupGui(); + + // DaemonOptionsWidget->ProgramsInPathcheckBox->setChecked(GlobalConfig->programsInPath); + // programsInPathToggled(GlobalConfig->programsInPath); + // + + ok_icon = KGlobal::iconLoader() ->loadIcon( "button_ok", KIcon::NoGroup, 16 ); + wrong_icon = KGlobal::iconLoader() ->loadIcon( "button_cancel", KIcon::NoGroup, 16 ); + + unfoldTreeList (); + if ( !showOnlyProfiles ) + { + ConfigDaemonOptionsWidget->RacoonDebugLevelComboBox->clear(); + + /* these levels must be deactivated because we need informational output !!! */ + //ConfigDaemonOptionsWidget->RacoonDebugLevelComboBox->insertItem( "none" ); + //ConfigDaemonOptionsWidget->RacoonDebugLevelComboBox->insertItem( "warning" ); + //ConfigDaemonOptionsWidget->RacoonDebugLevelComboBox->insertItem( "notify" ); + + ConfigDaemonOptionsWidget->RacoonDebugLevelComboBox->insertItem( "info" ); + ConfigDaemonOptionsWidget->RacoonDebugLevelComboBox->insertItem( "debug" ); + ConfigDaemonOptionsWidget->RacoonDebugLevelComboBox->insertItem( "debug2" ); + + + if ( GlobalConfig->PptpLogLevel == 0 ) + ConfigDaemonOptionsWidget->PptpLogLevelComboBox->setCurrentText( i18n( "low" ) ); + else if ( GlobalConfig->PptpLogLevel == 1 ) + ConfigDaemonOptionsWidget->PptpLogLevelComboBox->setCurrentText( i18n( "default" ) ); + else if ( GlobalConfig->PptpLogLevel == 2 ) + ConfigDaemonOptionsWidget->PptpLogLevelComboBox->setCurrentText( i18n( "high" ) ); + + ConfigDaemonOptionsWidget->DoKillL2tpdIfStillRunningCheckBox->setChecked(GlobalConfig->doKillL2tpdIfStillRunning); + ConfigDaemonOptionsWidget->DoKillXl2tpdIfStillRunningCheckBox->setChecked(GlobalConfig->doKillXl2tpdIfStillRunning); + ConfigDaemonOptionsWidget->DoKillRacoonIfStillRunningCheckBox->setChecked(GlobalConfig->doKillRacoonIfStillRunning); + + slotStatusMsg ( i18n( "Collecting daemon tool data..."), ID_STATUS_MSG ); + + ToolInfo *VpncInfo = Utils( GlobalConfig ).getToolInfo ( "vpnc" ); + VpncInfo->collectToolInfo(); + ToolInfo *CiscoVpncInfo = Utils( GlobalConfig ).getToolInfo ( "vpnclient" ); + CiscoVpncInfo->collectToolInfo(); + ToolInfo *IpsecInfo = Utils( GlobalConfig ).getToolInfo ( "ipsec" ); + IpsecInfo->collectToolInfo(); + ToolInfo *RacoonInfo = Utils( GlobalConfig ).getToolInfo ( "racoon" ); + RacoonInfo->collectToolInfo(); + ToolInfo *PppdInfo = Utils( GlobalConfig ).getToolInfo ( "pppd" ); + PppdInfo->collectToolInfo(); + ToolInfo *PptpInfo = Utils( GlobalConfig ).getToolInfo ( "pptp" ); + PptpInfo->collectToolInfo(); + ToolInfo *L2tpdInfo = Utils( GlobalConfig ).getToolInfo ( "l2tpd" ); + L2tpdInfo->collectToolInfo(); + ToolInfo *Xl2tpdInfo = Utils( GlobalConfig ).getToolInfo ( "xl2tpd" ); + Xl2tpdInfo->collectToolInfo(); + ToolInfo *Openl2tpInfo = Utils( GlobalConfig ).getToolInfo ( "openl2tpd" ); + Openl2tpInfo->collectToolInfo(); + ToolInfo *OpenvpnInfo = Utils( GlobalConfig ).getToolInfo ( "openvpn" ); + OpenvpnInfo->collectToolInfo(); + ToolInfo *VtunInfo = Utils( GlobalConfig ).getToolInfo ( "vtund" ); + VtunInfo->collectToolInfo(); + ToolInfo *SshInfo = Utils( GlobalConfig ).getToolInfo ( "ssh" ); + SshInfo->collectToolInfo(); + + ConfigDaemonOptionsWidget->VpncVersionLineEdit->setText( VpncInfo->Version ); + ConfigDaemonOptionsWidget->CiscoVpncVersionLineEdit->setText( CiscoVpncInfo->Version ); + ConfigDaemonOptionsWidget->IpsecVersionLineEdit->setText( IpsecInfo->Version ); + ConfigDaemonOptionsWidget->RacoonVersionLineEdit->setText( RacoonInfo->Version ); + ConfigDaemonOptionsWidget->PppdVersionLineEdit->setText( PppdInfo->Version ); + ConfigDaemonOptionsWidget->PptpVersionLineEdit->setText( PptpInfo->Version ); + ConfigDaemonOptionsWidget->OpenvpnVersionLineEdit->setText( OpenvpnInfo->Version ); + ConfigDaemonOptionsWidget->L2tpdVersionLineEdit->setText( L2tpdInfo->Version ); + ConfigDaemonOptionsWidget->Xl2tpdVersionLineEdit->setText( Xl2tpdInfo->Version ); + ConfigDaemonOptionsWidget->Openl2tpVersionLineEdit->setText( Openl2tpInfo->Version ); + ConfigDaemonOptionsWidget->VtunVersionLineEdit->setText( VtunInfo->Version ); + ConfigDaemonOptionsWidget->SshVersionLineEdit->setText( SshInfo->Version ); + + if (GlobalConfig->pathToVpnc.isEmpty() && !VpncInfo->PathToExec.isEmpty()) + ConfigDaemonOptionsWidget->VpncPathInput->setURL( VpncInfo->PathToExec ); + else + ConfigDaemonOptionsWidget->VpncPathInput->setURL( GlobalConfig->pathToVpnc ); + + if (GlobalConfig->pathToVpnc.isEmpty() && !VpncInfo->PathToExec.isEmpty()) + ConfigDaemonOptionsWidget->CiscoVpncPathInput->setURL( CiscoVpncInfo->PathToExec ); + else + ConfigDaemonOptionsWidget->CiscoVpncPathInput->setURL( GlobalConfig->pathToCiscoVpnc ); + + if (GlobalConfig->pathToIpsec.isEmpty() && !IpsecInfo->PathToExec.isEmpty()) + ConfigDaemonOptionsWidget->FreeswanPathInput->setURL( IpsecInfo->PathToExec ); + else + ConfigDaemonOptionsWidget->FreeswanPathInput->setURL( GlobalConfig->pathToIpsec ); + + if (GlobalConfig->pathToRacoon.isEmpty() && !RacoonInfo->PathToExec.isEmpty()) + ConfigDaemonOptionsWidget->RacoonPathInput->setURL( RacoonInfo->PathToExec ); + else + ConfigDaemonOptionsWidget->RacoonPathInput->setURL( GlobalConfig->pathToRacoon ); + + if (GlobalConfig->pathToPppd.isEmpty() && !PppdInfo->PathToExec.isEmpty()) + ConfigDaemonOptionsWidget->PppdPathInput->setURL( PppdInfo->PathToExec ); + else + ConfigDaemonOptionsWidget->PppdPathInput->setURL( GlobalConfig->pathToPppd ); + + if (GlobalConfig->pathToPptp.isEmpty() && !PptpInfo->PathToExec.isEmpty()) + ConfigDaemonOptionsWidget->PptpPathInput->setURL( PptpInfo->PathToExec ); + else + ConfigDaemonOptionsWidget->PptpPathInput->setURL( GlobalConfig->pathToPptp ); + + if (GlobalConfig->pathToOpenvpn.isEmpty() && !OpenvpnInfo->PathToExec.isEmpty()) + ConfigDaemonOptionsWidget->OpenvpnPathInput->setURL( OpenvpnInfo->PathToExec ); + else + ConfigDaemonOptionsWidget->OpenvpnPathInput->setURL( GlobalConfig->pathToOpenvpn ); + + if (GlobalConfig->pathToL2tpd.isEmpty() && !L2tpdInfo->PathToExec.isEmpty()) + ConfigDaemonOptionsWidget->L2tpdPathInput->setURL( L2tpdInfo->PathToExec ); + else + ConfigDaemonOptionsWidget->L2tpdPathInput->setURL( GlobalConfig->pathToL2tpd ); + + if (GlobalConfig->pathToXl2tpd.isEmpty() && !Xl2tpdInfo->PathToExec.isEmpty()) + ConfigDaemonOptionsWidget->Xl2tpdPathInput->setURL( Xl2tpdInfo->PathToExec ); + else + ConfigDaemonOptionsWidget->Xl2tpdPathInput->setURL( GlobalConfig->pathToXl2tpd ); + + if (GlobalConfig->pathToOpenl2tp.isEmpty() && !Openl2tpInfo->PathToExec.isEmpty()) + ConfigDaemonOptionsWidget->Openl2tpPathInput->setURL( Openl2tpInfo->PathToExec ); + else + ConfigDaemonOptionsWidget->Openl2tpPathInput->setURL( GlobalConfig->pathToOpenl2tp ); + + if (GlobalConfig->pathToVtund.isEmpty() && !VtunInfo->PathToExec.isEmpty()) + ConfigDaemonOptionsWidget->VtundPathInput->setURL( VtunInfo->PathToExec ); + else + ConfigDaemonOptionsWidget->VtundPathInput->setURL( GlobalConfig->pathToVtund ); + + if (GlobalConfig->pathToSsh.isEmpty() && !SshInfo->PathToExec.isEmpty()) + ConfigDaemonOptionsWidget->SshPathInput->setURL( VtunInfo->PathToExec ); + else + ConfigDaemonOptionsWidget->SshPathInput->setURL( GlobalConfig->pathToSsh ); + + + if ( VpncInfo->found && QFileInfo( VpncInfo->PathToExec ).isFile() && VpncInfo->found ) + ConfigDaemonOptionsWidget->VpncStatePixmapLabel->setPixmap( ok_icon ); + else + ConfigDaemonOptionsWidget->CiscoVpncStatePixmapLabel->setPixmap( wrong_icon ); + if ( VpncInfo->found && QFileInfo( CiscoVpncInfo->PathToExec ).isFile() && CiscoVpncInfo->found ) + ConfigDaemonOptionsWidget->CiscoVpncStatePixmapLabel->setPixmap( ok_icon ); + else + ConfigDaemonOptionsWidget->CiscoVpncStatePixmapLabel->setPixmap( wrong_icon ); + + if ( VtunInfo->found && QFileInfo( VtunInfo->PathToExec ).isFile() && VtunInfo->found ) + ConfigDaemonOptionsWidget->VtundStatePixmapLabel->setPixmap( ok_icon ); + else + ConfigDaemonOptionsWidget->VtundStatePixmapLabel->setPixmap( wrong_icon ); + + if ( SshInfo->found && QFileInfo( SshInfo->PathToExec ).isFile() && SshInfo->found ) + ConfigDaemonOptionsWidget->SshStatePixmapLabel->setPixmap( ok_icon ); + else + ConfigDaemonOptionsWidget->SshStatePixmapLabel->setPixmap( wrong_icon ); + + if ( IpsecInfo->found ) + ConfigDaemonOptionsWidget->IpsecStatePixmapLabel->setPixmap( ok_icon ); + else + ConfigDaemonOptionsWidget->IpsecStatePixmapLabel->setPixmap( wrong_icon ); + if ( RacoonInfo->found ) + ConfigDaemonOptionsWidget->RacoonStatePixmapLabel->setPixmap( ok_icon ); + else + ConfigDaemonOptionsWidget->RacoonStatePixmapLabel->setPixmap( wrong_icon ); + if ( PppdInfo->found ) + ConfigDaemonOptionsWidget->PppdStatePixmapLabel->setPixmap( ok_icon ); + else + ConfigDaemonOptionsWidget->PppdStatePixmapLabel->setPixmap( wrong_icon ); + if ( PptpInfo->found ) + ConfigDaemonOptionsWidget->PptpStatePixmapLabel->setPixmap( ok_icon ); + else + ConfigDaemonOptionsWidget->PptpStatePixmapLabel->setPixmap( wrong_icon ); + if ( OpenvpnInfo->found ) + ConfigDaemonOptionsWidget->OpenvpnStatePixmapLabel->setPixmap( ok_icon ); + else + ConfigDaemonOptionsWidget->OpenvpnStatePixmapLabel->setPixmap( wrong_icon ); + if ( L2tpdInfo->found ) + ConfigDaemonOptionsWidget->L2tpdStatePixmapLabel->setPixmap( ok_icon ); + else + ConfigDaemonOptionsWidget->L2tpdStatePixmapLabel->setPixmap( wrong_icon ); + if ( Xl2tpdInfo->found ) + ConfigDaemonOptionsWidget->Xl2tpdStatePixmapLabel->setPixmap( ok_icon ); + else + ConfigDaemonOptionsWidget->Xl2tpdStatePixmapLabel->setPixmap( wrong_icon ); + if ( Openl2tpInfo->found ) + ConfigDaemonOptionsWidget->Openl2tpStatePixmapLabel->setPixmap( ok_icon ); + else + ConfigDaemonOptionsWidget->Openl2tpStatePixmapLabel->setPixmap( wrong_icon ); + + + HelperProgramOptionsWidget->IptablesPathInput->setURL( GlobalConfig->pathToIptables ); + HelperProgramOptionsWidget->OpenSSLPathInput->setURL( GlobalConfig->pathToOpenssl ); + HelperProgramOptionsWidget->KillPathInput->setURL( GlobalConfig->pathToKill ); + HelperProgramOptionsWidget->KillallPathInput->setURL( GlobalConfig->pathToKillall ); + HelperProgramOptionsWidget->PingPathInput->setURL( GlobalConfig->pathToPing ); + HelperProgramOptionsWidget->IpPathInput->setURL( GlobalConfig->pathToIp ); + HelperProgramOptionsWidget->IfconfigPathInput->setURL( GlobalConfig->pathToIfconfig ); + HelperProgramOptionsWidget->RoutePathInput->setURL( GlobalConfig->pathToRoute ); + HelperProgramOptionsWidget->Pkcs11ToolPathInput->setURL( GlobalConfig->pathToPkcs11Tool ); + HelperProgramOptionsWidget->CiscoCertMgrPathInput->setURL( GlobalConfig->pathToCiscoCertMgr ); + HelperProgramOptionsWidget->TailPathInput->setURL( GlobalConfig->pathToTail ); + HelperProgramOptionsWidget->KsshaskpassPathInput->setURL( GlobalConfig->pathToKsshAskpass ); + HelperProgramOptionsWidget->GnomeaskpassPathInput->setURL( GlobalConfig->pathToGnomeSshAskpass ); + + slotStatusMsg ( i18n( "Collecting helper tool data..."), ID_STATUS_MSG ); + + ToolInfo *OpensslInfo = Utils( GlobalConfig ).getToolInfo ( "openssl" ); + OpensslInfo->collectToolInfo(); + ToolInfo *IptablesInfo = Utils( GlobalConfig ).getToolInfo ( "iptables" ); + IptablesInfo->collectToolInfo(); + ToolInfo *KillInfo = Utils( GlobalConfig ).getToolInfo ( "kill" ); + KillInfo->collectToolInfo(); + ToolInfo *KillallInfo = Utils( GlobalConfig ).getToolInfo ( "killall" ); + KillallInfo->collectToolInfo(); + ToolInfo *PingInfo = Utils( GlobalConfig ).getToolInfo ( "ping" ); + PingInfo->collectToolInfo(); + ToolInfo *IpInfo = Utils( GlobalConfig ).getToolInfo ( "ip" ); + IpInfo->collectToolInfo(); + ToolInfo *IfconfigInfo = Utils( GlobalConfig ).getToolInfo ( "ifconfig" ); + IfconfigInfo->collectToolInfo(); + ToolInfo *RouteInfo = Utils( GlobalConfig ).getToolInfo ( "route" ); + RouteInfo->collectToolInfo(); + ToolInfo *Pkcs11ToolInfo = Utils( GlobalConfig ).getToolInfo ( "pkcs11-tool" ); + Pkcs11ToolInfo->collectToolInfo(); + ToolInfo *CiscoCertMgrInfo = Utils( GlobalConfig ).getToolInfo ( "cisco_cert_mgr" ); + CiscoCertMgrInfo->collectToolInfo(); + ToolInfo *TailInfo = Utils( GlobalConfig ).getToolInfo ( "tail" ); + TailInfo->collectToolInfo(); + ToolInfo *KsshaskpassInfo = Utils( GlobalConfig ).getToolInfo ( "ksshaskpass" ); + KsshaskpassInfo->collectToolInfo(); + ToolInfo *GnomeaskpassInfo = Utils( GlobalConfig ).getToolInfo ( "gnome-ssh-askpass" ); + GnomeaskpassInfo->collectToolInfo(); + + + HelperProgramOptionsWidget->OpensslVersionLineEdit->setText( OpensslInfo->Version ); + HelperProgramOptionsWidget->IptablesVersionLineEdit->setText( IptablesInfo->Version ); + HelperProgramOptionsWidget->KillVersionLineEdit->setText( KillInfo->Version ); + HelperProgramOptionsWidget->KillallVersionLineEdit->setText( KillallInfo->Version ); + HelperProgramOptionsWidget->PingVersionLineEdit->setText( PingInfo->Version ); + HelperProgramOptionsWidget->IpVersionLineEdit->setText( IpInfo->Version ); + HelperProgramOptionsWidget->IfconfigVersionLineEdit->setText( IfconfigInfo->Version ); + HelperProgramOptionsWidget->RouteVersionLineEdit->setText( RouteInfo->Version ); + HelperProgramOptionsWidget->Pkcs11ToolVersionLineEdit->setText( Pkcs11ToolInfo->Version ); + HelperProgramOptionsWidget->CiscoCertMgrVersionLineEdit->setText( CiscoCertMgrInfo->Version ); + HelperProgramOptionsWidget->TailVersionLineEdit->setText( TailInfo->Version ); + HelperProgramOptionsWidget->KsshaskpassVersionLineEdit->setText( KsshaskpassInfo->Version ); + HelperProgramOptionsWidget->GnomeaskpassVersionLineEdit->setText( GnomeaskpassInfo->Version ); + + if ( OpensslInfo->found ) + HelperProgramOptionsWidget->OpensslStatePixmapLabel->setPixmap( ok_icon ); + else + HelperProgramOptionsWidget->OpensslStatePixmapLabel->setPixmap( wrong_icon ); + if ( IptablesInfo->found ) + HelperProgramOptionsWidget->IptablesStatePixmapLabel->setPixmap( ok_icon ); + else + HelperProgramOptionsWidget->IptablesStatePixmapLabel->setPixmap( wrong_icon ); + if ( KillInfo->found ) + HelperProgramOptionsWidget->KillStatePixmapLabel->setPixmap( ok_icon ); + else + HelperProgramOptionsWidget->KillStatePixmapLabel->setPixmap( wrong_icon ); + if ( KillallInfo->found ) + HelperProgramOptionsWidget->KillallStatePixmapLabel->setPixmap( ok_icon ); + else + HelperProgramOptionsWidget->KillallStatePixmapLabel->setPixmap( wrong_icon ); + if ( PingInfo->found ) + HelperProgramOptionsWidget->PingStatePixmapLabel->setPixmap( ok_icon ); + else + HelperProgramOptionsWidget->PingStatePixmapLabel->setPixmap( wrong_icon ); + if ( IpInfo->found ) + HelperProgramOptionsWidget->IpStatePixmapLabel->setPixmap( ok_icon ); + else + HelperProgramOptionsWidget->IpStatePixmapLabel->setPixmap( wrong_icon ); + if ( IfconfigInfo->found ) + HelperProgramOptionsWidget->IfconfigStatePixmapLabel->setPixmap( ok_icon ); + else + HelperProgramOptionsWidget->IfconfigStatePixmapLabel->setPixmap( wrong_icon ); + if ( RouteInfo->found ) + HelperProgramOptionsWidget->RouteStatePixmapLabel->setPixmap( ok_icon ); + else + HelperProgramOptionsWidget->RouteStatePixmapLabel->setPixmap( wrong_icon ); + if ( Pkcs11ToolInfo->found ) + HelperProgramOptionsWidget->Pkcs11ToolStatePixmapLabel->setPixmap( ok_icon ); + else + HelperProgramOptionsWidget->Pkcs11ToolStatePixmapLabel->setPixmap( wrong_icon ); + if ( CiscoCertMgrInfo->found ) + HelperProgramOptionsWidget->CiscoCertMgrStatePixmapLabel->setPixmap( ok_icon ); + else + HelperProgramOptionsWidget->CiscoCertMgrStatePixmapLabel->setPixmap( wrong_icon ); + if ( TailInfo->found ) + HelperProgramOptionsWidget->TailStatePixmapLabel->setPixmap( ok_icon ); + else + HelperProgramOptionsWidget->TailStatePixmapLabel->setPixmap( wrong_icon ); + if ( KsshaskpassInfo->found ) + HelperProgramOptionsWidget->KsshaskpassStatePixmapLabel->setPixmap( ok_icon ); + else + HelperProgramOptionsWidget->KsshaskpassStatePixmapLabel->setPixmap( wrong_icon ); + if ( GnomeaskpassInfo->found ) + HelperProgramOptionsWidget->GnomeaskpassStatePixmapLabel->setPixmap( ok_icon ); + else + HelperProgramOptionsWidget->GnomeaskpassStatePixmapLabel->setPixmap( wrong_icon ); + + slotStatusMsg ( i18n("Ready."), ID_STATUS_MSG ); + + ConnectOptionsWidget->checkMinimizeAfterConnectCheck->setChecked( GlobalConfig->minimizeAfterConnect ); + DebugOptionsWidget->showDebugCheck->setChecked( GlobalConfig->showDebugConsole ); + DebugOptionsWidget->WriteLogCheck->setChecked( GlobalConfig->writeLogFile ); + DebugOptionsWidget->spinKvpncDebugLevel->setValue ( GlobalConfig->KvpncDebugLevel ); + + if (GlobalConfig->RacoonDebugLevel != "info" && GlobalConfig->RacoonDebugLevel != "debug" && GlobalConfig->RacoonDebugLevel != "debug2" ) + GlobalConfig->RacoonDebugLevel = "info"; + ConfigDaemonOptionsWidget->RacoonDebugLevelComboBox->setCurrentText ( GlobalConfig->RacoonDebugLevel ); + ConfigDaemonOptionsWidget->spinVpncDebugLevel->setValue ( GlobalConfig->VpncDebugLevel ); + ConfigDaemonOptionsWidget->spinOpenvpnDebugLevel->setValue ( GlobalConfig->OpenvpnDebugLevel - 1 ); + ConfigDaemonOptionsWidget->DebugPppdcheckBox->setChecked( GlobalConfig->enableDebugPppd ); + ConfigDaemonOptionsWidget->DebugPptpdcheckBox->setChecked( GlobalConfig->enableDebugPptpd ); + ConfigDaemonOptionsWidget->spinSshDebugLevel->setValue ( GlobalConfig->SshDebugLevel ); + + + ConfigDaemonOptionsWidget->EnableDebugXl2tpdtunnelCheckBox->setChecked( GlobalConfig->enableDebugXl2tpdtunnel ); + ConfigDaemonOptionsWidget->EnableDebugXl2tpdstateCheckBox ->setChecked( GlobalConfig->enableDebugXl2tpdstate ); + ConfigDaemonOptionsWidget->EnableDebugXl2tpdpacketCheckBox->setChecked( GlobalConfig->enableDebugXl2tpdpacket ); + ConfigDaemonOptionsWidget->EnableDebugXl2tpdNetworkCheckBox->setChecked( GlobalConfig->enableDebugXl2tpdNetwork ); + + ConfigDaemonOptionsWidget->DebugOpenl2tpCheckBox->setChecked( GlobalConfig->enableDebugOpenl2tp ); + + + ConfigDaemonOptionsWidget->PppdKernelLogLevelComboBox->setCurrentText(i18n("none")); + if (GlobalConfig->PppdKernelLogLevel ==0) + ConfigDaemonOptionsWidget->PppdKernelLogLevelComboBox->setCurrentText(i18n("none")); + if (GlobalConfig->PppdKernelLogLevel ==1) + ConfigDaemonOptionsWidget->PppdKernelLogLevelComboBox->setCurrentText(i18n("general")); + if (GlobalConfig->PppdKernelLogLevel ==4) + ConfigDaemonOptionsWidget->PppdKernelLogLevelComboBox->setCurrentText(i18n("general + packets")); + + ConfigDaemonOptionsWidget->DebugL2tpdCheckBox->setChecked( GlobalConfig->enableDebugL2tpd ); + for ( QStringList::Iterator it = GlobalConfig->PlutoDebug.begin(); it != GlobalConfig->PlutoDebug.end(); ++it ) + { + if (*it == "raw") + ConfigDaemonOptionsWidget->IpsecRawDebugCheckBox->setChecked(true); + if (*it == "crypt") + ConfigDaemonOptionsWidget->IpsecCryptDebugCheckBox->setChecked(true); + if (*it == "parsing") + ConfigDaemonOptionsWidget->IpsecParsingDebugCheckBox->setChecked(true); + if (*it == "emitting") + ConfigDaemonOptionsWidget->IpsecEmittingDebugCheckBox->setChecked(true); + if (*it == "control") + ConfigDaemonOptionsWidget->IpsecControlDebugCheckBox->setChecked(true); + if (*it == "klips") + ConfigDaemonOptionsWidget->IpsecKlipsDebugCheckBox->setChecked(true); + if (*it == "private") + ConfigDaemonOptionsWidget->IpsecPrivateDebugCheckBox->setChecked(true); + + } + + for ( QStringList::Iterator it = GlobalConfig->KlipsDebug.begin(); it != GlobalConfig->KlipsDebug.end(); ++it ) + { + if (*it == "tunnel-xmit") + ConfigDaemonOptionsWidget->KlipsDebugTunnel_xmitCheckBox->setChecked(true); + if (*it == "pfkey") + ConfigDaemonOptionsWidget->KlipsDebugPfkeyCheckBox->setChecked(true); + if (*it == "xform") + ConfigDaemonOptionsWidget->KlipsDebugXformCheckBox->setChecked(true); + if (*it == "eroute") + ConfigDaemonOptionsWidget->KlipsDebugErouteCheckBox->setChecked(true); + if (*it == "spi") + ConfigDaemonOptionsWidget->KlipsDebugSpiCheckBox->setChecked(true); + if (*it == "radij") + ConfigDaemonOptionsWidget->KlipsDebugRadijCheckBox->setChecked(true); + if (*it == "esp") + ConfigDaemonOptionsWidget->KlipsDebugEspCheckBox->setChecked(true); + if (*it == "ah") + ConfigDaemonOptionsWidget->KlipsDebugAhCheckBox->setChecked(true); + if (*it == "ipcomp") + ConfigDaemonOptionsWidget->KlipsDebugIpcompCheckBox->setChecked(true); + if (*it == "verbose") + ConfigDaemonOptionsWidget->KlipsDebugVerboseCheckBox->setChecked(true); + } + + ProfileCiscoOptionsWidget->PeerTimeoutIntNumInput->setValue( GlobalConfig->tryConnectTimeout ); + ConnectOptionsWidget->SilentQuitcheckBox->setChecked( GlobalConfig->useSilentQuit ); + GeneralOptionsWidget->DontQuitOnCloseEventCheckBox->setChecked( GlobalConfig->dontQuitOnCloseEvent ); + GeneralOptionsWidget->HideOnStartupCheckBox->setChecked (GlobalConfig->hideMainWindow); + GeneralOptionsWidget->useKwalletCheckBox->setChecked( GlobalConfig->useKwallet ); + ConfigDaemonOptionsWidget->ProgramsInPathcheckBox->setChecked( GlobalConfig->programsInPath ); + DebugOptionsWidget->KeepConnectionFilesCheckBox->setChecked( GlobalConfig->holdGeneratedScripts ); + LogOptionsWidget->InfoLogLabel->setPaletteBackgroundColor ( GlobalConfig->InfoLogColor ); + LogOptionsWidget->RemoteLogLabel->setPaletteBackgroundColor ( GlobalConfig->RemoteLogColor ); + LogOptionsWidget->ErrorLogLabel->setPaletteBackgroundColor ( GlobalConfig->ErrorLogColor ); + LogOptionsWidget->SuccessLogLabel->setPaletteBackgroundColor ( GlobalConfig->SuccessLogColor ); + LogOptionsWidget->DebugLogLabel->setPaletteBackgroundColor ( GlobalConfig->DebugLogColor ); + LogOptionsWidget->BackgroundLogLabel->setPaletteBackgroundColor ( GlobalConfig->DebugBackgroundcolor ); + LogOptionsWidget->UseColorizedLogOutputcheckBox->setChecked( GlobalConfig->useColorizedLogOutput ); + ConfigDaemonOptionsWidget->ShowInterfaceIPinTooltipCheckBox->setChecked( GlobalConfig->showInterfaceIPinTooltip ); + ConnectOptionsWidget->DoAutoConnectCheckBox->setChecked( GlobalConfig->doAutoConnectAtStartup ); + LogOptionsWidget->LogFontSizeSpinBox->setValue( GlobalConfig->LogViewerFontSize ); + + /* keep english names! */ + ConfigDaemonOptionsWidget->KlipsDebugTunnel_xmitCheckBox->setText( QString( "&tunnel-xmit" ) ); + ConfigDaemonOptionsWidget->KlipsDebugPfkeyCheckBox->setText( QString( "pfkey" ) ); + ConfigDaemonOptionsWidget->KlipsDebugXformCheckBox->setText( QString( "xform" ) ); + ConfigDaemonOptionsWidget->KlipsDebugErouteCheckBox->setText( QString( "eroute" ) ); + ConfigDaemonOptionsWidget->KlipsDebugSpiCheckBox->setText( QString( "spi" ) ); + ConfigDaemonOptionsWidget->KlipsDebugRadijCheckBox->setText( QString( "radij" ) ); + ConfigDaemonOptionsWidget->KlipsDebugEspCheckBox->setText( QString( "esp" ) ); + ConfigDaemonOptionsWidget->KlipsDebugAhCheckBox->setText( QString( "ah" ) ); + ConfigDaemonOptionsWidget->KlipsDebugIpcompCheckBox->setText( QString( "ipcomp" ) ); + ConfigDaemonOptionsWidget->KlipsDebugVerboseCheckBox->setText( QString( "verbose" ) ); + + ConfigDaemonOptionsWidget->IpsecEmittingDebugCheckBox->setText( QString( "emitting" ) ); + ConfigDaemonOptionsWidget->IpsecCryptDebugCheckBox->setText( QString( "cr&ypt" ) ); + ConfigDaemonOptionsWidget->IpsecRawDebugCheckBox->setText( QString( "&raw" ) ); + ConfigDaemonOptionsWidget->IpsecKlipsDebugCheckBox->setText( QString( "&klips" ) ); + ConfigDaemonOptionsWidget->IpsecParsingDebugCheckBox->setText( QString( "&parsing" ) ); + ConfigDaemonOptionsWidget->IpsecPrivateDebugCheckBox->setText( QString( "&private" ) ); + ConfigDaemonOptionsWidget->IpsecControlDebugCheckBox->setText( QString( "&control" ) ); + + bool profileInList = false; + for ( uint i = 0; i < GlobalConfig->AccountList->count();i++ ) + { + ConnectOptionsWidget->AutoConnectProfileComboBox->insertItem( GlobalConfig->AccountList->at( i ) ->getName() ); + if ( GlobalConfig->AccountList->at( i ) ->getName() == GlobalConfig->AutoConnectProfile ) + { + profileInList = true; + } + } + + ProfileCertOptionsWidget->x509certComboBox->clear(); + + if ( profileInList ) + { + ConnectOptionsWidget->AutoConnectProfileComboBox->setCurrentText( GlobalConfig->AutoConnectProfile ); + } + else + { + GlobalConfig->doAutoConnectAtStartup = false; + ConnectOptionsWidget->DoAutoConnectCheckBox->setChecked( GlobalConfig->doAutoConnectAtStartup ); + } + } + KDialogBase::adjustSize(); + + // TODO read types from list + ProfileGeneralOptionsWidget->ConnectionTypeComboBox->insertItem( i18n( "Cisco (vpnc)" ), VpnAccountData::cisco ); + + ProfileGeneralOptionsWidget->ConnectionTypeComboBox->insertItem( i18n( "IPSec (%1)" ).arg("racoon"), VpnAccountData::racoon ); + ProfileGeneralOptionsWidget->ConnectionTypeComboBox->insertItem( i18n( "IPSec (%1)" ).arg("Openswan/strongSwan"), VpnAccountData::freeswan ); + ProfileGeneralOptionsWidget->ConnectionTypeComboBox->insertItem( i18n( "PPTP" ), VpnAccountData::pptp ); + ProfileGeneralOptionsWidget->ConnectionTypeComboBox->insertItem( i18n( "OpenVPN" ), VpnAccountData::openvpn ); + ProfileGeneralOptionsWidget->ConnectionTypeComboBox->insertItem( i18n( "L2TP (%1)" ).arg("racoon"), VpnAccountData::l2tpd_racoon ); + ProfileGeneralOptionsWidget->ConnectionTypeComboBox->insertItem( i18n( "L2TP (%1)" ).arg("Openswan/strongSwan"), VpnAccountData::l2tpd_freeswan ); + ProfileGeneralOptionsWidget->ConnectionTypeComboBox->insertItem( i18n( "Cisco (proprietary)" ), VpnAccountData::ciscoorig ); + ProfileGeneralOptionsWidget->ConnectionTypeComboBox->insertItem( i18n( "Vtun" ), VpnAccountData::vtun ); + ProfileGeneralOptionsWidget->ConnectionTypeComboBox->insertItem( i18n( "SSH" ), VpnAccountData::ssh ); + //ConnectionTypeComboBox->insertItem( "-", 5 ); + + +// modp768 1 +// modp1024 2 +// modp1536 5 +// modp2048 14 +// modp3072 15 +// modp4096 16 +// modp6144 17 +// modp8192 18 + + ProfileRacoonOptionsWidget->DHGroupComboBox->insertItem( "modp768" ); + ProfileRacoonOptionsWidget->DHGroupComboBox->insertItem( "modp1024" ); + ProfileRacoonOptionsWidget->DHGroupComboBox->insertItem( "ec2n155" ); + ProfileRacoonOptionsWidget->DHGroupComboBox->insertItem( "ec2n185" ); + ProfileRacoonOptionsWidget->DHGroupComboBox->insertItem( "modp1536" ); + ProfileRacoonOptionsWidget->DHGroupComboBox->insertItem( "modp2048" ); + ProfileRacoonOptionsWidget->DHGroupComboBox->insertItem( "modp3072" ); + ProfileRacoonOptionsWidget->DHGroupComboBox->insertItem( "modp4096" ); + ProfileRacoonOptionsWidget->DHGroupComboBox->insertItem( "modp6144" ); + ProfileRacoonOptionsWidget->DHGroupComboBox->insertItem( "modp8192" ); + +// ProfileRacoonOptionsWidget->HashAlgoComboBox->insertItem("SHA1"); +// ProfileRacoonOptionsWidget->HashAlgoComboBox->insertItem("MD5"); + + /* + none: No ID + address: The type is the IP address. This is the default type if you do not specify an identifier to use + user_fqdn: The type is a USER_FQDN (user fully-qualified domain name) + fqdn: The type is a FQDN (fully-qualified domain name) + keyid: The type is a KEY_ID, read from the file + keyid: The type is a KEY_ID, specified in the quoted string + asn1dn: The type is an ASN.1 distinguished name. If empty, DN from the Subject field in the certificate will be used + */ + + ProfileRacoonOptionsWidget->LocalIdTypeCombobox->insertItem("none"); + ProfileRacoonOptionsWidget->LocalIdTypeCombobox->insertItem("address"); + ProfileRacoonOptionsWidget->LocalIdTypeCombobox->insertItem("user_fqdn"); + ProfileRacoonOptionsWidget->LocalIdTypeCombobox->insertItem("fqdn"); + ProfileRacoonOptionsWidget->LocalIdTypeCombobox->insertItem("keyid (file)"); + ProfileRacoonOptionsWidget->LocalIdTypeCombobox->insertItem("keyid"); + ProfileRacoonOptionsWidget->LocalIdTypeCombobox->insertItem("asn1dn"); + + ProfileRacoonOptionsWidget->RemoteIdTypeCombobox->insertItem("none"); + ProfileRacoonOptionsWidget->RemoteIdTypeCombobox->insertItem("address"); + ProfileRacoonOptionsWidget->RemoteIdTypeCombobox->insertItem("user_fqdn"); + ProfileRacoonOptionsWidget->RemoteIdTypeCombobox->insertItem("fqdn"); + ProfileRacoonOptionsWidget->RemoteIdTypeCombobox->insertItem("keyid (file)"); + ProfileRacoonOptionsWidget->RemoteIdTypeCombobox->insertItem("keyid"); + ProfileRacoonOptionsWidget->RemoteIdTypeCombobox->insertItem("asn1dn"); + + + ProfileIpsecOptionsWidget->LocalIdTypeCombobox->insertItem(i18n("Certificate ID")); + ProfileIpsecOptionsWidget->LocalIdTypeCombobox->insertItem("asn1dn"); + ProfileIpsecOptionsWidget->LocalIdTypeCombobox->insertItem("address"); + ProfileIpsecOptionsWidget->LocalIdTypeCombobox->insertItem("fqdn"); + ProfileIpsecOptionsWidget->LocalIdTypeCombobox->insertItem("keyid"); + ProfileIpsecOptionsWidget->LocalIdTypeCombobox->insertItem("user_fqdn"); + + ProfileIpsecOptionsWidget->RemoteIdTypeCombobox->insertItem("asn1dn"); + ProfileIpsecOptionsWidget->RemoteIdTypeCombobox->insertItem("address"); + ProfileIpsecOptionsWidget->RemoteIdTypeCombobox->insertItem("fqdn"); + ProfileIpsecOptionsWidget->RemoteIdTypeCombobox->insertItem("keyid"); + ProfileIpsecOptionsWidget->RemoteIdTypeCombobox->insertItem("user_fqdn"); + ProfileIpsecOptionsWidget->RemoteIdTypeCombobox->insertItem("none"); + + + + slotStatusMsg ( i18n( "Collecting kernel crypto..."), ID_FLASH_MSG ); + Utils::IpsecAlgos KernelCrypto = Utils ( GlobalConfig ).getKernelCrypto(); + + // man racoon.conf + ProfileRacoonOptionsWidget->EncryptionAlgorithmComboBox->insertItem("des" ); + ProfileRacoonOptionsWidget->EncryptionAlgorithmComboBox->insertItem("3des" ); + ProfileRacoonOptionsWidget->EncryptionAlgorithmComboBox->insertItem("blowfish" ); + ProfileRacoonOptionsWidget->EncryptionAlgorithmComboBox->insertItem("cast128" ); + ProfileRacoonOptionsWidget->EncryptionAlgorithmComboBox->insertItem("aes" ); + ProfileRacoonOptionsWidget->EncryptionAlgorithmComboBox->insertItem("camellia" ); + + // man racoon.conf + ProfileRacoonOptionsWidget->HashAlgoComboBox->insertItem( "md5" ); + ProfileRacoonOptionsWidget->HashAlgoComboBox->insertItem( "sha1" ); + ProfileRacoonOptionsWidget->HashAlgoComboBox->insertItem( "sha256" ); + ProfileRacoonOptionsWidget->HashAlgoComboBox->insertItem( "sha384" ); + ProfileRacoonOptionsWidget->HashAlgoComboBox->insertItem( "sha512" ); + + + + +// // phase 2 encr algos from kernel +// for ( QStringList::Iterator it = KernelCrypto.IpsecEspEncryptionAlgorithms.begin(); it != KernelCrypto.IpsecEspEncryptionAlgorithms.end(); ++it ) +// { +// ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->insertItem ( *it ); +// } +// +// // phase 2 auth algos from kernel +// for ( QStringList::Iterator it = KernelCrypto.IpsecEspAuthenticationAlgorithms.begin(); it != KernelCrypto.IpsecEspAuthenticationAlgorithms.end(); ++it ) +// { +// ProfileRacoonOptionsWidget->AuthenticationAlgorithm2ComboBox->insertItem ( *it ); +// } + + // vpn mit linux book + ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->insertItem("des" ); + ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->insertItem("3des" ); + ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->insertItem("des_iv64" ); + ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->insertItem("des_iv32" ); + ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->insertItem("rc5" ); + ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->insertItem("rc4" ); + ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->insertItem("idea" ); + ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->insertItem("3idea" ); + ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->insertItem("cast128" ); + ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->insertItem("blowfish" ); + ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->insertItem("null_enc" ); + ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->insertItem("twofish" ); + ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->insertItem("rijndael" ); + ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->insertItem("aes" ); + + ProfileRacoonOptionsWidget->AuthenticationAlgorithm2ComboBox->insertItem( "des" ); + ProfileRacoonOptionsWidget->AuthenticationAlgorithm2ComboBox->insertItem( "3des" ); + ProfileRacoonOptionsWidget->AuthenticationAlgorithm2ComboBox->insertItem( "des_iv64" ); + ProfileRacoonOptionsWidget->AuthenticationAlgorithm2ComboBox->insertItem( "des_iv32" ); + ProfileRacoonOptionsWidget->AuthenticationAlgorithm2ComboBox->insertItem( "hmac_md5" ); + ProfileRacoonOptionsWidget->AuthenticationAlgorithm2ComboBox->insertItem( "hmac_sha1" ); + ProfileRacoonOptionsWidget->AuthenticationAlgorithm2ComboBox->insertItem( "hmac_sha256" ); + ProfileRacoonOptionsWidget->AuthenticationAlgorithm2ComboBox->insertItem( "hmac_sha384" ); + ProfileRacoonOptionsWidget->AuthenticationAlgorithm2ComboBox->insertItem( "hmac_sha512" ); + ProfileRacoonOptionsWidget->AuthenticationAlgorithm2ComboBox->insertItem( "non_auth" ); + + ProfileNetworkHttpProxyOptionsWidget->HttpProxyAuthTypeComboBox->insertItem( "Basic" ); + ProfileNetworkHttpProxyOptionsWidget->HttpProxyAuthTypeComboBox->insertItem( "NTLM" ); + + + slotStatusMsg ( i18n( "Collecting OpenVPN capabilities..."), ID_FLASH_MSG ); + QStringList ciphers = Utils( GlobalConfig ).getOpenvpnCiphers(); + QStringList digests = Utils( GlobalConfig ).getOpenvpnDigests(); + + for ( QStringList::Iterator it = ciphers.begin(); it != ciphers.end(); ++it ) + { + ProfileOpenvpnOptionsWidget->UserdefiniedCipherComboBox->insertItem( *it ); + } + + for ( QStringList::Iterator it = digests.begin(); it != digests.end(); ++it ) + { + ProfileOpenvpnOptionsWidget->UserdefiniedDigestComboBox->insertItem( *it ); + } + slotStatusMsg ( i18n("Ready."), ID_STATUS_MSG ); + + ProfilePptpOptionsWidget->AuthMethodComboBox->insertItem("chap"); + ProfilePptpOptionsWidget->AuthMethodComboBox->insertItem("pap"); + ProfilePptpOptionsWidget->AuthMethodComboBox->insertItem("mschap"); + ProfilePptpOptionsWidget->AuthMethodComboBox->insertItem("mschap-v2"); + + ProfileNetworkGeneralOptionsWidget->TunnelDeviceTypeComboBox->insertItem("TUN"); + ProfileNetworkGeneralOptionsWidget->TunnelDeviceTypeComboBox->insertItem("TAP"); + + ProfileCiscoOptionsWidget->CiscoNatModeComboBox->insertItem("natt"); + ProfileCiscoOptionsWidget->CiscoNatModeComboBox->insertItem("force-natt"); + ProfileCiscoOptionsWidget->CiscoNatModeComboBox->insertItem("cisco-udp"); + ProfileCiscoOptionsWidget->CiscoNatModeComboBox->insertItem("none"); + connect (ProfileCiscoOptionsWidget->CiscoNatModeComboBox, SIGNAL(textChanged ( const QString &)), this, SLOT(natModeToggled( const QString &))); + + + profileAddedOrDeleted = false; + NewProfileName = ""; + bool vpnclient_profile_in_list=false; + + // profile data + VpnAccountData * it; + if ( !GlobalConfig->AccountList->isEmpty() ) + { + + for ( it = GlobalConfig->AccountList->first(); it; it = GlobalConfig->AccountList->next() ) + { + if ( it != 0 ) + { + if ( GlobalConfig->KvpncDebugLevel > 3 ) + GlobalConfig->appendLogEntry( "item found: " + it->getName(), KVpncConfig::debug ); + + ProfileGeneralSelector->insertItem( it->getName() ); + ProfileNetworkRouteSelector->insertItem( it->getName() ); + ProfileNetworkGeneralSelector->insertItem( it->getName() ); + ProfileNetworkNatSelector->insertItem( it->getName() ); + ProfileNetworkHttpProxySelector->insertItem( it->getName() ); + ProfileNetworkVirtualIpSelector->insertItem( it->getName() ); + ProfileCertSelector->insertItem( it->getName() ); + ProfileSmartcardSelector->insertItem( it->getName() ); + ProfilePskSelector->insertItem( it->getName() ); + ProfileUserSelector->insertItem( it->getName() ); + ProfileOpenvpnSelector->insertItem( it->getName() ); + ProfilePptpSelector->insertItem( it->getName() ); + ProfileVtunSelector->insertItem( it->getName() ); + ProfileSshSelector->insertItem( it->getName() ); + ProfileRacoonSelector->insertItem( it->getName() ); + ProfileIpsecSelector->insertItem( it->getName() ); + ProfileCiscoSelector->insertItem( it->getName() ); + ProfileCmdExecBeforeConnectSelector->insertItem( it->getName() ); + ProfileCmdExecBeforeDisconnectSelector->insertItem( it->getName() ); + ProfileCmdExecAfterConnectSelector->insertItem( it->getName() ); + ProfileCmdExecAfterDisconnectSelector->insertItem( it->getName() ); + + if (vpnclient_profile_in_list==false) + if (it->getConnectionType() == VpnAccountData::ciscoorig) + vpnclient_profile_in_list=true; + } + } + + if ( Utils ( GlobalConfig ).getToolInfo ( "vpnclient" )->found == true && vpnclient_profile_in_list==true ) + { + slotStatusMsg ( i18n("Collecting cisco certs from Cisco certificate store..."), ID_STATUS_MSG ); + CiscoCerts.clear(); + if (GlobalConfig->KvpncDebugLevel > 2) + GlobalConfig->appendLogEntry(i18n("Looking for certs in Cisco certificate store..."),GlobalConfig->debug); + CiscoCerts = Utils(GlobalConfig).getCertsFromCiscoCertStore(); + + slotStatusMsg ( i18n("Collecting cisco CA certs from Cisco certificate store..."), ID_STATUS_MSG ); + CiscoCaCerts.clear(); + if (GlobalConfig->KvpncDebugLevel > 2) + GlobalConfig->appendLogEntry(i18n("Looking for CA certs in Cisco certificate store..."),GlobalConfig->debug); + CiscoCaCerts = Utils(GlobalConfig).getCertsFromCiscoCertStore("ca"); + + if (GlobalConfig->KvpncDebugLevel > 2) + GlobalConfig->appendLogEntry(i18n("done."),GlobalConfig->debug); + + slotStatusMsg ( i18n("Ready."), ID_STATUS_MSG ); + } + + + if ( GlobalConfig->currentProfile != 0 ) + { + // set only if in list of current ciphers + // if ( ciphers.contains(GlobalConfig->currentProfile->getUserdefiniedCipher())) { + if ( !GlobalConfig->currentProfile->getUserdefiniedCipher().isEmpty() ) + ProfileOpenvpnOptionsWidget->UserdefiniedCipherComboBox->setCurrentText( GlobalConfig->currentProfile->getUserdefiniedCipher() ); + else + ProfileOpenvpnOptionsWidget->UserdefiniedCipherComboBox->setCurrentText( ciphers.first() ); + ProfileOpenvpnOptionsWidget->UseUserdefiniedCipherCheckBox->setChecked( GlobalConfig->currentProfile->getUseUserdefiniedCipher() ); + // } + // else + // ProfileOpenvpnOptionsWidget->UseUserdefinedPortCheckBox->setChecked(false); + + + ProfileOpenvpnOptionsWidget->UseTlsAuthCheckBox->setChecked( GlobalConfig->currentProfile->getUseTlsAuth() ); + ProfileOpenvpnOptionsWidget->TlsAuthURLRequester->setURL( GlobalConfig->currentProfile->getTlsAuthFile() ); + + ProfileOpenvpnOptionsWidget->UseTlsRemoteHostCheckBox->setChecked( GlobalConfig->currentProfile->getUseTlsRemoteHost() ); + ProfileOpenvpnOptionsWidget->TlsRemoteHostLineEdit->setText( GlobalConfig->currentProfile->getTlsRemoteHost() ); + ProfileOpenvpnOptionsWidget->AuthenticationDirectionComboBox->insertItem(i18n("None")); + ProfileOpenvpnOptionsWidget->AuthenticationDirectionComboBox->insertItem(i18n("0")); + ProfileOpenvpnOptionsWidget->AuthenticationDirectionComboBox->insertItem(i18n("1")); + + ProfileNetworkHttpProxyOptionsWidget->UseHttpProxyCheckBox->setChecked( GlobalConfig->currentProfile->getUseHttpProxy() ); + ProfileNetworkHttpProxyOptionsWidget->HttpProxyLineEdit->setText( GlobalConfig->currentProfile->getHttpProxy() ); + ProfileNetworkHttpProxyOptionsWidget->HttpProxyTimeoutIntSpinBox->setValue( GlobalConfig->currentProfile->getHttpProxyTimeout() ); + ProfileNetworkHttpProxyOptionsWidget->HttpProxyPortIntNumInput->setValue( GlobalConfig->currentProfile->getHttpProxyPort() ); + ProfileNetworkHttpProxyOptionsWidget->useHttpProxyToggeled(GlobalConfig->currentProfile->getUseHttpProxy()); + + if ( GlobalConfig->currentProfile->getHttpProxyAuthType() == "basic" ) + ProfileNetworkHttpProxyOptionsWidget->HttpProxyAuthTypeComboBox->setCurrentText( "Basic" ); + else if ( GlobalConfig->currentProfile->getHttpProxyAuthType() == "ntlm" ) + ProfileNetworkHttpProxyOptionsWidget->HttpProxyAuthTypeComboBox->setCurrentText( "NTLM" ); + else + ProfileNetworkHttpProxyOptionsWidget->HttpProxyAuthTypeComboBox->setCurrentText( "Basic" ); + + ProfileNetworkHttpProxyOptionsWidget->HttpProxyUserLineEdit->setText( GlobalConfig->currentProfile->getHttpProxyUser() ); + ProfileNetworkHttpProxyOptionsWidget->HttpProxyAuthPasswordEdit->setText( GlobalConfig->currentProfile->getHttpProxyPass() ); + + ProfileNetworkHttpProxyOptionsWidget->UseHttpProxyAuthCheckBox->setChecked( GlobalConfig->currentProfile->getUseHttpProxyAuth() ); + + ProfileGeneralSelector->setCurrentText( GlobalConfig->currentProfile->getName() ); + ProfileNetworkRouteSelector->setCurrentText( GlobalConfig->currentProfile->getName() ); + ProfileNetworkGeneralSelector->setCurrentText( GlobalConfig->currentProfile->getName() ); + ProfileNetworkNatSelector->setCurrentText( GlobalConfig->currentProfile->getName() ); + ProfileNetworkHttpProxySelector->setCurrentText( GlobalConfig->currentProfile->getName() ); + ProfileNetworkVirtualIpSelector->setCurrentText( GlobalConfig->currentProfile->getName() ); + ProfileCertSelector->setCurrentText( GlobalConfig->currentProfile->getName() ); + ProfileSmartcardSelector->setCurrentText( GlobalConfig->currentProfile->getName() ); + ProfilePskSelector->setCurrentText( GlobalConfig->currentProfile->getName() ); + ProfileUserSelector->setCurrentText( GlobalConfig->currentProfile->getName() ); + ProfileOpenvpnSelector->setCurrentText( GlobalConfig->currentProfile->getName() ); + ProfilePptpSelector->setCurrentText( GlobalConfig->currentProfile->getName() ); + ProfileVtunSelector->setCurrentText( GlobalConfig->currentProfile->getName() ); + ProfileSshSelector->setCurrentText( GlobalConfig->currentProfile->getName() ); + ProfileRacoonSelector->setCurrentText( GlobalConfig->currentProfile->getName() ); + ProfileIpsecSelector->setCurrentText( GlobalConfig->currentProfile->getName() ); + ProfileCiscoSelector->setCurrentText( GlobalConfig->currentProfile->getName() ); + ProfileCmdExecBeforeConnectSelector->setCurrentText( GlobalConfig->currentProfile->getName() ); + ProfileCmdExecBeforeDisconnectSelector->setCurrentText( GlobalConfig->currentProfile->getName() ); + ProfileCmdExecAfterConnectSelector->setCurrentText( GlobalConfig->currentProfile->getName() ); + ProfileCmdExecAfterDisconnectSelector->setCurrentText( GlobalConfig->currentProfile->getName() ); + + ProfileNetworkGeneralOptionsWidget->MtuCheckbox->setChecked( GlobalConfig->currentProfile->getUseMtu() ); + ProfileNetworkGeneralOptionsWidget->MtuSpinbox->setValue( GlobalConfig->currentProfile->getMtu() ); + ProfileNetworkGeneralOptionsWidget->MruCheckbox->setChecked( GlobalConfig->currentProfile->getUseMru() ); + ProfileNetworkGeneralOptionsWidget->MruSpinbox->setValue( GlobalConfig->currentProfile->getMru() ); + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::cisco || + GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::pptp || + GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan || + GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan || + GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::openvpn ) + { + ProfileNetworkGeneralOptionsWidget->MtuCheckbox->setEnabled( true ); + ProfileNetworkGeneralOptionsWidget->MruCheckbox->setEnabled( true ); + + if ( GlobalConfig->currentProfile->getUseMtu() ) + ProfileNetworkGeneralOptionsWidget->MtuSpinbox->setEnabled( true ); + else + ProfileNetworkGeneralOptionsWidget->MtuSpinbox->setEnabled( false ); + + if ( GlobalConfig->currentProfile->getUseMru() ) + ProfileNetworkGeneralOptionsWidget->MruSpinbox->setEnabled( true ); + else + ProfileNetworkGeneralOptionsWidget->MruSpinbox->setEnabled( false ); + } + else + { + ProfileNetworkGeneralOptionsWidget->MtuCheckbox->setEnabled( false ); + ProfileNetworkGeneralOptionsWidget->MruCheckbox->setEnabled( false ); + } + + } + else + { + // ProfileGeneralOptionsWidget->ProfileComboBox->setCurrentText( "" ); + // ProfileNetworkRouteOptionsWidget->ProfileComboBox->setCurrentText( "" ); + // ProfileNetworkNatOptionsWidget->ProfileComboBox->setCurrentText( "" ); + // ProfileNetworkVirtualIpOptionsWidget->ProfileComboBox->setCurrentText( "" ); + // ProfileCertPskOptionsWidget->ProfileComboBox->setCurrentText( "" ); + // ProfileUserOptionsWidget->ProfileComboBox->setCurrentText( "" ); + // ProfileOpenvpnOptionsWidget->ProfileComboBox->setCurrentText( "" ); + // ProfilePptpOptionsWidget->ProfileComboBox->setCurrentText( "" ); + // ProfileRacoonOptionsWidget->ProfileComboBox->setCurrentText( "" ); + // ProfileCiscoOptionsWidget->ProfileComboBox->setCurrentText( "" ); + // ProfileCmdExecBeforeConnectOptionsWidget->ProfileComboBox->setCurrentText( "" ); + // ProfileCmdExecBeforeDisconnectOptionsWidget->ProfileComboBox->setCurrentText( "" ); + // ProfileCmdExecAfterConnectOptionsWidget->ProfileComboBox->setCurrentText( "" ); + // ProfileCmdExecAfterDisconnectOptionsWidget->ProfileComboBox->setCurrentText( "" ); + + ProfileGeneralOptionsWidget->setEnabled( false ); + ProfileNetworkRouteOptionsWidget->setEnabled( false ); + ProfileNetworkNatOptionsWidget->setEnabled( false ); + ProfileNetworkVirtualIpOptionsWidget->setEnabled( false ); + ProfileCertOptionsWidget->setEnabled( false ); + ProfilePskOptionsWidget->setEnabled( false ); + ProfileUserOptionsWidget->setEnabled( false ); + ProfileOpenvpnOptionsWidget->setEnabled( false ); + ProfilePptpOptionsWidget->setEnabled( false ); + ProfileRacoonOptionsWidget->setEnabled( false ); + ProfileIpsecOptionsWidget->setEnabled( false ); + ProfileCiscoOptionsWidget->setEnabled( false ); + ProfileCmdExecBeforeConnectOptionsWidget->setEnabled( false ); + ProfileCmdExecBeforeDisconnectOptionsWidget->setEnabled( false ); + ProfileCmdExecAfterConnectOptionsWidget->setEnabled( false ); + ProfileCmdExecAfterDisconnectOptionsWidget->setEnabled( false ); + ProfileGeneralOptionsWidget->NewSessionPushButton->setEnabled( true ); + + } + } + else + { + ProfileGeneralOptionsWidget->RenameSessionPushButton->setEnabled( false ); + ProfileGeneralOptionsWidget->DeleteSessionPushButton->setEnabled( false ); + ProfileGeneralOptionsWidget->SaveSessionPushButton->setEnabled( false ); + } + + + NetworkInterface iface( GlobalConfig, GlobalConfig->appPointer ); + QStringList list = iface.getAllNetworkInterfaces(); + ProfileNetworkGeneralOptionsWidget->NetworkDeviceComboBox->insertItem( "default" ); + + // // pppd settings + ProfilePptpOptionsWidget->DnsServerLineedit->setEnabled( false ); + + // disabled for now + ProfileCertOptionsWidget->AllowEmptyPrivateKeyPasswordCheckBox->hide(); + + ProfileNetworkVirtualIpOptionsWidget->UseVirtualIPCheckBox->setEnabled( true ); +// ProfileNetworkVirtualIpOptionsWidget->RemoteVirtualIpLineEdit->setEnabled( true ); +// ProfileNetworkVirtualIpOptionsWidget->LocalVirtualIpEdit->setEnabled( true ); +// ProfileNetworkVirtualIpOptionsWidget->LabelRemoteVirtualIp->setEnabled( true ); +// ProfileNetworkVirtualIpOptionsWidget->LabelLocalVirtualIp->setEnabled( true ); + + for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) + { + ProfileNetworkGeneralOptionsWidget->NetworkDeviceComboBox->insertItem( QString( *it ) ); + } + ProfileNetworkGeneralOptionsWidget->NetworkDeviceComboBox->setEnabled( true ); + ProfileNetworkGeneralOptionsWidget->LabelNetworkDevice->setEnabled( true ); + + if ( GlobalConfig->currentProfile != 0 ) + { + profileChanged( GlobalConfig->currentProfile->getName() ); + } + + configChanged=false; + canAccept = true; + KDialogBase::adjustSize(); + GlobalConfig->appPointer->restoreOverrideCursor(); +} + +void PreferencesDialog::setupGui() +{ + + setShowIconsInTreeList( true ); + + QStringList path; + path.clear(); + path << i18n( "KVpnc" ); + setFolderIcon ( path, SmallIcon( "application", KIcon::SizeSmall ) ); + + path.clear(); + + QVBoxLayout *lo; + + if ( !showOnlyProfiles ) + { + /* called as preferences dialog */ + + // General page + path << i18n( "Application" ) << i18n( "General" ); + GeneralFrame = addPage( path, i18n( "General" ), BarIcon( "kvpnc", KIcon::SizeSmall ) ); + lo = new QVBoxLayout( GeneralFrame, 0, KDialog::spacingHint() ); + GeneralOptionsWidget = new ConfigGeneralOptions( GeneralFrame ); + lo->addWidget( GeneralOptionsWidget ); + connect(GeneralOptionsWidget->useKwalletCheckBox, SIGNAL(toggled(bool)),this, SLOT(useKwalletToggled(bool))); + + // const QObjectList *GeneralOptionsWidgetList = GeneralOptionsWidget->queryList( "QCheckBox" ); + // QObjectListIt it( *GeneralOptionsWidgetList ); + // + // for ( QObject *child = it.current(); it; ++it) + // { + // // std::cout << "name: " << child->name() << std::endl; + // connect(child, SIGNAL(stateChanged(int)), this, SLOT(checkboxStateChanged(int))); + // } + + // Debug + path.clear(); + path << i18n( "Application" ) << i18n( "Debug" ); + DebugFrame = addPage( path, i18n( "Debug" ), BarIcon( "bug", KIcon::SizeSmall ) ); + lo = new QVBoxLayout( DebugFrame ); + lo->setSpacing( KDialog::spacingHint() ); + DebugOptionsWidget = new ConfigDebugOptions( DebugFrame, "Debug" ); + lo->addWidget( DebugOptionsWidget ); + + path.clear(); + path << i18n( "Application" ) << i18n( "Connect" ); + ConfigConnectOptionsFrame = addPage( path, i18n( "Connect" ), BarIcon( "connecting", KIcon::SizeSmall ) ); + lo = new QVBoxLayout( ConfigConnectOptionsFrame ); + lo->setSpacing( KDialog::spacingHint() ); + ConnectOptionsWidget = new ConfigConnectOptions( ConfigConnectOptionsFrame ); + lo->addWidget( ConnectOptionsWidget ); + + path.clear(); + path << i18n( "Application" ) << i18n( "Log" ); + LogFrame = addPage( path, i18n( "Log" ), BarIcon( "text_center", KIcon::SizeSmall ) ); + lo = new QVBoxLayout( LogFrame ); + lo->setSpacing( KDialog::spacingHint() ); + LogOptionsWidget = new ConfigLogOptions( LogFrame ); + lo->addWidget( LogOptionsWidget ); + + path << i18n( "Programs" ); + setFolderIcon ( path, SmallIcon( "kvpnc", KIcon::SizeSmall ) ); + + path.clear(); + path << i18n( "Programs" ) << i18n( "Daemons" ); + DaemonOptionsFrame = addVBoxPage( path, i18n( "Daemons" ), BarIcon( "fork", KIcon::SizeSmall ) ); +// DaemonOptionsFrame->resize(DaemonOptionsFrame->sizeHint()); +// lo = new QVBoxLayout( DaemonOptionsFrame ); + DaemonScrollView = new QScrollView(DaemonOptionsFrame, "daemonscrollview"); + lo = new QVBoxLayout( DaemonScrollView ); + lo->setSpacing( KDialog::spacingHint() ); + lo->addWidget(DaemonScrollView); + ConfigDaemonOptionsWidget = new ConfigDaemonOptions( DaemonScrollView->viewport() ); + DaemonScrollView->addChild(ConfigDaemonOptionsWidget); +// ConfigDaemonOptionsWidget->setFixedSize(520,ConfigDaemonOptionsWidget->height()); +// ConfigDaemonOptionsWidget->setFixedSize(DaemonScrollView->contentsWidth ()-DaemonScrollView->verticalScrollBar()->height()-95,ConfigDaemonOptionsWidget->height()); + + +// DaemonScrollView->adjustSize(); + QSize deamonsize = ConfigDaemonOptionsWidget->sizeHint(); + ConfigDaemonOptionsWidget->resize(QSize(deamonsize.width()-4,deamonsize.height())); + ConfigDaemonOptionsWidget->setFixedSize(QSize(deamonsize.width()-4,deamonsize.height())); +// DaemonScrollView->resize(sv->sizeHint()); +// lo->addWidget( DaemonScrollView ); +// DaemonFrame->adjustSize(); + + + connect(ConfigDaemonOptionsWidget->OpenvpnPathInput, SIGNAL( urlSelected( const QString& ) ), this, SLOT( OpenvpnPathChanged( const QString& ) ) ); + connect(ConfigDaemonOptionsWidget->FreeswanPathInput, SIGNAL( urlSelected( const QString& ) ), this, SLOT( FreeswanPathChanged( const QString& ) ) ); + connect(ConfigDaemonOptionsWidget->PppdPathInput, SIGNAL( urlSelected( const QString& ) ), this, SLOT( PppdPathChanged( const QString& ) ) ); + connect(ConfigDaemonOptionsWidget->PptpPathInput, SIGNAL( urlSelected( const QString& ) ), this, SLOT( PptpPathChanged( const QString& ) ) ); + connect(ConfigDaemonOptionsWidget->RacoonPathInput, SIGNAL( urlSelected( const QString& ) ), this, SLOT( RacoonPathChanged( const QString& ) ) ); + connect(ConfigDaemonOptionsWidget->VpncPathInput, SIGNAL( urlSelected( const QString& ) ), this, SLOT( VpncPathChanged( const QString& ) ) ); + connect(ConfigDaemonOptionsWidget->L2tpdPathInput, SIGNAL( urlSelected( const QString& ) ), this, SLOT( L2tpdPathChanged( const QString& ) ) ); + connect(ConfigDaemonOptionsWidget->Xl2tpdPathInput, SIGNAL( urlSelected( const QString& ) ), this, SLOT( Xl2tpdPathChanged( const QString& ) ) ); + connect(ConfigDaemonOptionsWidget->VtundPathInput, SIGNAL( urlSelected( const QString& ) ), this, SLOT( VtundPathChanged( const QString& ) ) ); + connect(ConfigDaemonOptionsWidget->SshPathInput, SIGNAL( urlSelected( const QString& ) ), this, SLOT( SshPathChanged( const QString& ) ) ); + + path.clear(); + path << i18n( "Programs" ) << i18n( "Helper Programs" ); + HelperProgramFrame = addPage( path, i18n( "Helper Programs" ), BarIcon( "tool", KIcon::SizeSmall ) ); + lo = new QVBoxLayout( HelperProgramFrame ); + lo->setSpacing( KDialog::spacingHint() ); + + HelperProgramOptionsWidget = new ConfigHelperProgramOptions( HelperProgramFrame ); + lo->addWidget( HelperProgramFrame ); + + setTreeListAutoResize( false ); + } + + // Profile page + path.clear(); + path << i18n( "Profile" ); + setFolderIcon ( path, SmallIcon( "view_icon", KIcon::SizeSmall ) ); + + path.clear(); + path << i18n( "Profile" ) << i18n( "General" ); + ProfileGeneralOptionsFrame = addPage( path, i18n( "General" ), BarIcon( "application", KIcon::SizeSmall ) ); + lo = new QVBoxLayout( ProfileGeneralOptionsFrame ); + lo->setSpacing( KDialog::spacingHint() ); + + QWidget *ProfileGeneralSelectorWidget = new QWidget( ProfileGeneralOptionsFrame ); + QHBoxLayout *ProfileGeneralSelectorLayout = new QHBoxLayout( ProfileGeneralSelectorWidget ); + QLabel *ProfileGeneralSelectorLabel = new QLabel( ProfileGeneralSelectorWidget ); + ProfileGeneralSelectorLabel->setText( i18n( "Profile:" ) ); + ProfileGeneralSelector = new QComboBox( ProfileGeneralSelectorWidget ); + ProfileGeneralSelectorLayout->addWidget( ProfileGeneralSelectorLabel ); + ProfileGeneralSelectorLayout->addWidget( ProfileGeneralSelector ); + + ProfileGeneralOptionsWidget = new ProfileGeneralOptions( ProfileGeneralOptionsFrame, GlobalConfig ); + + lo->addWidget( ProfileGeneralSelectorWidget ); + lo->addWidget( ProfileGeneralOptionsWidget ); + ProfileGeneralSelector->setEnabled( true ); + + path.clear(); + path << i18n( "Profile" ) << i18n( "Authenticate" ) << i18n( "User data" ); + ProfileUserOptionsFrame = addPage( path, i18n( "User Data" ), BarIcon( "user", KIcon::SizeSmall ) ); + lo = new QVBoxLayout( ProfileUserOptionsFrame ); + lo->setSpacing( KDialog::spacingHint() ); + + QWidget *ProfileUserSelectorWidget = new QWidget( ProfileUserOptionsFrame ); + QHBoxLayout *ProfileUserSelectorLayout = new QHBoxLayout( ProfileUserSelectorWidget ); + QLabel *ProfileUserSelectorLabel = new QLabel( ProfileUserSelectorWidget ); + ProfileUserSelectorLabel->setText( i18n( "Profile:" ) ); + ProfileUserSelector = new QComboBox( ProfileUserSelectorWidget ); + ProfileUserSelectorLayout->addWidget( ProfileUserSelectorLabel ); + ProfileUserSelectorLayout->addWidget( ProfileUserSelector ); + + + ProfileUserOptionsWidget = new ProfileUserOptions( ProfileUserOptionsFrame ); + lo->addWidget( ProfileUserSelectorWidget ); + lo->addWidget( ProfileUserOptionsWidget ); + ProfileUserSelector->setEnabled( true ); + connect(ProfileUserOptionsWidget->NtDomainNameCheckbox, SIGNAL(toggled(bool)), ProfileUserOptionsWidget, SLOT( domainNameToggled(bool) )); + + path.clear(); + path << i18n( "Profile" ) << i18n( "Authenticate" ) << i18n( "Certificate" ); + ProfileCertOptionsFrame = addVBoxPage( path, i18n( "Certificate" ), BarIcon( "certimport", KIcon::SizeSmall ) ); + lo = new QVBoxLayout( ProfileCertOptionsFrame ); + lo->setSpacing( KDialog::spacingHint() ); + QWidget *ProfileCertSelectorWidget = new QWidget( ProfileCertOptionsFrame ); + QHBoxLayout *ProfileCertSelectorLayout = new QHBoxLayout( ProfileCertSelectorWidget ); + QLabel *ProfileCertSelectorLabel = new QLabel( ProfileCertSelectorWidget ); + ProfileCertSelectorLabel->setText( i18n( "Profile:" ) ); + ProfileCertSelector = new QComboBox( ProfileCertSelectorWidget ); + ProfileCertSelectorLayout->addWidget( ProfileCertSelectorLabel ); + ProfileCertSelectorLayout->addWidget( ProfileCertSelector ); + + ProfileCertOptionsWidget = new ProfileCertOptions( ProfileCertOptionsFrame); + lo->addWidget( ProfileCertSelectorWidget ); + lo->addWidget( ProfileCertOptionsWidget ); + ProfileCertSelector->setEnabled( true ); + connect(ProfileCertOptionsWidget->ImportCertificatePushButton, SIGNAL(clicked()), this, SLOT(importCertificate())); + connect(ProfileCertOptionsWidget->UseCiscoCertStoreCheckBox, SIGNAL(toggled(bool)), this, SLOT(useCiscoCertStoreToggled(bool))); + + path.clear(); + path << i18n( "Profile" ) << i18n( "Authenticate" ) << i18n( "Smartcard" ); + ProfileSmartcardOptionsFrame = addPage( path, i18n( "Smartcard" ), BarIcon( "smartcard", KIcon::SizeSmall ) ); + lo = new QVBoxLayout( ProfileSmartcardOptionsFrame ); + lo->setSpacing( KDialog::spacingHint() ); + + QWidget *ProfileSmartcardSelectorWidget = new QWidget( ProfileSmartcardOptionsFrame ); + QHBoxLayout *ProfileSmartcardSelectorLayout = new QHBoxLayout( ProfileSmartcardSelectorWidget ); + QLabel *ProfileSmartcardSelectorLabel = new QLabel( ProfileSmartcardSelectorWidget ); + ProfileSmartcardSelectorLabel->setText( i18n( "Profile:" ) ); + ProfileSmartcardSelector = new QComboBox( ProfileSmartcardSelectorWidget ); + ProfileSmartcardSelectorLayout->addWidget( ProfileSmartcardSelectorLabel ); + ProfileSmartcardSelectorLayout->addWidget( ProfileSmartcardSelector ); + + ProfileSmartcardOptionsWidget = new ProfileSmartcardOptions( ProfileSmartcardOptionsFrame ); + lo->addWidget( ProfileSmartcardSelectorWidget ); + lo->addWidget( ProfileSmartcardOptionsWidget ); + ProfileSmartcardSelector->setEnabled( true ); + connect(ProfileSmartcardOptionsWidget->DetectPkcs11SlotsPushButton, SIGNAL(clicked()), this, SLOT(detectPkcs11Slots())); + connect(ProfileSmartcardOptionsWidget->DetectPkcs11IdPushButton, SIGNAL(clicked()), this, SLOT(detectPkcs11Ids())); + + path.clear(); + path << i18n( "Profile" ) << i18n( "Authenticate" ) << i18n( "PSK" ); + ProfilePskOptionsFrame = addPage( path, i18n( "PSK" ), BarIcon( "password", KIcon::SizeSmall ) ); + lo = new QVBoxLayout( ProfilePskOptionsFrame ); + lo->setSpacing( KDialog::spacingHint() ); + + QWidget *ProfilePskSelectorWidget = new QWidget( ProfilePskOptionsFrame ); + QHBoxLayout *ProfilePskSelectorLayout = new QHBoxLayout( ProfilePskSelectorWidget ); + QLabel *ProfilePskSelectorLabel = new QLabel( ProfilePskSelectorWidget ); + ProfilePskSelectorLabel->setText( i18n( "Profile:" ) ); + ProfilePskSelector = new QComboBox( ProfilePskSelectorWidget ); + ProfilePskSelectorLayout->addWidget( ProfilePskSelectorLabel ); + ProfilePskSelectorLayout->addWidget( ProfilePskSelector ); + + ProfilePskOptionsWidget = new ProfilePskOptions( ProfilePskOptionsFrame ); + lo->addWidget( ProfilePskSelectorWidget ); + lo->addWidget( ProfilePskOptionsWidget ); + ProfilePskSelector->setEnabled( true ); + + path.clear(); + path << i18n( "Profile" ) << i18n( "Network" ) << i18n( "General" ); + ProfileNetworkGeneralOptionsFrame = addPage( path, i18n( "General" ), BarIcon( "network", KIcon::SizeSmall ) ); + lo = new QVBoxLayout( ProfileNetworkGeneralOptionsFrame ); + lo->setSpacing( KDialog::spacingHint() ); + + QWidget *ProfileNetworkGeneralSelectorWidget = new QWidget( ProfileNetworkGeneralOptionsFrame ); + QHBoxLayout *ProfileNetworkGeneralSelectorLayout = new QHBoxLayout( ProfileNetworkGeneralSelectorWidget ); + QLabel *ProfileNetworkGeneralSelectorLabel = new QLabel( ProfileNetworkGeneralSelectorWidget ); + ProfileNetworkGeneralSelectorLabel->setText( i18n( "Profile:" ) ); + ProfileNetworkGeneralSelector = new QComboBox( ProfileNetworkGeneralSelectorWidget ); + ProfileNetworkGeneralSelectorLayout->addWidget( ProfileNetworkGeneralSelectorLabel ); + ProfileNetworkGeneralSelectorLayout->addWidget( ProfileNetworkGeneralSelector ); + + ProfileNetworkGeneralOptionsWidget = new ProfileNetworkGeneralOptions( ProfileNetworkGeneralOptionsFrame ); + + lo->addWidget( ProfileNetworkGeneralSelectorWidget ); + lo->addWidget( ProfileNetworkGeneralOptionsWidget ); + ProfileNetworkGeneralSelector->setEnabled( true ); + + path.clear(); + path << i18n( "Profile" ) << i18n( "Network" ) << i18n( "Routes" ); + ProfileNetworkRouteOptionsFrame = addPage( path, i18n( "Routes" ), BarIcon( "route", KIcon::SizeSmall ) ); + lo = new QVBoxLayout( ProfileNetworkRouteOptionsFrame ); + lo->setSpacing( KDialog::spacingHint() ); + + QWidget *ProfileNetworkRouteSelectorWidget = new QWidget( ProfileNetworkRouteOptionsFrame ); + QHBoxLayout *ProfileNetworkRouteSelectorLayout = new QHBoxLayout( ProfileNetworkRouteSelectorWidget ); + QLabel *ProfileNetworkRouteSelectorLabel = new QLabel( ProfileNetworkRouteSelectorWidget ); + ProfileNetworkRouteSelectorLabel->setText( i18n( "Profile:" ) ); + ProfileNetworkRouteSelector = new QComboBox( ProfileNetworkRouteSelectorWidget ); + ProfileNetworkRouteSelectorLayout->addWidget( ProfileNetworkRouteSelectorLabel ); + ProfileNetworkRouteSelectorLayout->addWidget( ProfileNetworkRouteSelector ); + + ProfileNetworkRouteOptionsWidget = new ProfileNetworkRouteOptions( ProfileNetworkRouteOptionsFrame ); + + lo->addWidget( ProfileNetworkRouteSelectorWidget ); + lo->addWidget( ProfileNetworkRouteOptionsWidget ); + ProfileNetworkRouteSelector->setEnabled( true ); + + path.clear(); + path << i18n( "Profile" ) << i18n( "Network" ) << i18n( "NAT" ); + ProfileNetworkNatOptionsFrame = addPage( path, i18n( "NAT" ), BarIcon( "application", KIcon::SizeSmall ) ); + lo = new QVBoxLayout( ProfileNetworkNatOptionsFrame ); + lo->setSpacing( KDialog::spacingHint() ); + + QWidget *ProfileNetworkNatSelectorWidget = new QWidget( ProfileNetworkNatOptionsFrame ); + QHBoxLayout *ProfileNetworkNatSelectorLayout = new QHBoxLayout( ProfileNetworkNatSelectorWidget ); + QLabel *ProfileNetworkNatSelectorLabel = new QLabel( ProfileNetworkNatSelectorWidget ); + ProfileNetworkNatSelectorLabel->setText( i18n( "Profile:" ) ); + ProfileNetworkNatSelector = new QComboBox( ProfileNetworkNatSelectorWidget ); + ProfileNetworkNatSelectorLayout->addWidget( ProfileNetworkNatSelectorLabel ); + ProfileNetworkNatSelectorLayout->addWidget( ProfileNetworkNatSelector ); + + ProfileNetworkNatOptionsWidget = new ProfileNetworkNatOptions( ProfileNetworkNatOptionsFrame ); + + lo->addWidget( ProfileNetworkNatSelectorWidget ); + lo->addWidget( ProfileNetworkNatOptionsWidget ); + ProfileNetworkNatSelector->setEnabled( true ); + + path.clear(); + path << i18n( "Profile" ) << i18n( "Network" ) << i18n( "HTTP proxy" ); + ProfileNetworkHttpProxyOptionsFrame = addPage( path, i18n( "HTTP proxy" ), BarIcon( "application", KIcon::SizeSmall ) ); + lo = new QVBoxLayout( ProfileNetworkHttpProxyOptionsFrame ); + lo->setSpacing( KDialog::spacingHint() ); + + QWidget *ProfileNetworkHttpProxySelectorWidget = new QWidget( ProfileNetworkHttpProxyOptionsFrame ); + QHBoxLayout *ProfileNetworkHttpProxySelectorLayout = new QHBoxLayout( ProfileNetworkHttpProxySelectorWidget ); + QLabel *ProfileNetworkHttpProxySelectorLabel = new QLabel( ProfileNetworkHttpProxySelectorWidget ); + ProfileNetworkHttpProxySelectorLabel->setText( i18n( "Profile:" ) ); + ProfileNetworkHttpProxySelector = new QComboBox( ProfileNetworkHttpProxySelectorWidget ); + ProfileNetworkHttpProxySelectorLayout->addWidget( ProfileNetworkHttpProxySelectorLabel ); + ProfileNetworkHttpProxySelectorLayout->addWidget( ProfileNetworkHttpProxySelector ); + + ProfileNetworkHttpProxyOptionsWidget = new ProfileNetworkHttpProxyOptions( ProfileNetworkHttpProxyOptionsFrame ); + + lo->addWidget( ProfileNetworkHttpProxySelectorWidget ); + lo->addWidget( ProfileNetworkHttpProxyOptionsWidget ); + ProfileNetworkHttpProxySelector->setEnabled( true ); + + + path.clear(); + path << i18n( "Profile" ) << i18n( "Network" ) << i18n( "Virtual IP" ); + ProfileNetworkVirtualIpOptionsFrame = addPage( path, i18n( "Virtual IP" ), BarIcon( "application", KIcon::SizeSmall ) ); + lo = new QVBoxLayout( ProfileNetworkVirtualIpOptionsFrame ); + lo->setSpacing( KDialog::spacingHint() ); + + QWidget *ProfileNetworkVirtualIpSelectorWidget = new QWidget( ProfileNetworkVirtualIpOptionsFrame ); + QHBoxLayout *ProfileNetworkVirtualIpSelectorLayout = new QHBoxLayout( ProfileNetworkVirtualIpSelectorWidget ); + QLabel *ProfileNetworkVirtualIpSelectorLabel = new QLabel( ProfileNetworkVirtualIpSelectorWidget ); + ProfileNetworkVirtualIpSelectorLabel->setText( i18n( "Profile:" ) ); + ProfileNetworkVirtualIpSelector = new QComboBox( ProfileNetworkVirtualIpSelectorWidget ); + ProfileNetworkVirtualIpSelectorLayout->addWidget( ProfileNetworkVirtualIpSelectorLabel ); + ProfileNetworkVirtualIpSelectorLayout->addWidget( ProfileNetworkVirtualIpSelector ); + + ProfileNetworkVirtualIpOptionsWidget = new ProfileNetworkVirtualIpOptions( ProfileNetworkVirtualIpOptionsFrame ); + + lo->addWidget( ProfileNetworkVirtualIpSelectorWidget ); + lo->addWidget( ProfileNetworkVirtualIpOptionsWidget ); + ProfileNetworkVirtualIpSelector->setEnabled( true ); + connect(ProfileNetworkGeneralOptionsWidget->TunnelDeviceTypeComboBox, SIGNAL(activated ( const QString & )),this, SLOT(tunnelDeviceTypeChanged(const QString& ))); + + path.clear(); + path << i18n( "Profile" ) << i18n( "Connection specific" ) << i18n( "Cisco" ); + ProfileCiscoOptionsFrame = addPage( path, i18n( "Cisco" ), BarIcon( "cisco", KIcon::SizeSmall ) ); + lo = new QVBoxLayout( ProfileCiscoOptionsFrame ); + lo->setSpacing( KDialog::spacingHint() ); + + QWidget *ProfileCiscoSelectorWidget = new QWidget( ProfileCiscoOptionsFrame ); + QHBoxLayout *ProfileCiscoSelectorLayout = new QHBoxLayout( ProfileCiscoSelectorWidget ); + QLabel *ProfileCiscoSelectorLabel = new QLabel( ProfileCiscoSelectorWidget ); + ProfileCiscoSelectorLabel->setText( i18n( "Profile:" ) ); + ProfileCiscoSelector = new QComboBox( ProfileCiscoSelectorWidget ); + ProfileCiscoSelectorLayout->addWidget( ProfileCiscoSelectorLabel ); + ProfileCiscoSelectorLayout->addWidget( ProfileCiscoSelector ); + + ProfileCiscoOptionsWidget = new ProfileCiscoOptions( ProfileCiscoOptionsFrame ); + + lo->addWidget( ProfileCiscoSelectorWidget ); + lo->addWidget( ProfileCiscoOptionsWidget ); + ProfileCiscoSelector->setEnabled( true ); + connect (ProfileCiscoOptionsWidget->LocalPortCheckbox, SIGNAL(toggled(bool)),this, SLOT(localPortToggled(bool))); + connect (ProfileCiscoOptionsWidget->ApplicationVersionCheckbox, SIGNAL(toggled(bool)),this, SLOT(applicationVersionToggled(bool))); + connect (ProfileCiscoOptionsWidget->PerfectForwardSecurityCheckbox, SIGNAL(toggled(bool)),this, SLOT(perfectForwardSecurityToggled(bool))); + connect (ProfileCiscoOptionsWidget->IkeGroupCheckbox, SIGNAL(toggled(bool)),this, SLOT(IkeGroupToggled(bool))); + connect (ProfileCiscoOptionsWidget->SingleDesCheckbox, SIGNAL(toggled(bool)),this, SLOT(singleDesToggled(bool))); + connect (ProfileCiscoOptionsWidget->EnableDpdIdleTimeoutCheckbox, SIGNAL(toggled(bool)),this, SLOT(dpdToggled(bool))); + + //ProfileCiscoOptionsWidget->PerfectForwardSecrecyCombobox->setEnabled( false ); + ProfileCiscoOptionsWidget->PerfectForwardSecrecyCombobox->clear(); + ProfileCiscoOptionsWidget->PerfectForwardSecrecyCombobox->insertItem( "server" ); + ProfileCiscoOptionsWidget->PerfectForwardSecrecyCombobox->insertItem( "nopfs" ); + ProfileCiscoOptionsWidget->PerfectForwardSecrecyCombobox->insertItem( "dh1" ); + ProfileCiscoOptionsWidget->PerfectForwardSecrecyCombobox->insertItem( "dh2" ); + ProfileCiscoOptionsWidget->PerfectForwardSecrecyCombobox->insertItem( "dh5"); + + //ProfileCiscoOptionsWidget->IkeGroupCombobox->setEnabled( false ); + ProfileCiscoOptionsWidget->IkeGroupCombobox->clear(); + ProfileCiscoOptionsWidget->IkeGroupCombobox->insertItem( "dh1"); + ProfileCiscoOptionsWidget->IkeGroupCombobox->insertItem( "dh2"); + ProfileCiscoOptionsWidget->IkeGroupCombobox->insertItem( "dh5"); + + path.clear(); + path << i18n( "Profile" ) << i18n( "Connection specific" ) << i18n( "Racoon" ); + ProfileRacoonOptionsFrame = addPage( path, i18n( "Racoon" ), BarIcon( "kame", KIcon::SizeSmall ) ); + lo = new QVBoxLayout( ProfileRacoonOptionsFrame ); + lo->setSpacing( KDialog::spacingHint() ); + + QWidget *ProfileRacoonSelectorWidget = new QWidget( ProfileRacoonOptionsFrame ); + QHBoxLayout *ProfileRacoonSelectorLayout = new QHBoxLayout( ProfileRacoonSelectorWidget ); + QLabel *ProfileRacoonSelectorLabel = new QLabel( ProfileRacoonSelectorWidget ); + ProfileRacoonSelectorLabel->setText( i18n( "Profile:" ) ); + ProfileRacoonSelector = new QComboBox( ProfileRacoonSelectorWidget ); + ProfileRacoonSelectorLayout->addWidget( ProfileRacoonSelectorLabel ); + ProfileRacoonSelectorLayout->addWidget( ProfileRacoonSelector ); + + ProfileRacoonOptionsWidget = new ProfileRacoonOptions( ProfileRacoonOptionsFrame ); + ProfileRacoonOptionsWidget->ExchangeModeComboBox->insertItem( "main", 0 ); + ProfileRacoonOptionsWidget->ExchangeModeComboBox->insertItem( "aggressive", 1 ); + ProfileRacoonOptionsWidget->ExchangeModeComboBox->insertItem( "base", 2 ); + ProfileRacoonOptionsWidget->ExchangeModeComboBox->setCurrentItem( 0 ); // main + connect (ProfileRacoonOptionsWidget->PerfectForwardSecurityCheckbox, SIGNAL(toggled(bool)),this, SLOT(perfectForwardSecurityToggled(bool))); + connect (ProfileRacoonOptionsWidget->IkeGroupCheckbox, SIGNAL(toggled(bool)),this, SLOT(IkeGroupToggled(bool))); + + //ProfileRacoonOptionsWidget->PerfectForwardSecrecyCombobox->setEnabled( false ); + ProfileRacoonOptionsWidget->PerfectForwardSecrecyCombobox->clear(); + ProfileRacoonOptionsWidget->PerfectForwardSecrecyCombobox->insertItem( "modp768" ); + ProfileRacoonOptionsWidget->PerfectForwardSecrecyCombobox->insertItem( "modp1024" ); + ProfileRacoonOptionsWidget->PerfectForwardSecrecyCombobox->insertItem( "modp1536" ); + ProfileRacoonOptionsWidget->PerfectForwardSecrecyCombobox->insertItem( "modp2048" ); + ProfileRacoonOptionsWidget->PerfectForwardSecrecyCombobox->insertItem( "modp3072" ); + ProfileRacoonOptionsWidget->PerfectForwardSecrecyCombobox->insertItem( "modp4096" ); + ProfileRacoonOptionsWidget->PerfectForwardSecrecyCombobox->insertItem( "modp6144" ); + ProfileRacoonOptionsWidget->PerfectForwardSecrecyCombobox->insertItem( "modp8192" ); + + ProfileRacoonOptionsWidget->DHGroupComboBox->setEnabled( false ); + ProfileRacoonOptionsWidget->DHGroupComboBox->clear(); + ProfileRacoonOptionsWidget->DHGroupComboBox->insertItem( "modp768" ); + ProfileRacoonOptionsWidget->DHGroupComboBox->insertItem( "modp1024" ); + ProfileRacoonOptionsWidget->DHGroupComboBox->insertItem( "modp1536" ); + ProfileRacoonOptionsWidget->DHGroupComboBox->insertItem( "modp2048" ); + ProfileRacoonOptionsWidget->DHGroupComboBox->insertItem( "modp3072" ); + ProfileRacoonOptionsWidget->DHGroupComboBox->insertItem( "modp4096" ); + ProfileRacoonOptionsWidget->DHGroupComboBox->insertItem( "modp6144" ); + ProfileRacoonOptionsWidget->DHGroupComboBox->insertItem( "modp8192" ); + + lo->addWidget( ProfileRacoonSelectorWidget ); + lo->addWidget( ProfileRacoonOptionsWidget ); + ProfileRacoonSelector->setEnabled( true ); + + path.clear(); + path << i18n( "Profile" ) << i18n( "Connection specific" ) << i18n( "Openswan/strongSwan" ); + ProfileIpsecOptionsFrame = addPage( path, i18n( "Openswan/strongSwan" ), BarIcon( "openswan", KIcon::SizeSmall ) ); + lo = new QVBoxLayout( ProfileIpsecOptionsFrame ); + lo->setSpacing( KDialog::spacingHint() ); + + QWidget *ProfileIpsecSelectorWidget = new QWidget( ProfileIpsecOptionsFrame ); + QHBoxLayout *ProfileIpsecSelectorLayout = new QHBoxLayout( ProfileIpsecSelectorWidget ); + QLabel *ProfileIpsecSelectorLabel = new QLabel( ProfileIpsecSelectorWidget ); + ProfileIpsecSelectorLabel->setText( i18n( "Profile:" ) ); + ProfileIpsecSelector = new QComboBox( ProfileIpsecSelectorWidget ); + ProfileIpsecSelectorLayout->addWidget( ProfileIpsecSelectorLabel ); + ProfileIpsecSelectorLayout->addWidget( ProfileIpsecSelector ); + + ProfileIpsecOptionsWidget = new ProfileIpsecOptions( ProfileIpsecOptionsFrame ); + connect (ProfileIpsecOptionsWidget->PerfectForwardSecurityCheckbox, SIGNAL(toggled(bool)),this, SLOT(perfectForwardSecurityToggled(bool))); + connect (ProfileIpsecOptionsWidget->UseXauthCheckBox, SIGNAL(toggled(bool)),this, SLOT(useXauthToggled(bool))); + + ProfileIpsecOptionsWidget->IpsecVpnModeCombobox->insertItem( "transport" ); + ProfileIpsecOptionsWidget->IpsecVpnModeCombobox->insertItem( "tunnel" ); + + ProfileIpsecOptionsWidget->ExchangeModeComboBox->insertItem( "main", 0 ); + ProfileIpsecOptionsWidget->ExchangeModeComboBox->insertItem( "aggressive", 1 ); + ProfileIpsecOptionsWidget->ExchangeModeComboBox->insertItem( "base", 2 ); + + ProfileIpsecOptionsWidget->PerfectForwardSecrecyCombobox->setEnabled( false ); + ProfileIpsecOptionsWidget->PerfectForwardSecrecyCombobox->clear(); + ProfileIpsecOptionsWidget->PerfectForwardSecrecyCombobox->insertItem( "modp768" ); + ProfileIpsecOptionsWidget->PerfectForwardSecrecyCombobox->insertItem( "modp1024" ); + ProfileIpsecOptionsWidget->PerfectForwardSecrecyCombobox->insertItem( "modp1536" ); + ProfileIpsecOptionsWidget->PerfectForwardSecrecyCombobox->insertItem( "modp2048" ); + ProfileIpsecOptionsWidget->PerfectForwardSecrecyCombobox->insertItem( "modp3072" ); + ProfileIpsecOptionsWidget->PerfectForwardSecrecyCombobox->insertItem( "modp4096" ); + ProfileIpsecOptionsWidget->PerfectForwardSecrecyCombobox->insertItem( "modp6144" ); + ProfileIpsecOptionsWidget->PerfectForwardSecrecyCombobox->insertItem( "modp8192" ); + + lo->addWidget( ProfileIpsecSelectorWidget ); + lo->addWidget( ProfileIpsecOptionsWidget ); + ProfileIpsecSelector->setEnabled( true ); + + path.clear(); + path << i18n( "Profile" ) << i18n( "Connection specific" ) << i18n( "OpenVPN" ); + ProfileOpenvpnOptionsFrame = addPage( path, i18n( "OpenVPN" ), BarIcon( "openvpn", KIcon::SizeSmall ) ); + lo = new QVBoxLayout( ProfileOpenvpnOptionsFrame ); + lo->setSpacing( KDialog::spacingHint() ); + + QWidget *ProfileOpenvpnSelectorWidget = new QWidget( ProfileOpenvpnOptionsFrame ); + QHBoxLayout *ProfileOpenvpnSelectorLayout = new QHBoxLayout( ProfileOpenvpnSelectorWidget ); + QLabel *ProfileOpenvpnSelectorLabel = new QLabel( ProfileOpenvpnSelectorWidget ); + ProfileOpenvpnSelectorLabel->setText( i18n( "Profile:" ) ); + ProfileOpenvpnSelector = new QComboBox( ProfileOpenvpnSelectorWidget ); + ProfileOpenvpnSelectorLayout->addWidget( ProfileOpenvpnSelectorLabel ); + ProfileOpenvpnSelectorLayout->addWidget( ProfileOpenvpnSelector ); + + ProfileOpenvpnOptionsWidget = new ProfileOpenvpnOptions( ProfileOpenvpnOptionsFrame ); + + lo->addWidget( ProfileOpenvpnSelectorWidget ); + lo->addWidget( ProfileOpenvpnOptionsWidget ); + ProfileOpenvpnSelector->setEnabled( true ); + + path.clear(); + path << i18n( "Profile" ) << i18n( "Connection specific" ) << i18n( "PPTP/L2TP" ); + ProfilePptpOptionsFrame = addPage( path, i18n( "PPTP/L2TP" ), BarIcon( "application", KIcon::SizeSmall ) ); + lo = new QVBoxLayout( ProfilePptpOptionsFrame ); + lo->setSpacing( KDialog::spacingHint() ); + + QWidget *ProfilePptpSelectorWidget = new QWidget( ProfilePptpOptionsFrame ); + QHBoxLayout *ProfilePptpSelectorLayout = new QHBoxLayout( ProfilePptpSelectorWidget ); + QLabel *ProfilePptpSelectorLabel = new QLabel( ProfilePptpSelectorWidget ); + ProfilePptpSelectorLabel->setText( i18n( "Profile:" ) ); + ProfilePptpSelector = new QComboBox( ProfilePptpSelectorWidget ); + ProfilePptpSelectorLayout->addWidget( ProfilePptpSelectorLabel ); + ProfilePptpSelectorLayout->addWidget( ProfilePptpSelector ); + + ProfilePptpOptionsWidget = new ProfilePptpOptions( ProfilePptpOptionsFrame ); + + lo->addWidget( ProfilePptpSelectorWidget ); + lo->addWidget( ProfilePptpOptionsWidget ); + ProfilePptpSelector->setEnabled( true ); + + path.clear(); + path << i18n( "Profile" ) << i18n( "Connection specific" ) << i18n( "Vtun" ); + ProfileVtunOptionsFrame = addPage( path, i18n( "Vtun" ), BarIcon( "application", KIcon::SizeSmall ) ); + lo = new QVBoxLayout( ProfileVtunOptionsFrame ); + lo->setSpacing( KDialog::spacingHint() ); + + QWidget *ProfileVtunSelectorWidget = new QWidget( ProfileVtunOptionsFrame ); + QHBoxLayout *ProfileVtunSelectorLayout = new QHBoxLayout( ProfileVtunSelectorWidget ); + QLabel *ProfileVtunSelectorLabel = new QLabel( ProfileVtunSelectorWidget ); + ProfileVtunSelectorLabel->setText( i18n( "Profile:" ) ); + ProfileVtunSelector = new QComboBox( ProfileVtunSelectorWidget ); + ProfileVtunSelectorLayout->addWidget( ProfileVtunSelectorLabel ); + ProfileVtunSelectorLayout->addWidget( ProfileVtunSelector ); + + ProfileVtunOptionsWidget = new ProfileVtunOptions( ProfileVtunOptionsFrame ); + + lo->addWidget( ProfileVtunSelectorWidget ); + lo->addWidget( ProfileVtunOptionsWidget ); + ProfileVtunSelector->setEnabled( true ); + + path.clear(); + path << i18n( "Profile" ) << i18n( "Connection specific" ) << i18n( "SSH" ); + ProfileSshOptionsFrame = addPage( path, i18n( "SSH" ), BarIcon( "openssh", KIcon::SizeSmall ) ); + lo = new QVBoxLayout( ProfileSshOptionsFrame ); + lo->setSpacing( KDialog::spacingHint() ); + + QWidget *ProfileSshSelectorWidget = new QWidget( ProfileSshOptionsFrame ); + QHBoxLayout *ProfileSshSelectorLayout = new QHBoxLayout( ProfileSshSelectorWidget ); + QLabel *ProfileSshSelectorLabel = new QLabel( ProfileSshSelectorWidget ); + ProfileSshSelectorLabel->setText( i18n( "Profile:" ) ); + ProfileSshSelector = new QComboBox( ProfileSshSelectorWidget ); + ProfileSshSelectorLayout->addWidget( ProfileSshSelectorLabel ); + ProfileSshSelectorLayout->addWidget( ProfileSshSelector ); + + ProfileSshOptionsWidget = new ProfileSshOptions( ProfileSshOptionsFrame ); + + lo->addWidget( ProfileSshSelectorWidget ); + lo->addWidget( ProfileSshOptionsWidget ); + ProfileSshSelector->setEnabled( true ); + ProfileSshOptionsWidget->SshKeyComboBox->clear(); + QString Home= QString(getenv("HOME")); + if (!Home.isEmpty()) + { + QDir dir( Home+"/.ssh" ); + QStringList KeyFiles = dir.entryList( "*" ); + + //if (GlobalConfig->KvpncDebugLevel > 2) + //{ + // GlobalConfig->appendLogEntry(i18n("SSH files: %1").arg(KeyFiles.join(",")),GlobalConfig->debug); + //} + + if (KeyFiles.size() > 1) + { + for ( QStringList::Iterator it = KeyFiles.begin(); it != KeyFiles.end(); ++it ) + { + QString item = QString(*it); + if (GlobalConfig->KvpncDebugLevel > 2) + { + GlobalConfig->appendLogEntry(i18n("processing entry: %1").arg(item),GlobalConfig->debug); + } + if (!item.contains (".pub", false) && !item.contains ("authorized_keys", false) && !item.contains ("known_hosts", false) && !item.contains (".", false) && !item.contains ("..", false) && !item.contains ("config", false) ) + { + if (GlobalConfig->KvpncDebugLevel > 2) + { + GlobalConfig->appendLogEntry(i18n("SSH key found: %1").arg(*it),GlobalConfig->debug); + } + ProfileSshOptionsWidget->SshKeyComboBox->insertItem(*it); + } + } + } + } + + + + path.clear(); + path << i18n( "Profile" ) << i18n( "Command Execution" ) << i18n( "Before Connect" ); + ProfileCmdExecBeforeConnectOptionsFrame = addPage( path, i18n( "Before Connect" ), BarIcon( "exec", KIcon::SizeSmall ) ); + lo = new QVBoxLayout( ProfileCmdExecBeforeConnectOptionsFrame ); + lo->setSpacing( KDialog::spacingHint() ); + + QWidget *ProfileCmdExecBeforeConnectSelectorWidget = new QWidget( ProfileCmdExecBeforeConnectOptionsFrame ); + QHBoxLayout *ProfileCmdExecBeforeConnectSelectorLayout = new QHBoxLayout( ProfileCmdExecBeforeConnectSelectorWidget ); + QLabel *ProfileCmdExecBeforeConnectSelectorLabel = new QLabel( ProfileCmdExecBeforeConnectSelectorWidget ); + ProfileCmdExecBeforeConnectSelectorLabel->setText( i18n( "Profile:" ) ); + ProfileCmdExecBeforeConnectSelector = new QComboBox( ProfileCmdExecBeforeConnectSelectorWidget ); + ProfileCmdExecBeforeConnectSelectorLayout->addWidget( ProfileCmdExecBeforeConnectSelectorLabel ); + ProfileCmdExecBeforeConnectSelectorLayout->addWidget( ProfileCmdExecBeforeConnectSelector ); + + ProfileCmdExecBeforeConnectOptionsWidget = new ProfileCmdExecBeforeConnectOptions( ProfileCmdExecBeforeConnectOptionsFrame ); + + lo->addWidget( ProfileCmdExecBeforeConnectSelectorWidget ); + lo->addWidget( ProfileCmdExecBeforeConnectOptionsWidget ); + ProfileCmdExecBeforeConnectSelector->setEnabled( true ); + + path.clear(); + path << i18n( "Profile" ) << i18n( "Command Execution" ) << i18n( "After Connect" ); + ProfileCmdExecAfterConnectOptionsFrame = addPage( path, i18n( "After Connect" ), BarIcon( "exec", KIcon::SizeSmall ) ); + lo = new QVBoxLayout( ProfileCmdExecAfterConnectOptionsFrame ); + lo->setSpacing( KDialog::spacingHint() ); + + QWidget *ProfileCmdExecAfterConnectSelectorWidget = new QWidget( ProfileCmdExecAfterConnectOptionsFrame ); + QHBoxLayout *ProfileCmdExecAfterConnectSelectorLayout = new QHBoxLayout( ProfileCmdExecAfterConnectSelectorWidget ); + QLabel *ProfileCmdExecAfterConnectSelectorLabel = new QLabel( ProfileCmdExecAfterConnectSelectorWidget ); + ProfileCmdExecAfterConnectSelectorLabel->setText( i18n( "Profile:" ) ); + ProfileCmdExecAfterConnectSelector = new QComboBox( ProfileCmdExecAfterConnectSelectorWidget ); + ProfileCmdExecAfterConnectSelectorLayout->addWidget( ProfileCmdExecAfterConnectSelectorLabel ); + ProfileCmdExecAfterConnectSelectorLayout->addWidget( ProfileCmdExecAfterConnectSelector ); + + ProfileCmdExecAfterConnectOptionsWidget = new ProfileCmdExecAfterConnectOptions( ProfileCmdExecAfterConnectOptionsFrame ); + lo->addWidget( ProfileCmdExecAfterConnectSelectorWidget ); + lo->addWidget( ProfileCmdExecAfterConnectOptionsWidget ); + ProfileCmdExecAfterConnectSelector->setEnabled( true ); + + path.clear(); + path << i18n( "Profile" ) << i18n( "Command Execution" ) << i18n( "Before Disconnect" ); + ProfileCmdExecBeforeDisconnectOptionsFrame = addPage( path, i18n( "Before Disconnect" ), BarIcon( "exec", KIcon::SizeSmall ) ); + lo = new QVBoxLayout( ProfileCmdExecBeforeDisconnectOptionsFrame ); + lo->setSpacing( KDialog::spacingHint() ); + + QWidget *ProfileCmdExecBeforeDisconnectSelectorWidget = new QWidget( ProfileCmdExecBeforeDisconnectOptionsFrame ); + QHBoxLayout *ProfileCmdExecBeforeDisconnectSelectorLayout = new QHBoxLayout( ProfileCmdExecBeforeDisconnectSelectorWidget ); + QLabel *ProfileCmdExecBeforeDisconnectSelectorLabel = new QLabel( ProfileCmdExecBeforeDisconnectSelectorWidget ); + ProfileCmdExecBeforeDisconnectSelectorLabel->setText( i18n( "Profile:" ) ); + ProfileCmdExecBeforeDisconnectSelector = new QComboBox( ProfileCmdExecBeforeDisconnectSelectorWidget ); + ProfileCmdExecBeforeDisconnectSelectorLayout->addWidget( ProfileCmdExecBeforeDisconnectSelectorLabel ); + ProfileCmdExecBeforeDisconnectSelectorLayout->addWidget( ProfileCmdExecBeforeDisconnectSelector ); + + ProfileCmdExecBeforeDisconnectOptionsWidget = new ProfileCmdExecBeforeDisconnectOptions( ProfileCmdExecBeforeDisconnectOptionsFrame ); + lo->addWidget( ProfileCmdExecBeforeDisconnectSelectorWidget ); + lo->addWidget( ProfileCmdExecBeforeDisconnectOptionsWidget ); + ProfileCmdExecBeforeDisconnectSelector->setEnabled( true ); + + path.clear(); + path << i18n( "Profile" ) << i18n( "Command Execution" ) << i18n( "After Disconnect" ); + ProfileCmdExecAfterDisconnectOptionsFrame = addPage( path, i18n( "Command Execute After Disconnect" ), BarIcon( "exec", KIcon::SizeSmall ) ); + lo = new QVBoxLayout( ProfileCmdExecAfterDisconnectOptionsFrame ); + lo->setSpacing( KDialog::spacingHint() ); + + QWidget *ProfileCmdExecAfterDisconnectSelectorWidget = new QWidget( ProfileCmdExecAfterDisconnectOptionsFrame ); + QHBoxLayout *ProfileCmdExecAfterDisconnectSelectorLayout = new QHBoxLayout( ProfileCmdExecAfterDisconnectSelectorWidget ); + QLabel *ProfileCmdExecAfterDisconnectSelectorLabel = new QLabel( ProfileCmdExecAfterDisconnectSelectorWidget ); + ProfileCmdExecAfterDisconnectSelectorLabel->setText( i18n( "Profile:" ) ); + ProfileCmdExecAfterDisconnectSelector = new QComboBox( ProfileCmdExecAfterDisconnectSelectorWidget ); + ProfileCmdExecAfterDisconnectSelectorLayout->addWidget( ProfileCmdExecAfterDisconnectSelectorLabel ); + ProfileCmdExecAfterDisconnectSelectorLayout->addWidget( ProfileCmdExecAfterDisconnectSelector ); + + ProfileCmdExecAfterDisconnectOptionsWidget = new ProfileCmdExecAfterDisconnectOptions( ProfileCmdExecAfterDisconnectOptionsFrame ); + lo->addWidget( ProfileCmdExecAfterDisconnectSelectorWidget ); + lo->addWidget( ProfileCmdExecAfterDisconnectOptionsWidget ); + ProfileCmdExecAfterDisconnectSelector->setEnabled( true ); + +// resize(QSize(800,600)); +// setFixedSize(QSize(800,600)); +// adjustSize(); + + if ( !showOnlyProfiles ) + { +// DaemonScrollView->adjustSize(); +// DaemonScrollView->updateContents(); +// ConfigDaemonOptionsWidget->resize(ConfigDaemonOptionsWidget->height(),DaemonScrollView->visibleWidth()-100); + ConfigDaemonOptionsWidget->sizeHint(); + } +// CertScrollView->adjustSize(); +// CertScrollView->updateContents(); +// ProfileCertOptionsWidget->adjustSize(); +// adjustSize(); +// ConfigDaemonOptionsWidget->adjustSize(); + + +// adjustSize(); + // enableButtonApply(false); + + /* connect profile combobox of each profile widget */ + connect( ProfileGeneralSelector, SIGNAL( activated ( const QString& ) ), this, SLOT( profileChanged( const QString& ) ) ); + connect( ProfileNetworkRouteSelector, SIGNAL( activated ( const QString& ) ), this, SLOT( profileChanged( const QString& ) ) ); + connect( ProfileNetworkGeneralSelector, SIGNAL( activated ( const QString& ) ), this, SLOT( profileChanged( const QString& ) ) ); + connect( ProfileNetworkNatSelector, SIGNAL( activated ( const QString& ) ), this, SLOT( profileChanged( const QString& ) ) ); + connect( ProfileNetworkHttpProxySelector, SIGNAL( activated ( const QString& ) ), this, SLOT( profileChanged( const QString& ) ) ); + connect( ProfileNetworkVirtualIpSelector, SIGNAL( activated ( const QString& ) ), this, SLOT( profileChanged( const QString& ) ) ); + connect( ProfileCertSelector, SIGNAL( activated ( const QString& ) ), this, SLOT( profileChanged( const QString& ) ) ); + connect( ProfileSmartcardSelector, SIGNAL( activated ( const QString& ) ), this, SLOT( profileChanged( const QString& ) ) ); + connect( ProfilePskSelector, SIGNAL( activated ( const QString& ) ), this, SLOT( profileChanged( const QString& ) ) ); + connect( ProfileUserSelector, SIGNAL( activated ( const QString& ) ), this, SLOT( profileChanged( const QString& ) ) ); + connect( ProfileOpenvpnSelector, SIGNAL( activated ( const QString& ) ), this, SLOT( profileChanged( const QString& ) ) ); + connect( ProfilePptpSelector, SIGNAL( activated ( const QString& ) ), this, SLOT( profileChanged( const QString& ) ) ); + connect( ProfileRacoonSelector, SIGNAL( activated ( const QString& ) ), this, SLOT( profileChanged( const QString& ) ) ); + connect( ProfileIpsecSelector, SIGNAL( activated ( const QString& ) ), this, SLOT( profileChanged( const QString& ) ) ); + connect( ProfileCiscoSelector, SIGNAL( activated ( const QString& ) ), this, SLOT( profileChanged( const QString& ) ) ); + connect( ProfileVtunSelector, SIGNAL( activated ( const QString& ) ), this, SLOT( profileChanged( const QString& ) ) ); + connect( ProfileSshSelector, SIGNAL( activated ( const QString& ) ), this, SLOT( profileChanged( const QString& ) ) ); + connect( ProfileCmdExecBeforeConnectSelector, SIGNAL( activated ( const QString& ) ), this, SLOT( profileChanged( const QString& ) ) ); + connect( ProfileCmdExecBeforeDisconnectSelector, SIGNAL( activated ( const QString& ) ), this, SLOT( profileChanged( const QString& ) ) ); + connect( ProfileCmdExecAfterConnectSelector, SIGNAL( activated ( const QString& ) ), this, SLOT( profileChanged( const QString& ) ) ); + connect( ProfileCmdExecAfterDisconnectSelector, SIGNAL( activated ( const QString& ) ), this, SLOT( profileChanged( const QString& ) ) ); + + connect( ProfileOpenvpnOptionsWidget->AuthWithUsernameAndPasswordCheckBox, SIGNAL( toggled ( bool ) ), this, SLOT( userAuthToggled( bool ) ) ); + + +// connect( ProfileCertOptionsWidget->UseSpecialServerSmartcardificateCheckBox, SIGNAL (toggled(bool)), SLOT(useSpecialServerSmartcardificateToggled(bool) ) ); + connect( ProfileCertOptionsWidget->AuthTypeComboBox, SIGNAL( activated ( int ) ), this, SLOT( authTypeChanged( int ) ) ); + connect( ProfilePskOptionsWidget->AuthTypeComboBox, SIGNAL( activated ( int ) ), this, SLOT( authTypeChanged( int ) ) ); + + + +// connect ( ProfileGeneralOptionsWidget->NewSessionPushButton , SIGNAL( clicked () ), this, SLOT( newSessionClicked() ) ); + connect ( ProfileGeneralOptionsWidget->SaveSessionPushButton, SIGNAL( clicked () ), this, SLOT( saveSessionClicked() ) ); + connect ( ProfileGeneralOptionsWidget->RenameSessionPushButton, SIGNAL( clicked () ), this, SLOT( renameSessionClicked() ) ); + connect ( ProfileGeneralOptionsWidget->DeleteSessionPushButton, SIGNAL( clicked () ), this, SLOT( deleteSessionClicked() ) ); + connect ( this, SIGNAL( aboutToShowPage( QWidget * ) ), this, SLOT( pageChanged( QWidget * ) ) ); + connect ( this, SIGNAL( applyClicked () ), this, SLOT( saveSessionClicked() ) ); + +} + +void PreferencesDialog::accept() +{ + //MyprofileWidget->saveSessionClicked(); + if ( !showOnlyProfiles ) + { + GlobalConfig->pathToVpnc =ConfigDaemonOptionsWidget->VpncPathInput->url(); + GlobalConfig->pathToRacoon =ConfigDaemonOptionsWidget->RacoonPathInput->url(); + GlobalConfig->pathToPppd =ConfigDaemonOptionsWidget->PppdPathInput->url(); + GlobalConfig->pathToPptp =ConfigDaemonOptionsWidget->PptpPathInput->url(); + GlobalConfig->pathToOpenvpn =ConfigDaemonOptionsWidget->OpenvpnPathInput->url(); + GlobalConfig->pathToIpsec =ConfigDaemonOptionsWidget->FreeswanPathInput->url(); + GlobalConfig->pathToSsh = ConfigDaemonOptionsWidget->SshPathInput->url(); + GlobalConfig->minimizeAfterConnect = ConnectOptionsWidget->checkMinimizeAfterConnectCheck->isChecked(); + GlobalConfig->showDebugConsole = DebugOptionsWidget->showDebugCheck->isChecked(); + GlobalConfig->useSilentQuit = ConnectOptionsWidget->SilentQuitcheckBox->isChecked(); + GlobalConfig->dontQuitOnCloseEvent = GeneralOptionsWidget->DontQuitOnCloseEventCheckBox->isChecked(); + GlobalConfig->useKwallet = GeneralOptionsWidget->useKwalletCheckBox->isChecked(); + GlobalConfig->writeLogFile = DebugOptionsWidget->WriteLogCheck->isChecked(); + GlobalConfig->KvpncDebugLevel = DebugOptionsWidget->spinKvpncDebugLevel->value(); + GlobalConfig->RacoonDebugLevel = ConfigDaemonOptionsWidget->RacoonDebugLevelComboBox->currentText(); + GlobalConfig->VpncDebugLevel =ConfigDaemonOptionsWidget->spinVpncDebugLevel->value(); + GlobalConfig->OpenvpnDebugLevel =ConfigDaemonOptionsWidget->spinOpenvpnDebugLevel->value() + 1; + GlobalConfig->SshDebugLevel =ConfigDaemonOptionsWidget->spinSshDebugLevel->value(); + + GlobalConfig->pathToIptables = HelperProgramOptionsWidget->IptablesPathInput->url(); + GlobalConfig->pathToOpenssl = HelperProgramOptionsWidget->OpenSSLPathInput->url(); + GlobalConfig->pathToKill = HelperProgramOptionsWidget->KillPathInput->url(); + GlobalConfig->pathToKillall = HelperProgramOptionsWidget->KillallPathInput->url(); + GlobalConfig->pathToPing = HelperProgramOptionsWidget->PingPathInput->url(); + GlobalConfig->pathToIp = HelperProgramOptionsWidget->IpPathInput->url(); + GlobalConfig->pathToIfconfig = HelperProgramOptionsWidget->IfconfigPathInput->url(); + GlobalConfig->pathToTail = HelperProgramOptionsWidget->TailPathInput->url(); + GlobalConfig->pathToRoute = HelperProgramOptionsWidget->RoutePathInput->url(); + GlobalConfig->pathToPkcs11Tool = HelperProgramOptionsWidget->Pkcs11ToolPathInput->url(); + GlobalConfig->pathToKsshAskpass = HelperProgramOptionsWidget->KsshaskpassPathInput->url(); + GlobalConfig->pathToGnomeSshAskpass = HelperProgramOptionsWidget->GnomeaskpassPathInput->url(); + GlobalConfig->pathToCiscoCertMgr = HelperProgramOptionsWidget->CiscoCertMgrPathInput->url(); + GlobalConfig->pathToTail = HelperProgramOptionsWidget->TailPathInput->url(); + + + if (ConfigDaemonOptionsWidget->PptpLogLevelComboBox->currentText() == i18n( "low" ) ) + GlobalConfig->PptpLogLevel = 0; + else if (ConfigDaemonOptionsWidget->PptpLogLevelComboBox->currentText() == i18n( "default" ) ) + GlobalConfig->PptpLogLevel = 1; + else if (ConfigDaemonOptionsWidget->PptpLogLevelComboBox->currentText() == i18n( "high" ) ) + GlobalConfig->PptpLogLevel = 2; + + GlobalConfig->enableDebugPppd =ConfigDaemonOptionsWidget->DebugPppdcheckBox->isChecked(); + GlobalConfig->enableDebugPptpd =ConfigDaemonOptionsWidget->DebugPptpdcheckBox->isChecked(); + GlobalConfig->enableDebugL2tpd =ConfigDaemonOptionsWidget->DebugL2tpdCheckBox->isChecked(); + + GlobalConfig->enableDebugXl2tpdtunnel = ConfigDaemonOptionsWidget->EnableDebugXl2tpdtunnelCheckBox->isChecked( ); + GlobalConfig->enableDebugXl2tpdstate = ConfigDaemonOptionsWidget->EnableDebugXl2tpdstateCheckBox ->isChecked( ); + GlobalConfig->enableDebugXl2tpdpacket = ConfigDaemonOptionsWidget->EnableDebugXl2tpdpacketCheckBox->isChecked( ); + GlobalConfig->enableDebugXl2tpdNetwork = ConfigDaemonOptionsWidget->EnableDebugXl2tpdNetworkCheckBox->isChecked( ); + + GlobalConfig->tryConnectTimeout = ProfileCiscoOptionsWidget->PeerTimeoutIntNumInput->value(); + GlobalConfig->programsInPath =ConfigDaemonOptionsWidget->ProgramsInPathcheckBox->isChecked(); + GlobalConfig->holdGeneratedScripts = DebugOptionsWidget->KeepConnectionFilesCheckBox->isChecked(); + GlobalConfig->InfoLogColor = LogOptionsWidget->InfoLogLabel->paletteBackgroundColor (); + GlobalConfig->RemoteLogColor = LogOptionsWidget->RemoteLogLabel->paletteBackgroundColor(); + GlobalConfig->ErrorLogColor = LogOptionsWidget->ErrorLogLabel->paletteBackgroundColor (); + GlobalConfig->SuccessLogColor = LogOptionsWidget->SuccessLogLabel->paletteBackgroundColor (); + GlobalConfig->DebugLogColor = LogOptionsWidget->DebugLogLabel->paletteBackgroundColor (); + GlobalConfig->DebugBackgroundcolor = LogOptionsWidget->BackgroundLogLabel->paletteBackgroundColor (); + GlobalConfig->useColorizedLogOutput = LogOptionsWidget->UseColorizedLogOutputcheckBox->isChecked(); + GlobalConfig->showInterfaceIPinTooltip =ConfigDaemonOptionsWidget->ShowInterfaceIPinTooltipCheckBox->isChecked(); + GlobalConfig->doAutoConnectAtStartup = ConnectOptionsWidget->DoAutoConnectCheckBox->isChecked(); + GlobalConfig->AutoConnectProfile = ConnectOptionsWidget->AutoConnectProfileComboBox->currentText(); + GlobalConfig->LogViewerFontSize = LogOptionsWidget->LogFontSizeSpinBox->value(); + } + + if ( !GlobalConfig->AccountList->isEmpty() ) + { + if (GlobalConfig->currentProfile == 0) + GlobalConfig->currentProfile = GlobalConfig->AccountList->first(); + } + + saveSessionClicked(); + + if ( canAccept ) + QDialog::accept(); +} + +void PreferencesDialog::reject() +{ + if (configChanged) + saveSessionClicked(); + QDialog::reject(); +} + +void PreferencesDialog::slotApply() +{ + saveSessionClicked(); +} + +PreferencesDialog::~PreferencesDialog() +{ + delete ProfileGeneralSelector; + delete ProfileNetworkRouteSelector; + delete ProfileNetworkNatSelector; + delete ProfileNetworkHttpProxySelector; + delete ProfileNetworkVirtualIpSelector; + delete ProfileCertSelector; + delete ProfileSmartcardSelector; + delete ProfilePskSelector; + delete ProfileUserSelector; + delete ProfileOpenvpnSelector; + delete ProfilePptpSelector; + delete ProfileRacoonSelector; + delete ProfileIpsecSelector; + delete ProfileCiscoSelector; + delete ProfileCmdExecBeforeConnectSelector; + delete ProfileCmdExecBeforeDisconnectSelector; + delete ProfileCmdExecAfterConnectSelector; + delete ProfileCmdExecAfterDisconnectSelector; + GlobalConfig->prefDlgOpen = false; +} + +void PreferencesDialog::connectionTypeChanged( int type ) +{ + + + if ( GlobalConfig->KvpncDebugLevel > 1 ) + GlobalConfig->appendLogEntry( i18n( "connectionTypeChanged(): %1" ).arg( QString().setNum( type ) ), GlobalConfig->debug ); + + // KMessageBox::information(0,"connection type changed: "+QString().setNum(type),QString("type set")); + + if ( GlobalConfig->currentProfile == 0 ) + return ; + + GlobalConfig->currentProfile->setConnectionType( ( VpnAccountData::ConnectionType ) ( type ) ); + + ProfileGeneralOptionsWidget->DeleteSessionPushButton->setEnabled ( TRUE ); + ProfileGeneralOptionsWidget->NewSessionPushButton->setEnabled ( TRUE ); + ProfileGeneralOptionsWidget->SaveSessionPushButton->setEnabled ( TRUE ); + + // First we should set a type + // parent->buttonCancel->setEnabled( FALSE ); + // parent->buttonOk->setEnabled( FALSE ); + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::cisco ) + { + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry( "new type: cisco", GlobalConfig->debug ); + + ProfileCiscoOptionsWidget->IDLineEdit->setEnabled( true ); + ProfileCiscoOptionsWidget->LabelID->setEnabled( true ); + + ProfileNetworkGeneralOptionsWidget->NetworkDeviceComboBox->setEnabled( true ); + ProfileNetworkGeneralOptionsWidget->LabelNetworkDevice->setEnabled( true ); + ProfileNetworkGeneralOptionsWidget->RemoteNetAddrLineEdit->setEnabled( false ); + ProfileNetworkGeneralOptionsWidget->RemoteNetMaskComboBox->setEnabled( false ); + + ProfileNetworkNatOptionsWidget->UseUdpCheckbox->setEnabled( true ); + ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setEnabled( true ); + if ( GlobalConfig->currentProfile->getUseUdp() ) + ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setEnabled( true ); + else + ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setEnabled( false ); + + ProfileCiscoOptionsWidget->CiscoNatModeComboBox->setCurrentText(GlobalConfig->currentProfile->getCiscoNatMode()); + + emit authTypeChanged( GlobalConfig->currentProfile->getAuthType() ); + } // vpnc + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ciscoorig ) + { + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry( "new type: cisco (proprietary)", GlobalConfig->debug ); + + ProfileCiscoOptionsWidget->IDLineEdit->setEnabled( true ); + ProfileCiscoOptionsWidget->LabelID->setEnabled( true ); + + + ProfileNetworkGeneralOptionsWidget->NetworkDeviceComboBox->setEnabled( true ); + ProfileNetworkGeneralOptionsWidget->LabelNetworkDevice->setEnabled( true ); + ProfileNetworkGeneralOptionsWidget->RemoteNetAddrLineEdit->setEnabled( false ); + ProfileNetworkGeneralOptionsWidget->RemoteNetMaskComboBox->setEnabled( false ); + + ProfileNetworkNatOptionsWidget->UseUdpCheckbox->setEnabled( true ); + ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setEnabled( true ); + if ( GlobalConfig->currentProfile->getUseUdp() ) + ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setEnabled( true ); + else + ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setEnabled( false ); + ProfileCiscoOptionsWidget->CiscoNatModeComboBox->setEnabled(false); + //ProfileCiscoOptionsWidget->CiscoNatModeComboBox->setCurrentText(GlobalConfig->currentProfile->getCiscoNatMode()); + + emit authTypeChanged( GlobalConfig->currentProfile->getAuthType() ); + } // vpnc (proprietary) + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon ) + { + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry( i18n( "New type: %1" ).arg( "racoon" ), GlobalConfig->debug ); + + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry( i18n( "New type: %1" ).arg( "l2tpd (racoon)" ), GlobalConfig->debug ); + + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan ) + { + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry( i18n( "New type: %1" ).arg( "ipsec (openswan/strongswan)" ), GlobalConfig->debug ); + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry( i18n( "New type: %1" ).arg( "l2tpd (openswan/strongswan)" ), GlobalConfig->debug ); + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::pptp ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry( "new type: pptp", GlobalConfig->debug ); + } // pptp + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::openvpn ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry( i18n( "new type: %1" ).arg( "openvpn" ), GlobalConfig->debug ); + + ProfileNetworkGeneralOptionsWidget->RemoteNetAddrLineEdit->setEnabled( false ); + ProfileNetworkGeneralOptionsWidget->LabelRemoteNetwork->setEnabled( false ); + ProfileNetworkGeneralOptionsWidget->RemoteNetMaskComboBox->setEnabled( false ); + ProfileCiscoOptionsWidget->IDLineEdit->setEnabled( false ); + ProfileCiscoOptionsWidget->LabelID->setEnabled( false ); + // buttonCancel->setEnabled( TRUE ); + // buttonOk->setEnabled( TRUE ); + + ProfileNetworkNatOptionsWidget->UseUdpCheckbox->setEnabled( true ); + ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setEnabled( true ); + if ( GlobalConfig->currentProfile->getUseUdp() ) + ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setEnabled( true ); + else + ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setEnabled( false ); + + emit authTypeChanged( GlobalConfig->currentProfile->getAuthType() ); + } // openvpn + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::vtun ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry( i18n( "new type: %1" ).arg( "Vtun" ), GlobalConfig->debug ); + + ProfileNetworkGeneralOptionsWidget->RemoteNetAddrLineEdit->setEnabled( false ); + ProfileNetworkGeneralOptionsWidget->LabelRemoteNetwork->setEnabled( false ); + ProfileNetworkGeneralOptionsWidget->RemoteNetMaskComboBox->setEnabled( false ); + ProfileCiscoOptionsWidget->IDLineEdit->setEnabled( false ); + ProfileCiscoOptionsWidget->LabelID->setEnabled( false ); + // buttonCancel->setEnabled( TRUE ); + // buttonOk->setEnabled( TRUE ); + +// ProfileNetworkNatOptionsWidget->UseUdpCheckbox->setEnabled( true ); +// ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setEnabled( true ); +// if ( GlobalConfig->currentProfile->getUseUdp() ) +// ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setEnabled( true ); +// else +// ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setEnabled( false ); + + emit authTypeChanged( GlobalConfig->currentProfile->getAuthType() ); + } // vtun + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ssh ) + { + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry( i18n( "new type: %1" ).arg( "SSH" ), GlobalConfig->debug ); + + ProfileNetworkGeneralOptionsWidget->RemoteNetAddrLineEdit->setEnabled( false ); + ProfileNetworkGeneralOptionsWidget->LabelRemoteNetwork->setEnabled( false ); + ProfileNetworkGeneralOptionsWidget->RemoteNetMaskComboBox->setEnabled( false ); + ProfileCiscoOptionsWidget->IDLineEdit->setEnabled( false ); + ProfileCiscoOptionsWidget->LabelID->setEnabled( false ); + // buttonCancel->setEnabled( TRUE ); + // buttonOk->setEnabled( TRUE ); + +// ProfileNetworkNatOptionsWidget->UseUdpCheckbox->setEnabled( true ); +// ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setEnabled( true ); +// if ( GlobalConfig->currentProfile->getUseUdp() ) +// ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setEnabled( true ); +// else +// ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setEnabled( false ); + + emit authTypeChanged( GlobalConfig->currentProfile->getAuthType() ); + } // ssh + // other + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::other ) + { + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry( i18n( "new type: none specified" ), GlobalConfig->debug ); + } + else + { + GlobalConfig->appendLogEntry( i18n( "unknown type" ), GlobalConfig->debug ); + } + + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon || + GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon || + GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan || + GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan) + { + if ( GlobalConfig->currentProfile != 0 ) + { + ProfileCertOptionsWidget->privkeypathURLRequester->setURL( GlobalConfig->currentProfile->getPrivateKey() ); + ProfileCertOptionsWidget->PrivkeyPasswordEdit->setText( GlobalConfig->currentProfile->getPrivateKeyPass() ); + ProfileCertOptionsWidget->SavePrivateKeyPasswordCheckBox->setChecked ( GlobalConfig->currentProfile->getSavePrivateKeyPassword() ); + } + + ProfileNetworkGeneralOptionsWidget->NetworkDeviceComboBox->setEnabled ( true ); + ProfileNetworkGeneralOptionsWidget->LabelNetworkDevice->setEnabled( true ); + + ProfileCiscoOptionsWidget->IDLineEdit->setEnabled( false ); + ProfileCiscoOptionsWidget->LabelID->setEnabled( false ); + + // buttonCancel->setEnabled( TRUE ); + // buttonOk->setEnabled( TRUE ); + + + + + ProfileNetworkNatOptionsWidget->UseUdpCheckbox->setEnabled( true ); + ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setEnabled( true ); + if ( GlobalConfig->currentProfile->getUseUdp() ) + ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setEnabled( true ); + else + ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setEnabled( false ); + + emit authTypeChanged( GlobalConfig->currentProfile->getAuthType() ); + } // racoon/freeswan + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon || GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan) + { + ProfilePptpOptionsWidget->MppeTab->setEnabled(false); + ProfilePptpOptionsWidget->PppTab->setEnabled(false); + } + else + { + ProfilePptpOptionsWidget->MppeTab->setEnabled(true); + ProfilePptpOptionsWidget->PppTab->setEnabled(true); + } +} + +void PreferencesDialog::authTypeChanged( int authtype ) +{ + if ( GlobalConfig->currentProfile == 0 ) + return ; + QComboBox *signalsender = (QComboBox *) QObject::sender (); + VpnAccountData::AuthenticationType oldAuthType = GlobalConfig->currentProfile->getAuthType(); + if (signalsender == ProfileCertOptionsWidget->AuthTypeComboBox) + { + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::cisco) + { + // we need a fix here + if (authtype == 0) + { + authtype = VpnAccountData::psk; + } + else + { + authtype = VpnAccountData::hybrid; + } + } + GlobalConfig->appendLogEntry( i18n( "authtype changed by %1." ).arg( "ProfileCertOptionsWidget" ) , GlobalConfig->debug ); + if ( ProfileCertOptionsWidget->AuthTypeComboBox->currentText() == i18n( "X.509 Certificate" )) + GlobalConfig->currentProfile->setAuthType(VpnAccountData::cert); + else if ( ProfileCertOptionsWidget->AuthTypeComboBox->currentText() == i18n( "Pre Shared Key" )) + GlobalConfig->currentProfile->setAuthType(VpnAccountData::psk); + else if ( ProfileCertOptionsWidget->AuthTypeComboBox->currentText() == i18n( "Hybrid" )) + GlobalConfig->currentProfile->setAuthType(VpnAccountData::hybrid); + ProfilePskOptionsWidget->AuthTypeComboBox->setCurrentText(ProfileCertOptionsWidget->AuthTypeComboBox->currentText()); + } + else + { + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::cisco) + { + // we need a fix here + if (authtype == 0) + { + authtype = VpnAccountData::psk; + } + else + { + authtype = VpnAccountData::hybrid; + } + } + GlobalConfig->appendLogEntry( i18n( "authtype changed by %1." ).arg( "ProfilePskOptionsWidget" ) , GlobalConfig->debug ); + if ( ProfilePskOptionsWidget->AuthTypeComboBox->currentText() == i18n( "X.509 Certificate" )) + GlobalConfig->currentProfile->setAuthType(VpnAccountData::cert); + else if ( ProfilePskOptionsWidget->AuthTypeComboBox->currentText() == i18n( "Pre Shared Key" )) + GlobalConfig->currentProfile->setAuthType(VpnAccountData::psk); + else if ( ProfilePskOptionsWidget->AuthTypeComboBox->currentText() == i18n( "Hybrid" )) + GlobalConfig->currentProfile->setAuthType(VpnAccountData::hybrid); + ProfileCertOptionsWidget->AuthTypeComboBox->setCurrentText(ProfilePskOptionsWidget->AuthTypeComboBox->currentText()); + } + + if ( oldAuthType != GlobalConfig->currentProfile->getAuthType()) + saveSessionClicked(); + ProfilePskOptionsWidget->PskInFileCheckBox->setEnabled( true ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + { + + QString type="unknown"; + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::cert ) + type = "cert"; + else if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::psk ) + type = "psk"; + else if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::hybrid ) + type = "hybrid"; + else + type ="unknown auth"; + + + GlobalConfig->appendLogEntry( i18n( "New authtype: \"%1\"." ).arg( type ) , GlobalConfig->debug ); + } + + ProfilePskOptionsWidget->PskGroupBox->setEnabled( false ); + ProfileCertOptionsWidget->AuthTypeComboBox->setEnabled( false ); + ProfilePskOptionsWidget->AuthTypeComboBox->setEnabled( false ); + ProfileCertOptionsWidget->LabelAuthType->setEnabled( false ); + ProfilePskOptionsWidget->LabelAuthType->setEnabled( false ); + ProfileCertOptionsWidget->CaCertpathURLRequester->setEnabled( false ); + + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::cisco || GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ciscoorig || GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::pptp ) + { + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::cisco ) + { + ProfilePskOptionsWidget->PskGroupBox->setEnabled( true ); + ProfilePskOptionsWidget->PSKLineEdit->setEnabled( true ); + ProfilePskOptionsWidget->LabelPsk->setEnabled( true ); + ProfilePskOptionsWidget->PskInFileCheckBox->setChecked( false ); + ProfilePskOptionsWidget->PskInFileCheckBox->setEnabled( false ); + ProfilePskOptionsWidget->PSKFileURLRequester->setEnabled( false ); + ProfilePskOptionsWidget->LabelPskFile->setEnabled( false ); + + + bool hasHybridSupport = getVpncHasHybridSupport(); + if (hasHybridSupport) + { + ProfileCertOptionsWidget->AuthTypeComboBox->setEnabled( true ); + ProfilePskOptionsWidget->AuthTypeComboBox->setEnabled( true ); + ProfileCertOptionsWidget->LabelAuthType->setEnabled( true ); + ProfilePskOptionsWidget->LabelAuthType->setEnabled( true ); + GlobalConfig->appendLogEntry ( i18n ( "Hybrid support detected, enabling cert options" ),GlobalConfig->debug ); + } + else + { +// ProfileCertOptionsWidget->AuthTypeComboBox->setCurrentText( i18n( "Pre Shared Key" ) ); // PSK + ProfileCertOptionsWidget->AuthTypeComboBox->setEnabled( false ); + ProfilePskOptionsWidget->AuthTypeComboBox->setEnabled( false ); + ProfileCertOptionsWidget->setEnabled (false); + GlobalConfig->appendLogEntry ( i18n ( "Hybrid support not detected, disabling cert options" ),GlobalConfig->debug ); + } + if ( authtype == VpnAccountData::cert || authtype == VpnAccountData::hybrid ) + { + + // certificate + ProfileCertOptionsWidget->setEnabled( true ); + if ( authtype == VpnAccountData::cert) + { + GlobalConfig->appendLogEntry ( i18n ( "Auth type is cert" ),GlobalConfig->debug ); + ProfileCertOptionsWidget->LabelCertificate->setEnabled( true ); + ProfileCertOptionsWidget->x509certURLRequester->setEnabled( true ); + ProfileCertOptionsWidget->x509certComboBox ->setEnabled( true ); + ProfilePskOptionsWidget->PskGroupBox->setEnabled( false ); + ProfilePskOptionsWidget->PSKFileURLRequester->setEnabled( false ); + ProfileCertOptionsWidget->LabelPrivateKeyPath->setEnabled( true ); + } + if ( authtype == VpnAccountData::hybrid) + { + GlobalConfig->appendLogEntry ( i18n ( "Auth type is hybrid" ),GlobalConfig->debug ); + ProfileCertOptionsWidget->LabelCertificate->setEnabled( false ); + ProfileCertOptionsWidget->x509certURLRequester->setEnabled( false ); + ProfileCertOptionsWidget->x509certComboBox ->setEnabled( false ); + } + + ProfileCertOptionsWidget->CaCertpathURLRequester->setEnabled( true ); + ProfileCertOptionsWidget->certpathURLRequester->setEnabled( true ); + ProfileCertOptionsWidget->LabelCaCertificatePath->setEnabled( true ); + ProfileCertOptionsWidget->LabelCertificatePath->setEnabled( true ); + ProfileCertOptionsWidget->privkeypathURLRequester->setEnabled( false ); + ProfileCertOptionsWidget->LabelPrivateKeyPath->setEnabled( false ); + ProfileCertOptionsWidget->privkeypathURLRequester->setEnabled( false ); + ProfileCertOptionsWidget->SavePrivateKeyPasswordCheckBox->setEnabled( true ); + ProfileCertOptionsWidget->PrivkeyPasswordEdit->setEnabled( true ); + + ProfileCertOptionsWidget->ImportCertificatePushButton->setEnabled( false ); + } + if ( authtype == VpnAccountData::psk ) + { + GlobalConfig->appendLogEntry ( i18n ( "Auth type is psk" ),GlobalConfig->debug ); + // psk + ProfilePskOptionsWidget->PskGroupBox->setEnabled( true ); + ProfilePskOptionsWidget->PSKLineEdit->setEnabled( true ); + ProfilePskOptionsWidget->LabelPsk->setEnabled( true ); + ProfilePskOptionsWidget->PskInFileCheckBox->setChecked( false ); + ProfilePskOptionsWidget->PskInFileCheckBox->setEnabled( false ); + ProfilePskOptionsWidget->PSKFileURLRequester->setEnabled( false ); + ProfilePskOptionsWidget->LabelPskFile->setEnabled( false ); + ProfileCertOptionsWidget->CaCertpathComboBox->setEnabled( false ); + ProfileCertOptionsWidget->CaCertpathURLRequester->setEnabled( false ); + + ProfileCertOptionsWidget->LabelPrivateKeyPath->setEnabled( false ); + ProfileCertOptionsWidget->x509certURLRequester->setEnabled( false ); + ProfileCertOptionsWidget->x509certComboBox->setEnabled( false ); + ProfileCertOptionsWidget->LabelCertificate->setEnabled( false ); + ProfileCertOptionsWidget->certpathURLRequester->setEnabled( false ); + ProfileCertOptionsWidget->LabelCaCertificatePath->setEnabled( false ); + ProfileCertOptionsWidget->CaCertpathComboBox->setEnabled( false ); + ProfileCertOptionsWidget->CaCertpathURLRequester->setEnabled( false ); + ProfileCertOptionsWidget->LabelCertificatePath->setEnabled( false ); + ProfileCertOptionsWidget->privkeypathURLRequester->setEnabled( false ); + ProfileCertOptionsWidget->SavePrivateKeyPasswordCheckBox->setEnabled( false ); + ProfileCertOptionsWidget->PrivkeyPasswordEdit->setEnabled( false ); + ProfileCertOptionsWidget->ImportCertificatePushButton->setEnabled( false ); + } + } + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ciscoorig ) + { + ProfileCertOptionsWidget->setEnabled( true ); + ProfileCertOptionsWidget->AuthTypeComboBox->setEnabled( true ); + ProfilePskOptionsWidget->AuthTypeComboBox->setEnabled( true ); + ProfileCertOptionsWidget->LabelAuthType->setEnabled( true ); + ProfilePskOptionsWidget->LabelAuthType->setEnabled( true ); + // cert + if ( authtype == VpnAccountData::cert || authtype == VpnAccountData::hybrid ) + { + // certificate + ProfileCertOptionsWidget->setEnabled( true ); + if ( authtype == VpnAccountData::cert) + { + GlobalConfig->appendLogEntry ( i18n ( "Auth type is cert" ),GlobalConfig->debug ); + ProfileCertOptionsWidget->LabelCertificate->setEnabled( true ); + ProfileCertOptionsWidget->x509certURLRequester->setEnabled( true ); + ProfileCertOptionsWidget->x509certComboBox ->setEnabled( true ); + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "Auth type is hybrid" ),GlobalConfig->debug ); + ProfileCertOptionsWidget->LabelCertificate->setEnabled( false ); + ProfileCertOptionsWidget->x509certURLRequester->setEnabled( false ); + ProfileCertOptionsWidget->x509certComboBox ->setEnabled( false ); + } + ProfileCertOptionsWidget->CaCertpathURLRequester->setEnabled( false ); + ProfileCertOptionsWidget->certpathURLRequester->setEnabled( true ); + ProfileCertOptionsWidget->LabelCaCertificatePath->setEnabled( true ); + ProfileCertOptionsWidget->LabelCertificatePath->setEnabled( true ); + ProfileCertOptionsWidget->privkeypathURLRequester->setEnabled( true ); + ProfileCertOptionsWidget->LabelPrivateKeyPath->setEnabled( true ); + ProfileCertOptionsWidget->privkeypathURLRequester->setEnabled( true ); + ProfileCertOptionsWidget->SavePrivateKeyPasswordCheckBox->setEnabled( true ); + ProfileCertOptionsWidget->PrivkeyPasswordEdit->setEnabled( true ); + + ProfileCertOptionsWidget->ImportCertificatePushButton->setEnabled( false ); + + ProfilePskOptionsWidget->PskGroupBox->setEnabled( false ); + ProfilePskOptionsWidget->PSKFileURLRequester->setEnabled( false ); + ProfileCertOptionsWidget->LabelPrivateKeyPath->setEnabled( true ); + } + + // psk + if ( authtype == VpnAccountData::psk ) + { + // psk + GlobalConfig->appendLogEntry ( i18n ( "Auth type is psk" ),GlobalConfig->debug ); + ProfilePskOptionsWidget->PskGroupBox->setEnabled( true ); + ProfilePskOptionsWidget->PSKLineEdit->setEnabled( true ); + ProfilePskOptionsWidget->LabelPsk->setEnabled( true ); + ProfilePskOptionsWidget->PskInFileCheckBox->setChecked( false ); + ProfilePskOptionsWidget->PskInFileCheckBox->setEnabled( false ); + ProfilePskOptionsWidget->PSKFileURLRequester->setEnabled( false ); + ProfilePskOptionsWidget->LabelPskFile->setEnabled( false ); + ProfileCertOptionsWidget->CaCertpathComboBox->setEnabled( false ); + ProfileCertOptionsWidget->CaCertpathURLRequester->setEnabled( false ); + + ProfileCertOptionsWidget->LabelPrivateKeyPath->setEnabled( false ); + ProfileCertOptionsWidget->x509certURLRequester->setEnabled( false ); + ProfileCertOptionsWidget->x509certComboBox->setEnabled( false ); + ProfileCertOptionsWidget->LabelCertificate->setEnabled( false ); + ProfileCertOptionsWidget->certpathURLRequester->setEnabled( false ); + ProfileCertOptionsWidget->LabelCaCertificatePath->setEnabled( false ); + ProfileCertOptionsWidget->CaCertpathComboBox->setEnabled( false ); + ProfileCertOptionsWidget->CaCertpathURLRequester->setEnabled( false ); + ProfileCertOptionsWidget->LabelCertificatePath->setEnabled( false ); + ProfileCertOptionsWidget->privkeypathURLRequester->setEnabled( false ); + ProfileCertOptionsWidget->SavePrivateKeyPasswordCheckBox->setEnabled( false ); + ProfileCertOptionsWidget->PrivkeyPasswordEdit->setEnabled( false ); + ProfileCertOptionsWidget->ImportCertificatePushButton->setEnabled( false ); + } + } + + } + + // racoon or freeswan + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan || GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan || + GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon || GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { + + ProfileCertOptionsWidget->AuthTypeComboBox->setEnabled( true ); + ProfilePskOptionsWidget->AuthTypeComboBox->setEnabled( true ); + ProfileCertOptionsWidget->LabelAuthType->setEnabled( true ); + ProfilePskOptionsWidget->LabelAuthType->setEnabled( true ); + // cert + if ( authtype == VpnAccountData::cert ) + { + // certificate + ProfileCertOptionsWidget->setEnabled( true ); + ProfileCertOptionsWidget->x509certURLRequester->setEnabled( true ); + ProfileCertOptionsWidget->CaCertpathURLRequester->setEnabled(true); + ProfileCertOptionsWidget->LabelCertificate->setEnabled( true ); + ProfileCertOptionsWidget->certpathURLRequester->setEnabled( true ); + ProfileCertOptionsWidget->LabelCertificatePath->setEnabled( true ); + ProfileCertOptionsWidget->ImportCertificatePushButton->setEnabled( true ); + ProfileCertOptionsWidget->AuthTypeComboBox->setEnabled(true); + ProfilePskOptionsWidget->AuthTypeComboBox->setEnabled(true); + ProfileCertOptionsWidget->PrivkeyPasswordEdit->setEnabled(true); + ProfileCertOptionsWidget->privkeypathURLRequester->setEnabled(true); + ProfileCertOptionsWidget->x509certComboBox->setEnabled(true); + ProfileCertOptionsWidget->CaCertpathURLRequester->setEnabled(true); + + ProfilePskOptionsWidget->PskGroupBox->setEnabled( false ); + ProfilePskOptionsWidget->PSKLineEdit->setEnabled( false ); + ProfilePskOptionsWidget->LabelPsk->setEnabled( false ); + + + + } + + // psk + if ( authtype == VpnAccountData::psk ) + { + // psk + ProfilePskOptionsWidget->PskGroupBox->setEnabled( true ); + ProfilePskOptionsWidget->PSKLineEdit->setEnabled( true ); + ProfilePskOptionsWidget->LabelPsk->setEnabled( true ); + + ProfileCertOptionsWidget->x509certURLRequester->setEnabled( false ); + ProfileCertOptionsWidget->CaCertpathURLRequester->setEnabled(false); + ProfileCertOptionsWidget->LabelCertificate->setEnabled( false ); + + ProfileCertOptionsWidget->certpathURLRequester->setEnabled( false ); + ProfileCertOptionsWidget->LabelCertificatePath->setEnabled( false ); + ProfileCertOptionsWidget->PrivkeyPasswordEdit->setEnabled(false); + ProfileCertOptionsWidget->privkeypathURLRequester->setEnabled(false); + ProfileCertOptionsWidget->x509certComboBox->setEnabled(false); + ProfileCertOptionsWidget->CaCertpathURLRequester->setEnabled(false); + + ProfileCertOptionsWidget->ImportCertificatePushButton->setEnabled( false ); + ProfileCertOptionsWidget->AuthTypeComboBox->setEnabled(true); + ProfilePskOptionsWidget->AuthTypeComboBox->setEnabled(true); + } + + if (GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon || GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon) + { + if (GlobalConfig->currentProfile->getAuthType() == VpnAccountData::hybrid) + { + ProfileCertOptionsWidget->setEnabled(true); + ProfileCertOptionsWidget->x509certComboBox->setEnabled(false); + ProfileCertOptionsWidget->x509certURLRequester->setEnabled(false); + ProfileCertOptionsWidget->CaCertpathURLRequester->setEnabled(true); + ProfileCertOptionsWidget->CaCertpathURLRequester->setURL(GlobalConfig->currentProfile->getCaCertificate()); + ProfileCertOptionsWidget->certpathURLRequester->setURL( GlobalConfig->currentProfile->getCertPath() ); + ProfileCertOptionsWidget->VerifyCaCertCheckBox->setChecked(GlobalConfig->currentProfile->getVerifyCaCert()); + ProfileCertOptionsWidget->PrivkeyPasswordEdit->setText(GlobalConfig->currentProfile->getPrivateKeyPass()); + ProfileCertOptionsWidget->SavePrivateKeyPasswordCheckBox->setChecked(GlobalConfig->currentProfile->getSavePrivateKeyPassword()); + ProfileCertOptionsWidget->LabelCertificate->setEnabled(false); + ProfileCertOptionsWidget->LabelPrivateKeyPath->setEnabled(false); + ProfileCertOptionsWidget->LabelPrivateKeyPassword->setEnabled(false); + ProfileCertOptionsWidget->SpecialServerCertificateURLRequester->setEnabled(false); + ProfileCertOptionsWidget->PrivkeyPasswordEdit->setEnabled(false); + ProfileCertOptionsWidget->SavePrivateKeyPasswordCheckBox->setEnabled(false); + ProfileCertOptionsWidget->UseSpecialServerCertificateCheckBox->setEnabled(false); + ProfileCertOptionsWidget->privkeypathURLRequester->setEnabled(false); + ProfilePskOptionsWidget->setEnabled(false); + } + } + + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::openvpn ) + { + + ProfileCertOptionsWidget->AuthTypeComboBox->setEnabled( true ); + ProfilePskOptionsWidget->AuthTypeComboBox->setEnabled( true ); + ProfileCertOptionsWidget->LabelAuthType->setEnabled( true ); + ProfilePskOptionsWidget->LabelAuthType->setEnabled( true ); + // cert + if ( authtype == VpnAccountData::cert ) + { + // certificate + ProfileCertOptionsWidget->x509certURLRequester->setEnabled( true ); + ProfileCertOptionsWidget->CaCertpathURLRequester->setEnabled( true ); + ProfileCertOptionsWidget->LabelCertificate->setEnabled( true ); + + ProfileCertOptionsWidget->certpathURLRequester->setEnabled( true ); + ProfileCertOptionsWidget->LabelCertificatePath->setEnabled( true ); + ProfileCertOptionsWidget->privkeypathURLRequester->setEnabled( true ); + ProfileCertOptionsWidget->LabelPrivateKeyPath->setEnabled( true ); + + ProfileCertOptionsWidget->ImportCertificatePushButton->setEnabled( true ); + + ProfilePskOptionsWidget->PskGroupBox->setEnabled( false ); + ProfilePskOptionsWidget->PSKFileURLRequester->setEnabled( false ); + ProfileCertOptionsWidget->LabelPrivateKeyPath->setEnabled( true ); + ProfileCertOptionsWidget->PrivkeyPasswordEdit->setEnabled(true); + ProfileCertOptionsWidget->privkeypathURLRequester->setEnabled(true); + ProfileCertOptionsWidget->x509certComboBox->setEnabled(true); + ProfileCertOptionsWidget->CaCertpathURLRequester->setEnabled(true); + } + + // psk + if ( authtype == VpnAccountData::psk ) + { + // psk + ProfilePskOptionsWidget->PskGroupBox->setEnabled( true ); + ProfilePskOptionsWidget->PSKFileURLRequester->setEnabled( true ); + ProfilePskOptionsWidget->PSKLineEdit->setEnabled( true ); + ProfilePskOptionsWidget->LabelPsk->setEnabled( true ); + + ProfileCertOptionsWidget->LabelPrivateKeyPath->setEnabled( false ); + ProfileCertOptionsWidget->x509certURLRequester->setEnabled( false ); + ProfileCertOptionsWidget->LabelCertificate->setEnabled( false ); + + ProfileCertOptionsWidget->certpathURLRequester->setEnabled( false ); + ProfileCertOptionsWidget->LabelCertificatePath->setEnabled( false ); + ProfileCertOptionsWidget->ImportCertificatePushButton->setEnabled( false ); + ProfileCertOptionsWidget->PrivkeyPasswordEdit->setEnabled(false); + ProfileCertOptionsWidget->privkeypathURLRequester->setEnabled(false); + ProfileCertOptionsWidget->x509certComboBox->setEnabled(false); + ProfileCertOptionsWidget->CaCertpathURLRequester->setEnabled(false); + } + + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::vtun ) + { + //TODO + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ssh ) + { + //TODO + } +} + +void PreferencesDialog::profileChanged( const QString& itemtext ) +{ + + if ( !GlobalConfig->AccountList->isEmpty() && !itemtext.isEmpty() ) + { + + // KMessageBox::information(0,"item clicked",Name); + // profile data + VpnAccountData * it; + for ( it = GlobalConfig->AccountList->first(); it; it = GlobalConfig->AccountList->next() ) + { + if ( it->getName() == itemtext ) + { + GlobalConfig->currentProfile = it; + break; + } + } + + if (GlobalConfig->currentProfile == 0) + return; + + + if ( it == 0 ) + { + ProfileGeneralOptionsWidget->RenameSessionPushButton->setEnabled( false ); + ProfileGeneralOptionsWidget->DeleteSessionPushButton->setEnabled( false ); + ProfileGeneralOptionsWidget->SaveSessionPushButton->setEnabled( false ); + return ; + } + else + { + ProfileGeneralOptionsWidget->DeleteSessionPushButton->setEnabled( true ); + ProfileGeneralOptionsWidget->SaveSessionPushButton->setEnabled( true ); + } + + QString Name = itemtext; + lastProfileName = Name; + + ProfileGeneralOptionsWidget->setEnabled( true ); + ProfileNetworkRouteOptionsWidget->setEnabled( true ); + ProfileNetworkNatOptionsWidget->setEnabled( true ); + ProfileNetworkVirtualIpOptionsWidget->setEnabled( true ); + ProfileCertOptionsWidget->setEnabled( true ); + ProfilePskOptionsWidget->setEnabled( true ); + ProfileUserOptionsWidget->setEnabled( true ); + ProfileOpenvpnOptionsWidget->setEnabled( true ); + ProfilePptpOptionsWidget->setEnabled( true ); + ProfileRacoonOptionsWidget->setEnabled( true ); + ProfileIpsecOptionsWidget->setEnabled( true ); + ProfileCiscoOptionsWidget->setEnabled( true ); + ProfileCmdExecBeforeConnectOptionsWidget->setEnabled( true ); + ProfileCmdExecBeforeDisconnectOptionsWidget->setEnabled( true ); + ProfileCmdExecAfterConnectOptionsWidget->setEnabled( true ); + ProfileCmdExecAfterDisconnectOptionsWidget->setEnabled( true ); + + ProfileNetworkGeneralOptionsWidget->RemoteNetAddrLineEdit->setEnabled( false ); + ProfileNetworkGeneralOptionsWidget->LabelRemoteNetwork->setEnabled( false ); + ProfileNetworkGeneralOptionsWidget->RemoteNetMaskComboBox->setEnabled( false ); + ProfileNetworkGeneralOptionsWidget->NetworkDeviceComboBox->setEnabled( false ); + ProfileNetworkGeneralOptionsWidget->RemoteNetDividetextLabel->setEnabled( false ); + ProfileNetworkGeneralOptionsWidget->LabelNetworkDevice->setEnabled( false ); + ProfileSmartcardOptionsWidget->UseSmartcardCheckBox->setEnabled( false ); + ProfileNetworkVirtualIpOptionsWidget->SourceIpgroupBox->show(); + + ProfileGeneralSelector->setCurrentText( lastProfileName ); + ProfileNetworkRouteSelector->setCurrentText( lastProfileName ); + ProfileNetworkNatSelector->setCurrentText( lastProfileName ); + ProfileNetworkHttpProxySelector->setCurrentText( lastProfileName ); + ProfileNetworkVirtualIpSelector->setCurrentText( lastProfileName ); + ProfileCertSelector->setCurrentText( lastProfileName ); + ProfileSmartcardSelector->setCurrentText( lastProfileName ); + ProfilePskSelector->setCurrentText( lastProfileName ); + ProfileUserSelector->setCurrentText( lastProfileName ); + ProfileOpenvpnSelector->setCurrentText( lastProfileName ); + ProfilePptpSelector->setCurrentText( lastProfileName ); + ProfileVtunSelector->setCurrentText( lastProfileName ); + ProfileSshSelector->setCurrentText( lastProfileName ); + ProfileRacoonSelector->setCurrentText( lastProfileName ); + ProfileIpsecSelector->setCurrentText( lastProfileName ); + ProfileCiscoSelector->setCurrentText( lastProfileName ); + ProfileCmdExecBeforeConnectSelector->setCurrentText( lastProfileName ); + ProfileCmdExecBeforeDisconnectSelector->setCurrentText( lastProfileName ); + ProfileCmdExecAfterConnectSelector->setCurrentText( lastProfileName ); + ProfileCmdExecAfterDisconnectSelector->setCurrentText( lastProfileName ); + + if ( GlobalConfig->KvpncDebugLevel > 0 ) + GlobalConfig->appendLogEntry( i18n( "New profile: %1" ).arg( Name ), GlobalConfig->debug ); + + profileHasChanged=true; + NewProfileName = Name; + + ProfileCertOptionsWidget->x509certURLRequester->clear(); + ProfileCertOptionsWidget->certpathURLRequester->clear(); + ProfileUserOptionsWidget->UsernameLineEdit->clear(); + ProfilePskOptionsWidget->PSKLineEdit->clear(); + ProfileNetworkGeneralOptionsWidget->RemoteNetAddrLineEdit->clear(); + ProfileGeneralOptionsWidget->gatewayLineEdit->clear(); + ProfileNetworkRouteOptionsWidget->NetworkListView->clear(); + ProfileCertOptionsWidget->SpecialServerCertificateURLRequester->clear(); + + ProfilePskOptionsWidget->CheckSavePsk->setChecked( false ); + ProfileUserOptionsWidget->CheckUserPass->setChecked( false ); + ProfileCiscoOptionsWidget->IDLineEdit->clear(); + ProfileUserOptionsWidget->UsernameLineEdit->clear(); + ProfileUserOptionsWidget->PasswordEdit->clear(); + ProfileCmdExecBeforeConnectOptionsWidget->CmdBeforeConnectTextEdit->setEnabled( false ); + ProfileCmdExecAfterConnectOptionsWidget->CmdAfterConnectTextEdit->setEnabled( false ); + ProfileCmdExecBeforeDisconnectOptionsWidget->CmdBeforeDisconnectTextEdit->setEnabled( false ); + ProfileCmdExecAfterDisconnectOptionsWidget->CmdAfterDisconnectTextEdit->setEnabled( false ); + ProfileCmdExecBeforeConnectOptionsWidget->ExcuteCmdBeforeConnectCheckBox->setChecked( false ); + ProfileCmdExecAfterConnectOptionsWidget->ExcuteCmdAfterConnectCheckBox->setChecked( false ); + ProfileCmdExecBeforeDisconnectOptionsWidget->ExcuteCmdBeforeDisconnectCheckBox->setChecked( false ); + ProfileCmdExecAfterDisconnectOptionsWidget->ExcuteCmdAfterDisconnectCheckBox->setChecked( false ); + ProfileNetworkVirtualIpOptionsWidget->UseVirtualIPCheckBox->setChecked( false ); + ProfileCertOptionsWidget->UseSpecialServerCertificateCheckBox->setChecked( false ); + + ProfilePptpOptionsWidget->RequireMppeCheckbox->setChecked( false ); + ProfilePptpOptionsWidget->Refuse128BitEncryptionCheckbox->setChecked( false ); + ProfilePptpOptionsWidget->Refuse40BitEncryptionCheckbox->setChecked( false ); + ProfilePptpOptionsWidget->UseNoMPPECompressionCheckbox->setChecked( false ); + ProfilePptpOptionsWidget->DnsServerCheckbox->setChecked( false ); + ProfilePptpOptionsWidget->DnsServerLineedit->clear(); + ProfilePptpOptionsWidget->AllowStatefulModeCheckbox->setChecked( false ); + ProfilePptpOptionsWidget->UseNoBsdCompCheckbox->setChecked( false ); + ProfilePptpOptionsWidget->UseNoDeflateCheckbox->setChecked( false ); + ProfileNetworkGeneralOptionsWidget->MtuSpinbox->setValue( 1500 ); + ProfileNetworkGeneralOptionsWidget->MruSpinbox->setValue( 1500 ); + ProfileNetworkGeneralOptionsWidget->MtuCheckbox->setChecked( false ); + ProfileNetworkGeneralOptionsWidget->MruCheckbox->setChecked( false ); + ProfilePptpOptionsWidget->DisableCcpCheckbox->setChecked( false ); + + ProfileNetworkVirtualIpOptionsWidget->setEnabled( false ); + ProfileVtunOptionsWidget->setEnabled( false ); + + ProfileNetworkGeneralOptionsWidget->TunnelDeviceTypeComboBox->setEnabled(false); + ProfileNetworkGeneralOptionsWidget->TunnelDeviceTypeLabel->setEnabled(false); + ProfileNetworkGeneralOptionsWidget->MtuCheckbox->setEnabled( false ); + ProfileNetworkGeneralOptionsWidget->MruCheckbox->setEnabled( false ); + + ProfileNetworkGeneralOptionsWidget->RemoteNetMaskComboBox->setCurrentText( "24" ); + ProfileGeneralOptionsWidget->DescriptionLineEdit->setText( it->getDescription() ); + ProfileGeneralOptionsWidget->gatewayLineEdit->setText( it->getGateway() ); + + + if (GlobalConfig->currentProfile->getTunnelDeviceType() == QString("tap")) + ProfileNetworkGeneralOptionsWidget->TunnelDeviceTypeComboBox->setCurrentItem(1); + else + ProfileNetworkGeneralOptionsWidget->TunnelDeviceTypeComboBox->setCurrentItem(0); + + + // AdvancedSettingsPushButton->setEnabled( false ); + if ( ( it->getNetworkDevice() ).isEmpty() ) + { + ProfileNetworkGeneralOptionsWidget->NetworkDeviceComboBox->setCurrentText( "default" ); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( i18n( "profile \"%1\": no network device defined, using \"default\"." ).arg( it->getName() ), GlobalConfig->debug ); + } + else + { + ProfileNetworkGeneralOptionsWidget->NetworkDeviceComboBox->setCurrentText( it->getNetworkDevice() ); + + if ( GlobalConfig->KvpncDebugLevel > 2 ) + GlobalConfig->appendLogEntry( i18n( "profile \"%1\": network device defined, using \"%2\"." ).arg( it->getName() ).arg( it->getNetworkDevice() ), GlobalConfig->debug ); + } + + ProfileGeneralOptionsWidget->ConnectionTypeComboBox->setCurrentItem( it->getConnectionType() ); + // KMessageBox::information(0,"profilechanged() new conntype: "+QString().setNum(it->getConnectionType()),QString("type set")); + + ProfileGeneralOptionsWidget->gatewayLineEdit->setText( it->getGateway() ); + + ProfilePskOptionsWidget->PSKLineEdit->setText( it->getPreSharedKey() ); + ProfilePskOptionsWidget->PSKFileURLRequester->setURL(it->getPreSharedKeyFile() ); + + ProfileCertOptionsWidget->UseMailAddressAsIdentifierCheckBox->setChecked( it->getUseMailAddressAsIdentifier() ); + + ProfileNetworkGeneralOptionsWidget->PingIPLineEdit->setText( it->getPingHostIP() ); + ProfileNetworkGeneralOptionsWidget->PingCheckBox ->setChecked( it->getDoPingIP() ); + + ProfileUserOptionsWidget->UsernameLineEdit->setText( it->getUserName() ); + ProfileUserOptionsWidget->PasswordEdit->setText( it->getUserPassword() ); + ProfileUserOptionsWidget->CheckUserPass->setChecked( it->getSaveUserPassword() ); + + if ( it->getUseUdp() ) + ProfileNetworkNatOptionsWidget->UseUdpCheckbox->setChecked( true ); + else + ProfileNetworkNatOptionsWidget->UseUdpCheckbox->setChecked( false ); + + if ( it->getUseNat() ) + ProfileNetworkNatOptionsWidget->UseNatCheckbox->setChecked( true ); + else + ProfileNetworkNatOptionsWidget->UseNatCheckbox->setChecked( false ); + + + ProfileNetworkNatOptionsWidget->UdpPortSpinbox->setValue( it->getUdpPort() ); + if ( it->getUseUdpPort() ) + ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setChecked( true ); + else + ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setChecked( false ); + + ProfileNetworkNatOptionsWidget->UseUdpCheckbox->setEnabled( true ); + ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setEnabled( true ); + if ( it->getUseUdp() ) + ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setEnabled( true ); + else + ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setEnabled( false ); + + if ( it->getConnectionType() == VpnAccountData::openvpn ) + connect ( ProfileNetworkNatOptionsWidget->UseUdpCheckbox, SIGNAL( toggled( bool ) ), this, SLOT( useUdpToggled( bool ) ) ); + else + disconnect ( ProfileNetworkNatOptionsWidget->UseUdpCheckbox, SIGNAL( toggled( bool ) ), this, SLOT( useUdpToggled( bool ) ) ); + + + ProfileNetworkGeneralOptionsWidget->MtuCheckbox->setChecked( it->getUseMtu() ); + ProfileNetworkGeneralOptionsWidget->MtuSpinbox->setValue( it->getMtu() ); + ProfileNetworkGeneralOptionsWidget->MruCheckbox->setChecked( it->getUseMru() ); + ProfileNetworkGeneralOptionsWidget->MruSpinbox->setValue( it->getMru() ); + ProfileNetworkGeneralOptionsWidget->FixPathMtuDiscoveryProblemCheckBox->setChecked(it->getFixPathMtuDiscoveryProblem()); + + if ( it->getConnectionType() == VpnAccountData::cisco || + it->getConnectionType() == VpnAccountData::pptp || + it->getConnectionType() == VpnAccountData::freeswan || + it->getConnectionType() == VpnAccountData::l2tpd_freeswan || + it->getConnectionType() == VpnAccountData::openvpn) + { + ProfileNetworkGeneralOptionsWidget->MtuCheckbox->setEnabled( true ); + ProfileNetworkGeneralOptionsWidget->MruCheckbox->setEnabled( true ); + + if ( GlobalConfig->currentProfile->getUseMtu() ) + ProfileNetworkGeneralOptionsWidget->MtuSpinbox->setEnabled( true ); + else + ProfileNetworkGeneralOptionsWidget->MtuSpinbox->setEnabled( false ); + + if ( GlobalConfig->currentProfile->getUseMru() ) + ProfileNetworkGeneralOptionsWidget->MruSpinbox->setEnabled( true ); + else + ProfileNetworkGeneralOptionsWidget->MruSpinbox->setEnabled( false ); + } + + ProfileNetworkGeneralOptionsWidget->UseReconnectDelayCheckBox->setChecked( it->getUseReconnectDelay() ); + ProfileNetworkGeneralOptionsWidget->ReconnectDelayNumInput->setEnabled( it->getUseReconnectDelay() ); + ProfileNetworkGeneralOptionsWidget->ReconnectDelayNumInput->setValue( it->getReconnectDelay() ); + + if ( it->getConnectionType() == VpnAccountData::ConnectionType( VpnAccountData::l2tpd_racoon ) || it->getConnectionType() == VpnAccountData::ConnectionType( VpnAccountData::racoon ) || it->getConnectionType() == VpnAccountData::ConnectionType( VpnAccountData::freeswan ) || it->getConnectionType() == VpnAccountData::ConnectionType( VpnAccountData::l2tpd_freeswan ) || it->getConnectionType() == VpnAccountData::ConnectionType( VpnAccountData::openvpn ) || it->getConnectionType() == VpnAccountData::ConnectionType( VpnAccountData::ciscoorig )) + { + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::cert) + { + + if (GlobalConfig->currentProfile->getUseSmartcard() && ProfileSmartcardOptionsWidget->UseSmartcardCheckBox->isEnabled() ) + { + ProfileCertOptionsWidget->x509certURLRequester->setEnabled(false); + ProfileCertOptionsWidget->PrivkeyPasswordEdit->setEnabled(false); + ProfileCertOptionsWidget->SavePrivateKeyPasswordCheckBox->setEnabled(false); + ProfileCertOptionsWidget->privkeypathURLRequester->setEnabled(false); + ProfileCertOptionsWidget->LabelCertificate->setEnabled(false); + ProfileCertOptionsWidget->LabelPrivateKeyPath->setEnabled(false); + ProfileCertOptionsWidget->CaCertpathURLRequester->setEnabled(false); + } + else + { + ProfileCertOptionsWidget->x509certURLRequester->setEnabled(true); + ProfileCertOptionsWidget->PrivkeyPasswordEdit->setEnabled(true); + ProfileCertOptionsWidget->SavePrivateKeyPasswordCheckBox->setEnabled(true); + ProfileCertOptionsWidget->privkeypathURLRequester->setEnabled(true); + ProfileCertOptionsWidget->LabelCertificate->setEnabled(true); + ProfileCertOptionsWidget->LabelPrivateKeyPath->setEnabled(true); + ProfileCertOptionsWidget->CaCertpathURLRequester->setEnabled(true); + } + } + } + + ProfileCertOptionsWidget->LabelPrivateKeyPassword->setText(i18n("Private key passphrase:")); + ProfileCertOptionsWidget->LabelCertificate->setText(i18n("Certificate:")); + ProfileCertOptionsWidget->x509certURLRequester->show(); + ProfileCertOptionsWidget->x509certURLRequester->sizeHint(); + ProfileCertOptionsWidget->x509certComboBox->hide(); + ProfileCertOptionsWidget->UseCiscoCertStoreCheckBox->hide(); + ProfileCertOptionsWidget->VerifyCaCertCheckBox->setEnabled(false); + ProfileCertOptionsWidget->setEnabled (true); + + ProfileCertOptionsWidget->AuthTypeComboBox->clear(); + ProfilePskOptionsWidget->AuthTypeComboBox->clear(); + + ProfileUserOptionsWidget->AskUserPasswordOnEachConnectCheckBox->setChecked(it->getAskUserPasswordOnEachConnect()); + // FIXME: implement in all types + if (it->getConnectionType() == VpnAccountData::cisco || it->getConnectionType() == VpnAccountData::ciscoorig || it->getConnectionType() == VpnAccountData::l2tpd_racoon || it->getConnectionType() == VpnAccountData::l2tpd_freeswan|| it->getConnectionType() == VpnAccountData::pptp || it->getConnectionType() == VpnAccountData::openvpn || it->getConnectionType() == VpnAccountData::vtun || it->getConnectionType() == VpnAccountData::ssh) + { + ProfileUserOptionsWidget->AskUserPasswordOnEachConnectCheckBox->setEnabled(true); + } + else + ProfileUserOptionsWidget->AskUserPasswordOnEachConnectCheckBox->setEnabled(false); + + if (it->getConnectionType() == VpnAccountData::freeswan || it->getConnectionType() == VpnAccountData::l2tpd_freeswan || it->getConnectionType() == VpnAccountData::pptp || it->getConnectionType() == VpnAccountData::openvpn || GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::vtun) + { + ProfileCertOptionsWidget->AuthTypeComboBox->insertItem( i18n( "X.509 Certificate" ) ); + ProfileCertOptionsWidget->AuthTypeComboBox->insertItem( i18n( "Pre Shared Key" ) ); + ProfilePskOptionsWidget->AuthTypeComboBox->insertItem( i18n( "X.509 Certificate" ) ); + ProfilePskOptionsWidget->AuthTypeComboBox->insertItem( i18n( "Pre Shared Key" ) ); + } + + ProfileCertOptionsWidget->UseMailAddressAsIdentifierCheckBox->show(); + ProfileCertOptionsWidget->UseSpecialServerCertificateCheckBox->show(); + + ProfileCertOptionsWidget->LabelAuthType->setEnabled( true ); + ProfilePskOptionsWidget->LabelAuthType->setEnabled( true ); + + /* connection specific */ + if ( it->getConnectionType() == VpnAccountData::cisco || it->getConnectionType() == VpnAccountData::ciscoorig ) + { + bool vpncHasHybridSupport = false; + ProfilePskOptionsWidget->CheckSavePsk->setChecked( it->getSavePsk() ); + ProfileUserOptionsWidget->CheckUserPass->setChecked ( it->getSaveUserPassword() ); + ProfileCiscoOptionsWidget->IDLineEdit->setText( it->getID() ); + ProfileUserOptionsWidget->UsernameLineEdit->setText ( it->getUserName() ); + ProfilePskOptionsWidget->PSKLineEdit->setText( it->getPreSharedKey() ); + ProfileUserOptionsWidget->PasswordEdit->setText ( it->getUserPassword() ); + ProfileUserOptionsWidget->DontSaveUsernameCheckBox->setChecked(it->getDontSaveUsername() ); + ProfileUserOptionsWidget->HideGroupPasswordInAccountDataDialogCheckBox->show(); + ProfileUserOptionsWidget->HideGroupPasswordInAccountDataDialogCheckBox->setChecked(it->getHideGroupPasswordInAccountDataDialog()); + + if ( it->getAuthType() == VpnAccountData::cert ) + { +// ProfileCertOptionsWidget->PrivkeyPasswordEdit->setEnabled(true); +// ProfileCertOptionsWidget->privkeypathURLRequester->setEnabled(true); +// ProfileCertOptionsWidget->x509certComboBox->setEnabled(true); +// ProfileCertOptionsWidget->CaCertpathURLRequester->setEnabled(true); + ProfileCertOptionsWidget->setEnabled(true); + ProfileCertOptionsWidget->x509certURLRequester->setURL( it->getX509Certificate() ); + + } + if ( it->getAuthType() == VpnAccountData::psk || it->getAuthType() == VpnAccountData::hybrid ) + { + ProfilePskOptionsWidget->PSKLineEdit->setText( it->getPreSharedKey() ); + ProfilePskOptionsWidget->CheckSavePsk->setChecked( it->getSavePsk() ); + ProfilePskOptionsWidget->PskGroupBox->setEnabled( true ); + ProfileCiscoOptionsWidget->IDLineEdit->setEnabled( true ); + ProfileCiscoOptionsWidget->LabelID->setEnabled( true ); + ProfileCiscoOptionsWidget->AllowEmptyGroupPasswordCheckBox->setChecked ( it->getAllowEmptyGroupPassword() ); + +// ProfileCertOptionsWidget->PrivkeyPasswordEdit->setEnabled(false); +// ProfileCertOptionsWidget->privkeypathURLRequester->setEnabled(false); +// ProfileCertOptionsWidget->x509certComboBox->setEnabled(false); +// ProfileCertOptionsWidget->CaCertpathURLRequester->setEnabled(false); + } + + if ( it->getConnectionType() == VpnAccountData::ciscoorig) + { + ProfileCertOptionsWidget->AuthTypeComboBox->insertItem( i18n( "X.509 Certificate" ) ); + ProfileCertOptionsWidget->AuthTypeComboBox->insertItem( i18n( "Pre Shared Key" ) ); + ProfilePskOptionsWidget->AuthTypeComboBox->insertItem( i18n( "X.509 Certificate" ) ); + ProfilePskOptionsWidget->AuthTypeComboBox->insertItem( i18n( "Pre Shared Key" ) ); + ProfileCertOptionsWidget->AuthTypeComboBox->insertItem( i18n( "Hybrid" ) ); + ProfilePskOptionsWidget->AuthTypeComboBox->insertItem( i18n( "Hybrid" ) ); + + ProfileCertOptionsWidget->AuthTypeComboBox->setEnabled( true ); + ProfilePskOptionsWidget->AuthTypeComboBox->setEnabled( true ); + + if ( it->getAuthType() == VpnAccountData::cert || it->getAuthType() == VpnAccountData::hybrid ) + { + ProfileCertOptionsWidget->UseMailAddressAsIdentifierCheckBox->hide(); + ProfileCertOptionsWidget->UseSpecialServerCertificateCheckBox->hide(); + if (it->getAuthType() == VpnAccountData::cert ) + { + ProfileCertOptionsWidget->AuthTypeComboBox->setCurrentText( i18n( "X.509 Certificate" ) ); + ProfilePskOptionsWidget->AuthTypeComboBox->setCurrentText( i18n( "X.509 Certificate" ) ); + } + else + { + ProfileCertOptionsWidget->AuthTypeComboBox->setCurrentText( i18n( "Hybrid" ) ); + ProfilePskOptionsWidget->AuthTypeComboBox->setCurrentText( i18n( "Hybrid" ) ); + } + ProfileCertOptionsWidget->PrivkeyPasswordEdit->setText( it->getPrivateKeyPass() ); + ProfileCertOptionsWidget->SavePrivateKeyPasswordCheckBox->setChecked( it->getSavePrivateKeyPassword() ); + //emit useCiscoCertStoreToggled(it->getSavePrivateKeyPassword()); + ProfileCertOptionsWidget->UseCiscoCertStoreCheckBox->show(); + ProfileCertOptionsWidget->UseCiscoCertStoreCheckBox->setChecked(it->getUseCiscoCertStore()); + if (it->getUseCiscoCertStore()) + { + ProfileCertOptionsWidget->x509certURLRequester->hide(); + ProfileCertOptionsWidget->x509certComboBox->show(); + ProfileCertOptionsWidget->CaCertpathURLRequester->hide(); + ProfileCertOptionsWidget->CaCertpathComboBox->show(); + ProfileCertOptionsWidget->x509certComboBox->sizeHint(); + ProfileCertOptionsWidget->sizeHint(); + ProfileCertOptionsWidget->UseCiscoCertStoreCheckBox->setChecked(true); + } + else + { + ProfileCertOptionsWidget->x509certURLRequester->show(); + ProfileCertOptionsWidget->CaCertpathURLRequester->show(); + ProfileCertOptionsWidget->x509certComboBox->hide(); + ProfileCertOptionsWidget->CaCertpathComboBox->hide(); + ProfileCertOptionsWidget->x509certComboBox->sizeHint(); + ProfileCertOptionsWidget->sizeHint(); + ProfileCertOptionsWidget->UseCiscoCertStoreCheckBox->setChecked(false); + } + + ProfileCertOptionsWidget->x509certComboBox->clear(); + for ( QStringList::Iterator ciscoit = CiscoCerts.begin(); ciscoit != CiscoCerts.end(); ++ciscoit ) + { + //std::cout << "insert item (cisco certs): " << QString(*ciscoit) << std::endl; + + if (GlobalConfig->KvpncDebugLevel > 4) + GlobalConfig->appendLogEntry(i18n("insert cisco cert:")+" "+QString(*ciscoit),GlobalConfig->debug); + ProfileCertOptionsWidget->x509certComboBox->insertItem( QString(*ciscoit)); + } + if (!it->getX509Certificate().isEmpty()) + ProfileCertOptionsWidget->x509certComboBox->setCurrentText( it->getX509Certificate() ); + ProfileCertOptionsWidget->x509certURLRequester->setURL( it->getX509Certificate() ); + + ProfileCertOptionsWidget->CaCertpathComboBox->clear(); + for ( QStringList::Iterator ciscocait = CiscoCaCerts.begin(); ciscocait != CiscoCaCerts.end(); ++ciscocait ) + { + //std::cout << "insert item (cisco certs): " << QString(*ciscocait) << std::endl; + + if (GlobalConfig->KvpncDebugLevel > 4) + GlobalConfig->appendLogEntry(i18n("insert cisco ca cert:")+" "+QString(*ciscocait),GlobalConfig->debug); + ProfileCertOptionsWidget->CaCertpathComboBox->insertItem( QString(*ciscocait)); + } + if (!it->getCaCertificate().isEmpty()) + ProfileCertOptionsWidget->CaCertpathComboBox->setCurrentText( it->getCaCertificate() ); + } + else + { + ProfileCertOptionsWidget->AuthTypeComboBox->setCurrentText( i18n( "Pre Shared Key" ) ); + ProfilePskOptionsWidget->AuthTypeComboBox->setCurrentText( i18n( "Pre Shared Key" ) ); + } + + ProfileCertOptionsWidget->LabelPrivateKeyPassword->setText("Certificate password:"); + // ProfileCertOptionsWidget->LabelCertificate->setText(i18n("Certificate (enter name here):")); + + if (!it->getX509Certificate().isEmpty()) + { + ProfileCertOptionsWidget->x509certComboBox->setCurrentText(it->getX509Certificate()); + ProfileCertOptionsWidget->x509certURLRequester->setURL(it->getX509Certificate()); + } + else + { + ProfileCertOptionsWidget->x509certComboBox->setCurrentItem(0); + } + } + if ( it->getConnectionType() == VpnAccountData::cisco) + { + ProfileCertOptionsWidget->AuthTypeComboBox->insertItem( i18n( "Pre Shared Key" ) ); + ProfilePskOptionsWidget->AuthTypeComboBox->insertItem( i18n( "Pre Shared Key" ) ); + ProfileCertOptionsWidget->x509certComboBox->hide(); + ProfileCertOptionsWidget->CaCertpathComboBox->hide(); + ToolInfo *tool; + bool hasHybridSupport = getVpncHasHybridSupport(); + + if (hasHybridSupport) + { + ProfileCertOptionsWidget->AuthTypeComboBox->insertItem( i18n( "Hybrid" ) ); + ProfilePskOptionsWidget->AuthTypeComboBox->insertItem( i18n( "Hybrid" ) ); + ProfileCertOptionsWidget->AuthTypeComboBox->setEnabled( true ); + ProfilePskOptionsWidget->AuthTypeComboBox->setEnabled( true ); + ProfileCertOptionsWidget->CaCertpathURLRequester->setURL(GlobalConfig->currentProfile->getCaCertificate()); + ProfileCertOptionsWidget->certpathURLRequester->setURL( GlobalConfig->currentProfile->getCertPath() ); + ProfileCertOptionsWidget->VerifyCaCertCheckBox->setChecked(GlobalConfig->currentProfile->getVerifyCaCert()); + ProfileCertOptionsWidget->PrivkeyPasswordEdit->setText(GlobalConfig->currentProfile->getPrivateKeyPass()); + ProfileCertOptionsWidget->SavePrivateKeyPasswordCheckBox->setChecked(GlobalConfig->currentProfile->getSavePrivateKeyPassword()); + if (it->getAuthType() == VpnAccountData::psk ) + { + ProfileCertOptionsWidget->AuthTypeComboBox->setCurrentText( i18n( "Pre Shared Key" ) ); + ProfilePskOptionsWidget->AuthTypeComboBox->setCurrentText( i18n( "Pre Shared Key" ) ); + } + else + { + ProfileCertOptionsWidget->AuthTypeComboBox->setCurrentText( i18n( "Hybrid" ) ); + ProfilePskOptionsWidget->AuthTypeComboBox->setCurrentText( i18n( "Hybrid" ) ); + } + GlobalConfig->appendLogEntry ( i18n ( "Hybrid support detected, enabling cert options" ),GlobalConfig->debug ); + } + else + { + ProfileCertOptionsWidget->AuthTypeComboBox->setCurrentText( i18n( "Pre Shared Key" ) ); // PSK + ProfileCertOptionsWidget->AuthTypeComboBox->setEnabled( false ); + ProfilePskOptionsWidget->AuthTypeComboBox->setEnabled( false ); + ProfileCertOptionsWidget->setEnabled (false); + GlobalConfig->appendLogEntry ( i18n ( "Hybrid support not detected, disabling cert options" ),GlobalConfig->debug ); + } + } + + ProfileCiscoOptionsWidget->UseXauthInteractiveCheckBox->setChecked( it->getUseXauthInteractive() ); + ProfileCiscoOptionsWidget->LocalPortCheckbox->setChecked ( it->getUseLocalPort() ); + ProfileCiscoOptionsWidget->LocalPortSpinbox->setValue( it->getLocalPort() ); + + int vpnc_version_major = 0; + int vpnc_version_minor = 2; + int vpnc_version_subminor = 1; + + ToolInfo *Tool = Utils( GlobalConfig ).getToolInfo ( "vpnc" ); + if ( !Tool->Version.isEmpty() ) + { + vpnc_version_major = ( Tool->Version.section( '.', 0, 0 ) ).toInt(); + vpnc_version_minor = ( Tool->Version.section( '.', 1, 1 ) ).toInt(); + vpnc_version_subminor = ( Tool->Version.section( '.', 2, 2 ) ).toInt(); + } + + if ( vpnc_version_major ==0 && vpnc_version_minor < 3 ) + { + GlobalConfig->appendLogEntry( i18n( "%1 is too old. Minimum requirement is %2, disabling Xauth interactive option." ).arg( "vpnc" ).arg( "0.3.x" ), GlobalConfig->error ); + ProfileCiscoOptionsWidget->UseXauthInteractiveCheckBox->setEnabled( false ); + } + + if ( it->getConnectionType() == VpnAccountData::cisco) + { + if ( (vpnc_version_major == 0 && vpnc_version_minor >= 5 ) || ( vpnc_version_major > 0 )) + { + std::cout << "vpnc >= 0.5.0" << std::endl; + ProfileCiscoOptionsWidget->EnableDpdIdleTimeoutCheckbox->setEnabled(true); + ProfileCiscoOptionsWidget->EnableDpdIdleTimeoutCheckbox->setChecked(it->getUseDpdIdleTimeout()); + } + else + { + std::cout << "vpnc < 0.5.0" << std::endl; + ProfileCiscoOptionsWidget->EnableDpdIdleTimeoutCheckbox->setEnabled(false); + ProfileCiscoOptionsWidget->EnableDpdIdleTimeoutCheckbox->setChecked(false); + } + + ProfileCiscoOptionsWidget->EnableDpdIdleTimeoutCheckbox->show(); + QWhatsThis::add( ProfileCiscoOptionsWidget->EnableDpdIdleTimeoutCheckbox, i18n( "This enables DPD. Requires vpnc >= 0.5.0." ) ); + } + if ( it->getConnectionType() == VpnAccountData::ciscoorig) + { + ProfileCiscoOptionsWidget->EnableDpdIdleTimeoutCheckbox->setChecked(true); + ProfileCiscoOptionsWidget->EnableDpdIdleTimeoutCheckbox->hide(); + QWhatsThis::add( ProfileCiscoOptionsWidget->EnableDpdIdleTimeoutCheckbox, i18n( "This enables DPD." ) ); + } + ProfileCiscoOptionsWidget->DpdIdleTimeoutSpinbox->setValue(it->getDpdIdleTimeout()); + + + + if ( it->getUseUdp() ) + ProfileNetworkNatOptionsWidget->UseUdpCheckbox->setChecked( true ); + else + ProfileNetworkNatOptionsWidget->UseUdpCheckbox->setChecked( false ); + + ProfileNetworkNatOptionsWidget->UdpPortSpinbox->setValue( it->getUdpPort() ); + if ( it->getUseUdpPort() ) + ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setChecked( true ); + else + ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setChecked( false ); + + ProfileNetworkNatOptionsWidget->UseUdpCheckbox->setEnabled( true ); + ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setEnabled( true ); + if ( it->getUseUdp() ) + ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setEnabled( true ); + else + ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setEnabled( false ); + + ProfileNetworkGeneralOptionsWidget->RemoteNetAddrLineEdit->setEnabled( false ); + ProfileNetworkGeneralOptionsWidget->LabelRemoteNetwork->setEnabled( false ); + ProfileNetworkGeneralOptionsWidget->RemoteNetMaskComboBox->setEnabled( false ); + + ProfilePptpOptionsWidget->setEnabled( false ); + ProfileOpenvpnOptionsWidget->setEnabled( false ); + ProfileCiscoOptionsWidget->setEnabled( true ); + ProfileRacoonOptionsWidget->setEnabled( false ); + ProfileIpsecOptionsWidget->setEnabled( false ); + ProfileSshOptionsWidget->setEnabled( false ); + + ProfileCiscoOptionsWidget->PeerTimeoutIntNumInput->setValue( it->getPeerTimeout() ); + + ProfileUserOptionsWidget->NtDomainNameCheckbox->setEnabled( true ); + ProfileUserOptionsWidget->NtDomainNameLineedit->setEnabled ( false ); + ProfileUserOptionsWidget->NtDomainNameLineedit->setText( it->getNtDomainName() ); + if ( it->getUseNtDomainName() ) + { + ProfileUserOptionsWidget->NtDomainNameLineedit->setEnabled ( true ); + ProfileUserOptionsWidget->NtDomainNameCheckbox->setChecked( true ); + } + + ProfilePptpOptionsWidget->UseSearchDomainInResolvConfCheckbox->setEnabled(true); + ProfilePptpOptionsWidget->SearchDomainInResolvConfLineedit->setEnabled(false); + if ( it->getUseSearchDomainInResolvConf() ) + { + ProfilePptpOptionsWidget->SearchDomainInResolvConfLineedit->setEnabled ( true ); + ProfilePptpOptionsWidget->UseSearchDomainInResolvConfCheckbox->setChecked( true ); + } + ProfilePptpOptionsWidget->SearchDomainInResolvConfLineedit->setText(it->getSearchDomainInResolvConf()); + + + + if ( it->getUseGlobalIpsecSecret() ) + ProfileCiscoOptionsWidget->UseGlobalIpsecSecretCheckbox->setChecked ( true ); + else + ProfileCiscoOptionsWidget->UseGlobalIpsecSecretCheckbox->setChecked ( false ); + + ProfileCiscoOptionsWidget->UseGlobalIpsecSecretCheckbox->setChecked ( it->getUseGlobalIpsecSecret() ); + + + //FIXME + // ProfileNetworkRouteOptionsWidget->InterfaceComboBox->insertItem("tun0"); + ProfileNetworkGeneralOptionsWidget->TunnelDeviceTypeComboBox->setEnabled(true); + ProfileNetworkGeneralOptionsWidget->TunnelDeviceTypeLabel->setEnabled(true); + + if ( it->getConnectionType() == VpnAccountData::ConnectionType( VpnAccountData::cisco )) + { + + ProfileCiscoOptionsWidget->SingleDesCheckbox->setChecked ( false ); + ProfileCiscoOptionsWidget->IkeGroupCombobox->setEnabled( false ); + ProfileCiscoOptionsWidget->PerfectForwardSecrecyCombobox->setEnabled( false ); + ProfileCiscoOptionsWidget->PerfectForwardSecurityCheckbox->setChecked ( false ); + ProfileCiscoOptionsWidget->ApplicationVersionLineedit->setEnabled ( false ); + ProfileCiscoOptionsWidget->IkeGroupCombobox->setCurrentText ( it->getIkeGroup() ); + ProfileCiscoOptionsWidget->PerfectForwardSecrecyCombobox->setCurrentText ( it->getPerfectForwardSecrety() ); + ProfileCiscoOptionsWidget->ApplicationVersionLineedit->setText ( it->getApplicationVersion() ); + + ProfileCiscoOptionsWidget->IkeGroupCheckbox->setEnabled ( true ); + ProfileCiscoOptionsWidget->PerfectForwardSecurityCheckbox->setEnabled ( true ); + ProfileCiscoOptionsWidget->SingleDesCheckbox->setEnabled ( true ); + ProfileCiscoOptionsWidget->ApplicationVersionCheckbox->setEnabled ( true ); + + if ( it->getUseSingleDes() ) + { + ProfileCiscoOptionsWidget->SingleDesCheckbox->setChecked ( true ); + } + + if ( it->getUseIkeGroup() ) + { + ProfileCiscoOptionsWidget->IkeGroupCheckbox->setChecked ( true ); + ProfileCiscoOptionsWidget->IkeGroupCombobox->setEnabled ( true ); + } + + if ( it->getUsePerfectForwardSecrety() ) + { + ProfileCiscoOptionsWidget->PerfectForwardSecrecyCombobox->setEnabled ( true ); + ProfileCiscoOptionsWidget->PerfectForwardSecurityCheckbox->setChecked ( true ); + } + else + { + ProfileCiscoOptionsWidget->PerfectForwardSecrecyCombobox->setEnabled ( false ); + ProfileCiscoOptionsWidget->PerfectForwardSecurityCheckbox->setChecked ( false ); + } + + if ( it->getUseApplicationVersion() ) + { + ProfileCiscoOptionsWidget->ApplicationVersionLineedit->setEnabled ( true ); + ProfileCiscoOptionsWidget->ApplicationVersionCheckbox->setChecked ( true ); + } + ProfileCiscoOptionsWidget->DisableDataEncryptionCheckbox->setChecked(it->getDisableDataEncryption()); + } + else + { + ProfileCiscoOptionsWidget->SingleDesCheckbox->setEnabled( false ); + ProfileCiscoOptionsWidget->IkeGroupCombobox->setEnabled( false ); + ProfileCiscoOptionsWidget->IkeGroupCombobox->setCurrentText ( it->getIkeGroup() ); + ProfileCiscoOptionsWidget->PerfectForwardSecrecyCombobox->setEnabled( false ); + ProfileCiscoOptionsWidget->PerfectForwardSecurityCheckbox->setChecked ( false ); + ProfileCiscoOptionsWidget->PerfectForwardSecrecyCombobox->setCurrentText ( it->getPerfectForwardSecrety() ); + ProfileCiscoOptionsWidget->ApplicationVersionLineedit->setEnabled ( false ); + ProfileCiscoOptionsWidget->ApplicationVersionLineedit->setText ( it->getApplicationVersion() ); + } + } // vpnc + + else if ( it->getConnectionType() == VpnAccountData::l2tpd_racoon || it->getConnectionType() == VpnAccountData::racoon || it->getConnectionType() == VpnAccountData::freeswan || it->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { + ProfileNetworkGeneralOptionsWidget->UseRemoteNetworkCheckBox->setChecked(it->getUseRemoteNetwork()); + ProfileNetworkGeneralOptionsWidget->RemoteNetAddrLineEdit->setText( it->getRemoteNetAddr() ); + if ( !it->getRemoteNetMask().isEmpty() ) + ProfileNetworkGeneralOptionsWidget->RemoteNetMaskComboBox->setCurrentText( it->getRemoteNetMask() ); + + ProfileCertOptionsWidget->x509certComboBox->hide(); + ProfileCertOptionsWidget->CaCertpathComboBox->hide(); + + if (it->getConnectionType() == VpnAccountData::freeswan || it->getConnectionType() == VpnAccountData::l2tpd_freeswan) + { + if ( it->getAuthType() == VpnAccountData::cert ) + { + ProfileCertOptionsWidget->AuthTypeComboBox->setCurrentItem( 0 ); + ProfilePskOptionsWidget->AuthTypeComboBox->setCurrentItem( 0 ); + } + if ( it->getAuthType() == VpnAccountData::psk ) + { + ProfileCertOptionsWidget->AuthTypeComboBox->setCurrentText( i18n( "Pre Shared Key" ) ); + ProfilePskOptionsWidget->AuthTypeComboBox->setCurrentText( i18n( "Pre Shared Key" ) ); + } + } + if (it->getConnectionType() == VpnAccountData::l2tpd_racoon || it->getConnectionType() == VpnAccountData::racoon) + { + ProfileCertOptionsWidget->AuthTypeComboBox->insertItem( i18n( "X.509 Certificate" ) ); + ProfileCertOptionsWidget->AuthTypeComboBox->insertItem( i18n( "Pre Shared Key" ) ); + ProfilePskOptionsWidget->AuthTypeComboBox->insertItem( i18n( "X.509 Certificate" ) ); + ProfilePskOptionsWidget->AuthTypeComboBox->insertItem( i18n( "Pre Shared Key" ) ); + ProfileCertOptionsWidget->AuthTypeComboBox->insertItem( i18n( "Hybrid" ) ); + ProfilePskOptionsWidget->AuthTypeComboBox->insertItem( i18n( "Hybrid" ) ); + if ( it->getAuthType() == VpnAccountData::cert ) + { + ProfileCertOptionsWidget->AuthTypeComboBox->setCurrentText( i18n( "X.509 Certificate" ) ); + ProfilePskOptionsWidget->AuthTypeComboBox->setCurrentText( i18n( "X.509 Certificate" ) ); + } + if ( it->getAuthType() == VpnAccountData::psk ) + { + ProfileCertOptionsWidget->AuthTypeComboBox->setCurrentText( i18n( "Pre Shared Key" ) ); + ProfilePskOptionsWidget->AuthTypeComboBox->setCurrentText( i18n( "Pre Shared Key" ) ); + } + if ( it->getAuthType() == VpnAccountData::hybrid ) + { + // hybrid + ProfileCertOptionsWidget->AuthTypeComboBox->setCurrentText( i18n( "Hybrid" ) ); + ProfilePskOptionsWidget->AuthTypeComboBox->setCurrentText( i18n( "Hybrid" ) ); + } + ProfileRacoonOptionsWidget->RemoteIDLineEdit->setText( it->getSpecialRemoteID() ); + + } + + ProfileCertOptionsWidget->x509certURLRequester->setURL( it->getX509Certificate() ); + ProfileCertOptionsWidget->CaCertpathURLRequester->setURL( it->getCaCertificate() ); + ProfileCertOptionsWidget->certpathURLRequester->setURL( it->getCertPath() ); +// std::cout << "certPath: " << it->getCertPath() << std::endl; + ProfileCertOptionsWidget->PrivkeyPasswordEdit->setText( it->getPrivateKeyPass() ); + ProfileCertOptionsWidget->SavePrivateKeyPasswordCheckBox->setChecked( it->getSavePrivateKeyPassword() ); + ProfileCertOptionsWidget->privkeypathURLRequester->setURL( it->getPrivateKey() ); +// std::cout << "privateKey: " << it->getPrivateKey() << std::endl; + ProfileCertOptionsWidget->SpecialServerCertificateURLRequester->setEnabled(it->getUseSpecialServerCertificate()); + + ProfileNetworkGeneralOptionsWidget->PingCheckBox->setChecked( it->getDoPingIP() ); + ProfileNetworkGeneralOptionsWidget->PingIPLineEdit->setText( it->getPingHostIP() ); + + ProfilePskOptionsWidget->PSKLineEdit->setText( it->getPreSharedKey() ); + ProfilePskOptionsWidget->CheckSavePsk->setChecked( it->getSavePsk() ); + + ProfileIpsecOptionsWidget->UseRightNextHopCheckBox->setChecked(it->getUseRightNextHop()); + ProfileIpsecOptionsWidget->UseLeftNextHopCheckBox->setChecked(it->getUseLeftNextHop()); + ProfileIpsecOptionsWidget->LeftNextHopLineEdit->setText( it->getLeftNextHop() ); + ProfileIpsecOptionsWidget->RightNextHopLineEdit->setText( it->getRightNextHop() ); + ProfileIpsecOptionsWidget->DisableOpportunisticEncryptionCheckBox->setChecked( it->getDisableOpportunisticEncryption() ); + ProfileRacoonOptionsWidget->LocalIDLineEdit->setText(it->getSpecialLocalID()); + ProfileIpsecOptionsWidget->LocalIDLineEdit->setText(it->getSpecialLocalID()); + ProfileRacoonOptionsWidget->RemoteIDLineEdit->setText(it->getSpecialRemoteID()); + ProfileIpsecOptionsWidget->RemoteIDLineEdit->setText(it->getSpecialRemoteID()); +// ProfileRacoonOptionsWidget->UseSpecialLocalIDcheckBox->setChecked(it->getUseSpecialLocalID()); + + if (it->getIpsecVpnMode() == "transport") + ProfileIpsecOptionsWidget->IpsecVpnModeCombobox->setCurrentText("transport"); + else + ProfileIpsecOptionsWidget->IpsecVpnModeCombobox->setCurrentItem("tunnel"); + + + if (it->getLocalIDType() =="") + it->setLocalIDType("none"); + + if (it->getRemoteIDType() =="") + it->setRemoteIDType("none"); + + ProfileRacoonOptionsWidget->LocalIdTypeCombobox->setCurrentText(it->getLocalIDType()); + ProfileRacoonOptionsWidget->RemoteIdTypeCombobox->setCurrentText(it->getRemoteIDType()); + + ProfileIpsecOptionsWidget->LocalIdTypeCombobox->setCurrentText(it->getLocalIDType()); + ProfileIpsecOptionsWidget->RemoteIdTypeCombobox->setCurrentText(it->getRemoteIDType()); + + ProfileRacoonOptionsWidget->LocalIDLineEdit->setText(it->getSpecialLocalID()); + ProfileRacoonOptionsWidget->RemoteIDLineEdit->setText(it->getSpecialRemoteID()); + + ProfileIpsecOptionsWidget->LocalIDLineEdit->setText(it->getSpecialLocalID()); + ProfileRacoonOptionsWidget->RemoteIDLineEdit->setText(it->getSpecialRemoteID()); + + ProfileRacoonOptionsWidget->localIDTypeToggled(it->getLocalIDType()); + ProfileRacoonOptionsWidget->remoteIDTypeToggled(it->getRemoteIDType()); + ProfileIpsecOptionsWidget->localIDTypeToggled(it->getLocalIDType()); + ProfileIpsecOptionsWidget->remoteIDTypeToggled(it->getRemoteIDType()); + + // TODO made it useable for freeswan + if ( it->getConnectionType() == VpnAccountData::freeswan || it->getConnectionType() == VpnAccountData::l2tpd_freeswan) + { + if (it->getConnectionType() == VpnAccountData::l2tpd_freeswan) + { + ProfilePptpOptionsWidget->setEnabled( true ); + } + else + { + ProfilePptpOptionsWidget->setEnabled( false ); + } + ProfileOpenvpnOptionsWidget->setEnabled( false ); + ProfileCiscoOptionsWidget->setEnabled( false ); + ProfileRacoonOptionsWidget->setEnabled( false ); + ProfileIpsecOptionsWidget->setEnabled( true ); + ProfileSshOptionsWidget->setEnabled( false ); + + ProfileIpsecOptionsWidget->UseModeConfigCheckBox->hide(); + + ProfileCertOptionsWidget->UseSpecialServerCertificateCheckBox->setChecked( it->getUseSpecialServerCertificate() ); + ProfileCertOptionsWidget->SpecialServerCertificateURLRequester->setURL( it->getSpecialServerCertificate() ); + + if ( it->getUseSpecialServerCertificate() ) + ProfileCertOptionsWidget->SpecialServerCertificateURLRequester->setEnabled(true); + else + ProfileCertOptionsWidget->SpecialServerCertificateURLRequester->setEnabled( false ); + + // ike + esp + if (it->getUseCustomEsp()) + { + ProfileIpsecOptionsWidget->EspGroupBox->setEnabled(true); + ProfileIpsecOptionsWidget->UseCustomEspCheckBox->setChecked(true); + } + else + { + ProfileIpsecOptionsWidget->EspGroupBox->setEnabled(false); + ProfileIpsecOptionsWidget->UseCustomEspCheckBox->setChecked(false); + } + + if (it->getUseCustomIke()) + { + ProfileIpsecOptionsWidget->IkeGroupBox->setEnabled(true); + ProfileIpsecOptionsWidget->UseCustomIkeCheckBox->setChecked(true); + } + else + { + ProfileIpsecOptionsWidget->IkeGroupBox->setEnabled(false); + ProfileIpsecOptionsWidget->UseCustomIkeCheckBox->setChecked(false); + } + + QStringList IkeList= QStringList::split(",", it->getIpsecIke()); + QStringList EspList= QStringList::split(",", it->getIpsecEsp()); + QString IkeOther=""; + QString EspOther=""; + + for ( QStringList::Iterator ikeit = IkeList.begin(); ikeit != IkeList.end(); ++ikeit ) + { + std::cout << "ike: " << *ikeit << ":" << std::endl; + + if (*ikeit == "aes256-sha1") + ProfileIpsecOptionsWidget->IkeAes256Sha1CheckBox->setChecked(true); + else if (*ikeit == "aes128-sha1") + ProfileIpsecOptionsWidget->IkeAes128Sha1CheckBox->setChecked(true); + else if (*ikeit == "3des-sha1-modp2048") + ProfileIpsecOptionsWidget->IkeDesSha1Modp2048CheckBox->setChecked(true); + else if (*ikeit == "3des-md5") + ProfileIpsecOptionsWidget->IkeDesMd5CheckBox->setChecked(true); + else if (*ikeit == "3des-sha1") + ProfileIpsecOptionsWidget->IkeDesSha1CheckBox->setChecked(true); + else + { + if (!IkeOther.isEmpty()) + IkeOther+=","; + IkeOther+= *ikeit; + } + } + if (!IkeOther.isEmpty()) + ProfileIpsecOptionsWidget->OtherIkeLineEdit->setText(IkeOther); + + for ( QStringList::Iterator espit = EspList.begin(); espit != EspList.end(); ++espit ) + { + std::cout << "esp: " << *espit << ":" << std::endl; + + if (*espit == "3des-md5") + ProfileIpsecOptionsWidget->Esp3desMd5CheckBox->setChecked(true); + else if (*espit == "3des-sha1") + ProfileIpsecOptionsWidget->EspDesSha1CheckBox->setChecked(true); + else if (*espit == "aes128-sha1") + ProfileIpsecOptionsWidget->EspAes128Sha1CheckBox->setChecked(true); + else if (*espit == "aes256-sha1") + ProfileIpsecOptionsWidget->EspAes256Sha1CheckBox->setChecked(true); + else + { + if (!EspOther.isEmpty()) + EspOther+=","; + EspOther+= *espit; + } + } + if (!EspOther.isEmpty()) + ProfileIpsecOptionsWidget->OtherEspLineEdit->setText(EspOther); + +// IkeAes256Sha1CheckBox->setText( tr2i18n( "aes256-sha1" ) ); +// IkeAes128Sha1CheckBox->setText( tr2i18n( "aes128-sha1" ) ); +// IkeDesSha1Modp2048CheckBox->setText( tr2i18n( "3des-sha1-modp2048" ) ); +// IkeDesMd5CheckBox->setText( tr2i18n( "3des-md5" ) ); +// IkeDesSha1CheckBox->setText( tr2i18n( "3des-sha1" ) ); + +// Esp3desMd5CheckBox->setText( tr2i18n( "3des-md5" ) ); +// EspDesSha1CheckBox->setText( tr2i18n( "3des-sha1" ) ); +// EspAes128Sha1CheckBox->setText( tr2i18n( "aes128-sha1" ) ); +// EspAes256Sha1CheckBox->setText( tr2i18n( "aes256-sha1" ) ); + + + ProfileIpsecOptionsWidget->LocalIdTypeCombobox->setCurrentText(it->getLocalIDType()); + ProfileIpsecOptionsWidget->RemoteIdTypeCombobox->setCurrentText(it->getRemoteIDType()); + + ProfileNetworkGeneralOptionsWidget->RemoteNetAddrLineEdit->setEnabled( true ); + ProfileNetworkGeneralOptionsWidget->LabelRemoteNetwork->setEnabled( true ); + ProfileNetworkGeneralOptionsWidget->RemoteNetMaskComboBox->setEnabled( true ); + + ToolInfo *tool = Utils( GlobalConfig ).getToolInfo ( "ipsec" ); + QString realversion = tool->Version.section( ' ', 1, 1 ).section( '/', 0, 0 ).right( tool->Version.section( ' ', 1, 1 ).section( '/', 0, 0 ).length() - 1 ); + QString realtype = tool->Version.section( ' ', 0, 0 ).lower(); + + if ( it->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + ProfileUserOptionsWidget->setEnabled( true ); + else + ProfileUserOptionsWidget->setEnabled( false ); + + + ProfileNetworkGeneralOptionsWidget->MtuCheckbox->setEnabled( true ); + ProfileNetworkGeneralOptionsWidget->MruCheckbox->setEnabled( true ); + + if ( it->getUseMtu() ) + ProfileNetworkGeneralOptionsWidget->MtuSpinbox->setEnabled( true ); + else + ProfileNetworkGeneralOptionsWidget->MtuSpinbox->setEnabled( false ); + + if ( it->getUseMru() ) + ProfileNetworkGeneralOptionsWidget->MruSpinbox->setEnabled( true ); + else + ProfileNetworkGeneralOptionsWidget->MruSpinbox->setEnabled( false ); + + + ProfileSmartcardOptionsWidget->UseSmartcardCheckBox->setEnabled( true ); + + ProfileIpsecOptionsWidget->LocalIdentifierGroupBox->setEnabled ( true ); + + ProfileIpsecOptionsWidget->PerfectForwardSecurityCheckbox->setText(i18n("Enable Perfect for&ward secrecy (PFS)")); + ProfileIpsecOptionsWidget->PerfectForwardSecurityCheckbox->setChecked(it->getUsePerfectForwardSecrety()); + if (it->getPerfectForwardSecrety().isEmpty()) + it->setPerfectForwardSecrety("dh1024"); // dh group 2 + ProfileIpsecOptionsWidget->PerfectForwardSecrecyCombobox->setCurrentText(it->getPerfectForwardSecrety()); + if (it->getConnectionType() == VpnAccountData::l2tpd_freeswan) + { + ProfilePptpOptionsWidget->setEnabled( true ); + ProfileIpsecOptionsWidget->IpsecVpnModeCombobox->setCurrentText("transport"); + ProfileIpsecOptionsWidget->IpsecVpnModeCombobox->setEnabled(false); + } + else + { + ProfileIpsecOptionsWidget->IpsecVpnModeCombobox->setEnabled(true); + ProfilePptpOptionsWidget->setEnabled( false ); + if (it->getAuthWithUsernameAndPassword()) + { + ProfileUserOptionsWidget->setEnabled(true); + } + else + { + ProfileUserOptionsWidget->setEnabled(false); + } + + } + ToolInfo *IpsecToolInfo = Utils ( GlobalConfig ).getToolInfo ( "ipsec" ) ; + QString IpsecType; + if ( IpsecToolInfo->Version.contains ( "Openswan" ) ) + { + ProfileIpsecOptionsWidget->ExchangeModeComboBox->setEnabled(true); + // if (GlobalConfig->currentProfile->getExchangeMode()=="main") + // ProfileIpsecOptionsWidget->ExchangeModeComboBox->setCurrentItem(0); + // if (GlobalConfig->currentProfile->getExchangeMode()=="aggressive") + // ProfileIpsecOptionsWidget->ExchangeModeComboBox->setCurrentItem(1); + // if (GlobalConfig->currentProfile->getExchangeMode()=="base") + // ProfileIpsecOptionsWidget->ExchangeModeComboBox->setCurrentItem(2); + ProfileIpsecOptionsWidget->ExchangeModeComboBox->setCurrentText(GlobalConfig->currentProfile->getExchangeMode()); + + } + + else if ( IpsecToolInfo->Version.contains ( "strongSwan" ) ) + { + // no aggressive mode :( + ProfileIpsecOptionsWidget->ExchangeModeComboBox->setEnabled(false); + ProfileIpsecOptionsWidget->ExchangeModeComboBox->setCurrentText("main"); + } + + + // xauth + if ( it->getConnectionType() == VpnAccountData::freeswan && GlobalConfig->currentProfile->getAuthType() == VpnAccountData::psk ) + { + if (it->getAuthWithUsernameAndPassword()) + { + ProfileIpsecOptionsWidget->UseXauthCheckBox->setChecked(true); +// ProfilePskOptionsWidget->setEnabled(true); + if (it->getPskIsInFile()) + { + QFile PskFile(it->getPreSharedKeyFile()); + QString Psk=""; + if (PskFile.exists()) + Psk = QString(PskFile.readAll()); + ProfilePskOptionsWidget->PSKLineEdit->setText(Psk); + } + else + ProfilePskOptionsWidget->PSKLineEdit->setText(it->getPreSharedKey()); + if (it->getSavePsk() && !ProfilePskOptionsWidget->PSKLineEdit->text().isEmpty()) + ProfilePskOptionsWidget->CheckSavePsk->setChecked(true); + else + ProfilePskOptionsWidget->CheckSavePsk->setChecked(true); + + } + else + { + ProfileIpsecOptionsWidget->UseXauthCheckBox->setChecked(false); +// ProfilePskOptionsWidget->setEnabled(false); + } + } + + + ProfileNetworkVirtualIpOptionsWidget->setEnabled(true); + + // temporary + ProfileNetworkVirtualIpOptionsWidget->VirtualIpGroupBox->setEnabled(true); + ProfileNetworkVirtualIpOptionsWidget->UseVirtualIPCheckBox->setChecked(it->getUseVirtualIP()); + ProfileNetworkVirtualIpOptionsWidget->LocalVirtualIpEdit->setText(it->getLocalVirtualIP()); + ProfileNetworkVirtualIpOptionsWidget->LocalVirtualIpEdit->setEnabled(false); + ProfileNetworkVirtualIpOptionsWidget->RemoteVirtualIpLineEdit->setText(it->getRemoteVirtualIP()); + + + ProfileNetworkVirtualIpOptionsWidget->SourceIpgroupBox->show(); + ProfileNetworkVirtualIpOptionsWidget->UseLeftSourceIpCheckBox->setChecked( it->getUseLeftSourceIp()); + ProfileNetworkVirtualIpOptionsWidget->UseRightSourceIpCheckBox->setChecked(it->getUseRightSourceIp()); + ProfileNetworkVirtualIpOptionsWidget->LeftSourceIpLineEdit->setText(it->getLeftSourceIp()); + ProfileNetworkVirtualIpOptionsWidget->RightSourceIpLineEdit->setText(it->getRightSourceIp()); + + ProfileNetworkVirtualIpOptionsWidget->UseVirtualSubnetsCheckBox->setChecked(it->getUseVirtualSubnetworks()); + ProfileNetworkVirtualIpOptionsWidget->VirtualSubnetsLineEdit->setText(it->getVirtualSubnetworks()); + + + + } + else + { + // racoon + + ProfileRacoonOptionsWidget->setEnabled( true ); + ProfileIpsecOptionsWidget->setEnabled( false ); + + ProfileRacoonOptionsWidget->HashAlgoComboBox->setEnabled( true ); + ProfileRacoonOptionsWidget->HashAlgoTextLabel->setEnabled( true ); + ProfileRacoonOptionsWidget->UseModeConfigCheckBox->setEnabled( true ); + ProfileRacoonOptionsWidget->ExchangeModeComboBox->setEnabled( true ); + ProfileRacoonOptionsWidget->LocalIdentifierGroupBox->setEnabled ( true ); + ProfileCertOptionsWidget->UseMailAddressAsIdentifierCheckBox->setEnabled ( false ); + ProfileCertOptionsWidget->UseMailAddressAsIdentifierCheckBox->setChecked(false); + + ProfileRacoonOptionsWidget->PerfectForwardSecurityCheckbox->setText(i18n("Perfect for&ward secrecy (PFS):")); + ProfileRacoonOptionsWidget->PerfectForwardSecrecyCombobox->show(); + + ProfileNetworkVirtualIpOptionsWidget->SourceIpgroupBox->show(); + ProfileNetworkVirtualIpOptionsWidget->UseLeftSourceIpCheckBox->setChecked( it->getUseLeftSourceIp()); + ProfileNetworkVirtualIpOptionsWidget->UseRightSourceIpCheckBox->setChecked(it->getUseRightSourceIp()); + ProfileNetworkVirtualIpOptionsWidget->LeftSourceIpLineEdit->setText(it->getLeftSourceIp()); + ProfileNetworkVirtualIpOptionsWidget->RightSourceIpLineEdit->setText(it->getRightSourceIp()); + + if ( it->getConnectionType() == VpnAccountData::racoon ) + { + ProfileNetworkGeneralOptionsWidget->RemoteNetAddrLineEdit->setEnabled( true ); + ProfileNetworkGeneralOptionsWidget->LabelRemoteNetwork->setEnabled( true ); + ProfileNetworkGeneralOptionsWidget->RemoteNetMaskComboBox->setEnabled( true ); + ProfileNetworkGeneralOptionsWidget->RemoteNetDividetextLabel->setEnabled( true ); + } + + + + if ( it->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { + ProfileUserOptionsWidget->setEnabled( true ); + + + + ProfileNetworkGeneralOptionsWidget->RemoteNetAddrLineEdit->setEnabled( false ); + ProfileNetworkGeneralOptionsWidget->LabelRemoteNetwork->setEnabled( false ); + ProfileNetworkGeneralOptionsWidget->RemoteNetMaskComboBox->setEnabled( false ); + ProfileNetworkGeneralOptionsWidget->RemoteNetAddrLineEdit->setEnabled( false ); + ProfileNetworkGeneralOptionsWidget->RemoteNetDividetextLabel->setEnabled( false ); + + ProfileNetworkGeneralOptionsWidget->MtuCheckbox->setEnabled( true ); + ProfileNetworkGeneralOptionsWidget->MruCheckbox->setEnabled( true ); + + if ( GlobalConfig->currentProfile->getUseMtu() ) + ProfileNetworkGeneralOptionsWidget->MtuSpinbox->setEnabled( true ); + else + ProfileNetworkGeneralOptionsWidget->MtuSpinbox->setEnabled( false ); + + if ( GlobalConfig->currentProfile->getUseMru() ) + ProfileNetworkGeneralOptionsWidget->MruSpinbox->setEnabled( true ); + else + ProfileNetworkGeneralOptionsWidget->MruSpinbox->setEnabled( false ); + } +// else +// { +// ProfileNetworkGeneralOptionsWidget->MtuCheckbox->setEnabled( false ); +// ProfileNetworkGeneralOptionsWidget->MruCheckbox->setEnabled( false ); +// } + + ProfileRacoonOptionsWidget->IkeGroupCheckbox->setChecked ( false ); + ProfileRacoonOptionsWidget->PerfectForwardSecurityCheckbox->setChecked ( false ); + if (!it->getIkeGroup().isEmpty()) + ProfileRacoonOptionsWidget->DHGroupComboBox->setCurrentText ( it->getIkeGroup() ); + else + ProfileRacoonOptionsWidget->DHGroupComboBox->setCurrentItem(0); + + if (!it->getPerfectForwardSecrety().isEmpty()) + ProfileRacoonOptionsWidget->PerfectForwardSecrecyCombobox->setCurrentText ( it->getPerfectForwardSecrety() ); + else + ProfileRacoonOptionsWidget->PerfectForwardSecrecyCombobox->setCurrentItem ( 0 ); + + if ( it->getUseIkeGroup() ) + { + ProfileRacoonOptionsWidget->IkeGroupCheckbox->setChecked ( true ); + } + + if ( GlobalConfig->currentProfile->getUsePerfectForwardSecrety() ) + { + ProfileRacoonOptionsWidget->PerfectForwardSecrecyCombobox->setEnabled ( true ); + ProfileRacoonOptionsWidget->PerfectForwardSecurityCheckbox->setChecked ( true ); + } + + + if ( it->getUseIkeGroup() ) + { + ProfileRacoonOptionsWidget->DHGroupComboBox->setEnabled ( true ); + } + + // xauth + if ( it->getConnectionType() == VpnAccountData::racoon && ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::psk || GlobalConfig->currentProfile->getAuthType() == VpnAccountData::hybrid ) ) + { + if (it->getAuthWithUsernameAndPassword()) + { + ProfileRacoonOptionsWidget->UseXauthCheckBox->setChecked(true); +// ProfilePskOptionsWidget->setEnabled(true); + if (it->getPskIsInFile()) + { + QFile PskFile(it->getPreSharedKeyFile()); + QString Psk=""; + if (PskFile.exists()) + Psk = QString(PskFile.readAll()); + ProfilePskOptionsWidget->PSKLineEdit->setText(Psk); + } + else + ProfilePskOptionsWidget->PSKLineEdit->setText(it->getPreSharedKey()); + if (it->getSavePsk() && !ProfilePskOptionsWidget->PSKLineEdit->text().isEmpty()) + ProfilePskOptionsWidget->CheckSavePsk->setChecked(true); + else + ProfilePskOptionsWidget->CheckSavePsk->setChecked(true); + + } + else + { + ProfileIpsecOptionsWidget->UseXauthCheckBox->setChecked(false); +// ProfilePskOptionsWidget->setEnabled(false); + } + } + + if (GlobalConfig->currentProfile->getAuthType() == VpnAccountData::hybrid) + { + ProfileCertOptionsWidget->setEnabled(true); + ProfileCertOptionsWidget->x509certComboBox->setEnabled(false); + ProfilePskOptionsWidget->setEnabled(false); + } + + if (GlobalConfig->currentProfile->getAuthType() == VpnAccountData::hybrid) + { + ProfileCertOptionsWidget->x509certURLRequester->setURL(it->getX509Certificate()); + } + + + } // racoon + + + // FIXME + // ProfileNetworkRouteOptionsWidget->main->InterfaceComboBox->insertItem("ppp0"); + + //FIXME + // ProfileNetworkRouteOptionsWidget->main->InterfaceComboBox->insertItem("tun0"); + ProfileUserOptionsWidget->HideGroupPasswordInAccountDataDialogCheckBox->hide(); + } + + if (it->getConnectionType() == VpnAccountData::l2tpd_racoon ||it->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { + if (it->getAuthMethod() == "chap") + ProfilePptpOptionsWidget->AuthMethodComboBox->setCurrentItem(0); + if (it->getAuthMethod() == "pap") + ProfilePptpOptionsWidget->AuthMethodComboBox->setCurrentItem(1); + if (it->getAuthMethod() == "mschap") + ProfilePptpOptionsWidget->AuthMethodComboBox->setCurrentItem(2); + if (it->getAuthMethod() == "mschap-v2") + ProfilePptpOptionsWidget->AuthMethodComboBox->setCurrentItem(3); + } + + if ( it->getConnectionType() == VpnAccountData::racoon || it->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { + + ProfilePptpOptionsWidget->setEnabled( false ); + ProfileOpenvpnOptionsWidget->setEnabled( false ); + ProfileCiscoOptionsWidget->setEnabled( false ); + ProfileRacoonOptionsWidget->setEnabled( true ); + ProfileSshOptionsWidget->setEnabled( false ); + ProfileNetworkHttpProxyOptionsWidget ->setEnabled( false ); + + if (it->getConnectionType() == VpnAccountData::l2tpd_racoon) + { + ProfilePptpOptionsWidget->setEnabled( true ); + ProfileUserOptionsWidget->setEnabled( true ); + } + else + { + if (it->getAuthWithUsernameAndPassword()) + { + ProfilePptpOptionsWidget->setEnabled( true ); + ProfileUserOptionsWidget->setEnabled( true ); + } + else + { + ProfilePptpOptionsWidget->setEnabled( false ); + ProfileUserOptionsWidget->setEnabled( false ); + } + } + +// ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->clear(); +// ProfileRacoonOptionsWidget->AuthenticationAlgorithm2ComboBox->clear(); +// +// QStringList KernelCrypto = Utils( GlobalConfig ).getKernelCrypto(); +// // std::cout << "kernel crypto start " << std::endl; +// +// for ( QStringList::Iterator it = KernelCrypto.begin(); it != KernelCrypto.end(); ++it ) +// { +// ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->insertItem( QString(*it) ); +// // std::cout << "kernel crypto: " << *it << std::endl; +// } +// //FIXME why this is not in kernel crypto list??? +// // ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->insertItem( "3des" ); +// // ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->insertItem("des" ); +// // ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->insertItem("des_iv64" ); +// // ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->insertItem("des_iv32" ); +// // ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->insertItem("rc5" ); +// // ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->insertItem("rc4" ); +// // ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->insertItem("idea" ); +// // ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->insertItem("3idea" ); +// // ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->insertItem("cast128" ); +// // ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->insertItem("blowfish" ); +// // ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->insertItem("null_enc" ); +// // ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->insertItem("twofish" ); +// // ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->insertItem("rijndael" ); +// // ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->insertItem("aes" ); +// +// ProfileRacoonOptionsWidget->AuthenticationAlgorithm2ComboBox->insertItem( "des" ); +// ProfileRacoonOptionsWidget->AuthenticationAlgorithm2ComboBox->insertItem( "3des" ); +// ProfileRacoonOptionsWidget->AuthenticationAlgorithm2ComboBox->insertItem( "des_iv64" ); +// ProfileRacoonOptionsWidget->AuthenticationAlgorithm2ComboBox->insertItem( "des_iv32" ); +// ProfileRacoonOptionsWidget->AuthenticationAlgorithm2ComboBox->insertItem( "hmac_md5" ); +// ProfileRacoonOptionsWidget->AuthenticationAlgorithm2ComboBox->insertItem( "hmac_sha1" ); +// ProfileRacoonOptionsWidget->AuthenticationAlgorithm2ComboBox->insertItem( "hmac_sha256" ); +// ProfileRacoonOptionsWidget->AuthenticationAlgorithm2ComboBox->insertItem( "hmac_sha384" ); +// ProfileRacoonOptionsWidget->AuthenticationAlgorithm2ComboBox->insertItem( "hmac_sha512" ); +// ProfileRacoonOptionsWidget->AuthenticationAlgorithm2ComboBox->insertItem( "non_auth" ); +// + +// if ( it->getHashAlgo() == "sha1" ) +// ProfileRacoonOptionsWidget->HashAlgoComboBox->setCurrentText( "SHA1" ); +// if ( it->getHashAlgo() == "md5" ) +// ProfileRacoonOptionsWidget->HashAlgoComboBox->setCurrentText( "MD5" ); + + ProfileRacoonOptionsWidget->HashAlgoComboBox->setCurrentText( it->getHashAlgo()); + + ProfileRacoonOptionsWidget->DHGroupComboBox->setCurrentText( it->getIkeGroup() ); + if (!it->getEncryptionAlgorithm().isEmpty()) + ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->setCurrentText( it->getEncryptionAlgorithm() ); + ProfileRacoonOptionsWidget->AuthenticationAlgorithm2ComboBox->setCurrentText( it->getAuthenticationAlgorithm() ); + + if (!it->getIpsecIke().isEmpty()) + ProfileRacoonOptionsWidget->EncryptionAlgorithmComboBox->setCurrentText(it->getIpsecIke()); + + ProfileRacoonOptionsWidget->ExchangeModeComboBox->setCurrentText( it->getExchangeMode() ); + ProfileRacoonOptionsWidget->UseModeConfigCheckBox->setChecked( it->getUseModeConfig() ); + + ProfileCertOptionsWidget->VerifyCaCertCheckBox->setEnabled(true); + ProfileCertOptionsWidget->VerifyCaCertCheckBox->setChecked(it->getVerifyCaCert()); + + ProfileNetworkVirtualIpOptionsWidget->setEnabled( true ); + ProfileNetworkVirtualIpOptionsWidget->SourceIpgroupBox->show(); + ProfileNetworkVirtualIpOptionsWidget->VirtualIpGroupBox->setEnabled(false); +// ProfileNetworkVirtualIpOptionsWidget->UseVirtualIPCheckBox->setEnabled( true ); +// +// ProfileNetworkVirtualIpOptionsWidget->LocalVirtualIpEdit->setText( it->getLocalVirtualIP() ); +// ProfileNetworkVirtualIpOptionsWidget->RemoteVirtualIpLineEdit->setText( it->getRemoteVirtualIP() ); +// ProfileNetworkVirtualIpOptionsWidget->UseVirtualIPCheckBox->setChecked(it->getUseVirtualIP()); +// +// if (it->getUseVirtualIP()) +// { +// ProfileNetworkVirtualIpOptionsWidget->LocalVirtualIpEdit->setEnabled(true); +// ProfileNetworkVirtualIpOptionsWidget->RemoteVirtualIpLineEdit->setEnabled(true); +// } +// else +// { +// ProfileNetworkVirtualIpOptionsWidget->LocalVirtualIpEdit->setEnabled(false); +// ProfileNetworkVirtualIpOptionsWidget->RemoteVirtualIpLineEdit->setEnabled(false); +// } + + + if (GlobalConfig->currentProfile->getAuthType() == VpnAccountData::hybrid) + { + ProfileCertOptionsWidget->setEnabled(true); + ProfileCertOptionsWidget->x509certComboBox->setEnabled(false); + ProfileCertOptionsWidget->x509certURLRequester->setEnabled(false); + ProfileCertOptionsWidget->CaCertpathURLRequester->setEnabled(true); + ProfileCertOptionsWidget->CaCertpathURLRequester->setURL(it->getCaCertificate()); + ProfileCertOptionsWidget->certpathURLRequester->setURL( it->getCertPath() ); + ProfileCertOptionsWidget->LabelCertificate->setEnabled(false); + ProfileCertOptionsWidget->LabelPrivateKeyPath->setEnabled(false); + ProfileCertOptionsWidget->LabelPrivateKeyPassword->setEnabled(false); + ProfileCertOptionsWidget->SpecialServerCertificateURLRequester->setEnabled(false); + ProfileCertOptionsWidget->PrivkeyPasswordEdit->setEnabled(false); + ProfileCertOptionsWidget->SavePrivateKeyPasswordCheckBox->setEnabled(false); + ProfileCertOptionsWidget->UseSpecialServerCertificateCheckBox->setEnabled(false); + ProfileCertOptionsWidget->privkeypathURLRequester->setEnabled(false); + ProfilePskOptionsWidget->setEnabled(false); + } + + + } // racoon + + else if ( it->getConnectionType() == VpnAccountData::ConnectionType( VpnAccountData::pptp ) ) + { + ProfilePskOptionsWidget->CheckSavePsk->setChecked( it->getSavePsk() ); + ProfileUserOptionsWidget->CheckUserPass->setChecked ( it->getSaveUserPassword() ); + ProfileUserOptionsWidget->UsernameLineEdit->setText ( it->getUserName() ); + ProfileUserOptionsWidget->PasswordEdit->setText ( it->getUserPassword() ); + ProfileUserOptionsWidget->DontSaveUsernameCheckBox->setChecked(it->getDontSaveUsername() ); + ProfileNetworkGeneralOptionsWidget->PingCheckBox->setChecked( it->getDoPingIP() ); + ProfileNetworkGeneralOptionsWidget->PingIPLineEdit->setText( it->getPingHostIP() ); + + if ( !it->getRemoteNetAddr().isEmpty() && !it->getRemoteNetMask().isEmpty() ) + { + ProfileNetworkGeneralOptionsWidget->RemoteNetAddrLineEdit->setText( it->getRemoteNetAddr() ); + if ( !it->getRemoteNetMask().isEmpty() ) + ProfileNetworkGeneralOptionsWidget->RemoteNetMaskComboBox->setCurrentText( it->getRemoteNetMask() ); + } + + ProfilePptpOptionsWidget->RequireMppeCheckbox->setChecked( it->getRequireMppe() ); + ProfilePptpOptionsWidget->Refuse128BitEncryptionCheckbox->setChecked( it->getRefuse128BitEncryption() ); + ProfilePptpOptionsWidget->Refuse40BitEncryptionCheckbox->setChecked( it->getRefuse40BitEncryption() ); + ProfilePptpOptionsWidget->UseNoMPPECompressionCheckbox->setChecked( it->getDisableMPPEComp() ); + ProfilePptpOptionsWidget->DnsServerCheckbox->setChecked( it->getUseDnsServer() ); + ProfilePptpOptionsWidget->DnsServerLineedit->setText( it->getDnsServer() ); + ProfilePptpOptionsWidget->UseNoBsdCompCheckbox->setChecked( it->getUseNoBsdComp() ); + ProfilePptpOptionsWidget->UseNoDeflateCheckbox->setChecked( it->getUseNoDeflate() ); + ProfilePptpOptionsWidget->AllowStatefulModeCheckbox->setChecked( it->getAllowStatefulMode() ); + ProfilePptpOptionsWidget->UseNoIpDefaultCheckbox->setChecked( it->getUseNoIpDefault() ); + ProfilePptpOptionsWidget->DisableCcpCheckbox->setChecked( it->getDisableCcp() ); + ProfilePptpOptionsWidget->DisableHeaderCompressionCheckbox->setChecked(it->getDisableHeaderCompression()); + ProfilePptpOptionsWidget->DisableMagicNumberNegotiationCheckbox->setChecked(it->getDisableMagicNumberNegotiation()); + ProfilePptpOptionsWidget->DisableIpxCheckbox->setChecked(it->getDisableIpx()); + ProfilePptpOptionsWidget->DisableAdressControlCompressionCheckbox->setChecked(it->getDisableAdressControlCompression()); + ProfilePptpOptionsWidget->DisableProtocolFieldCompressionCheckbox->setChecked(it->getDisableProtocolFieldCompression()); + ProfilePptpOptionsWidget->RequireEapCheckbox->setChecked(it->getRequireEap()); + + ProfileUserOptionsWidget->NtDomainNameCheckbox->setEnabled( true ); + ProfileUserOptionsWidget->NtDomainNameLineedit->setEnabled ( false ); + ProfileUserOptionsWidget->NtDomainNameLineedit->setText( it->getNtDomainName() ); + if ( it->getUseNtDomainName() ) + { + ProfileUserOptionsWidget->NtDomainNameLineedit->setEnabled ( true ); + ProfileUserOptionsWidget->NtDomainNameCheckbox->setChecked( true ); + } + + ProfilePptpOptionsWidget->UseSearchDomainInResolvConfCheckbox->setEnabled(true); + ProfilePptpOptionsWidget->SearchDomainInResolvConfLineedit->setEnabled(false); + ProfilePptpOptionsWidget->SearchDomainInResolvConfLineedit->setText(it->getSearchDomainInResolvConf()); + if ( it->getUseSearchDomainInResolvConf() ) + { + ProfilePptpOptionsWidget->SearchDomainInResolvConfLineedit->setEnabled ( true ); + ProfilePptpOptionsWidget->UseSearchDomainInResolvConfCheckbox->setChecked( true ); + } + + + ProfileCiscoOptionsWidget->IDLineEdit->setEnabled( false ); + ProfileCiscoOptionsWidget->LabelID->setEnabled( false ); + + ProfileNetworkGeneralOptionsWidget->RemoteNetAddrLineEdit->setEnabled( false ); + ProfileNetworkGeneralOptionsWidget->LabelRemoteNetwork->setEnabled( false ); + ProfileNetworkGeneralOptionsWidget->RemoteNetMaskComboBox->setEnabled( false ); + ProfileCertOptionsWidget->ImportCertificatePushButton->setEnabled( false ); + ProfileNetworkGeneralOptionsWidget->NetworkDeviceComboBox->setEnabled( false ); + ProfileNetworkGeneralOptionsWidget->RemoteNetDividetextLabel->setEnabled( false ); + ProfileNetworkGeneralOptionsWidget->LabelNetworkDevice->setEnabled( false ); + + ProfilePptpOptionsWidget->setEnabled( true ); + ProfileOpenvpnOptionsWidget->setEnabled( false ); + ProfileCiscoOptionsWidget->setEnabled( false ); + ProfileRacoonOptionsWidget->setEnabled( false ); + ProfileIpsecOptionsWidget->setEnabled( false ); + ProfileSshOptionsWidget->setEnabled( false ); + + if (it->getAuthMethod() == "chap") + ProfilePptpOptionsWidget->AuthMethodComboBox->setCurrentItem(0); + if (it->getAuthMethod() == "pap") + ProfilePptpOptionsWidget->AuthMethodComboBox->setCurrentItem(1); + if (it->getAuthMethod() == "mschap") + ProfilePptpOptionsWidget->AuthMethodComboBox->setCurrentItem(2); + if (it->getAuthMethod() == "mschap-v2") + ProfilePptpOptionsWidget->AuthMethodComboBox->setCurrentItem(3); + + //FIXME + // ProfileNetworkRouteOptionsWidget->InterfaceComboBox->insertItem("ppp0"); + + ProfileNetworkVirtualIpOptionsWidget->setEnabled( true ); + ProfileNetworkVirtualIpOptionsWidget->SourceIpgroupBox->hide(); + ProfileNetworkVirtualIpOptionsWidget->UseVirtualIPCheckBox->setEnabled( true ); + + ProfileNetworkVirtualIpOptionsWidget->LocalVirtualIpEdit->setText( it->getLocalVirtualIP() ); + ProfileNetworkVirtualIpOptionsWidget->RemoteVirtualIpLineEdit->setText( it->getRemoteVirtualIP() ); + ProfileNetworkVirtualIpOptionsWidget->UseVirtualIPCheckBox->setChecked(it->getUseVirtualIP()); + + if (it->getUseVirtualIP()) + { + ProfileNetworkVirtualIpOptionsWidget->LocalVirtualIpEdit->setEnabled(true); + ProfileNetworkVirtualIpOptionsWidget->RemoteVirtualIpLineEdit->setEnabled(true); + } + else + { + ProfileNetworkVirtualIpOptionsWidget->LocalVirtualIpEdit->setEnabled(false); + ProfileNetworkVirtualIpOptionsWidget->RemoteVirtualIpLineEdit->setEnabled(false); + } + ProfileUserOptionsWidget->HideGroupPasswordInAccountDataDialogCheckBox->hide(); + + } // pptp + + else if ( it->getConnectionType() == VpnAccountData::ConnectionType( VpnAccountData::openvpn ) ) + { + + if ( it->getAuthType() == VpnAccountData::cert ) + { + ProfileCertOptionsWidget->AuthTypeComboBox->setCurrentItem( 0 ); + ProfilePskOptionsWidget->AuthTypeComboBox->setCurrentItem( 0 ); + } + if ( it->getAuthType() == VpnAccountData::psk ) + { + ProfileCertOptionsWidget->AuthTypeComboBox->setCurrentItem( 1 ); + ProfilePskOptionsWidget->AuthTypeComboBox->setCurrentItem( 1 ); + } + + ProfileCertOptionsWidget->x509certComboBox->hide(); + ProfileCertOptionsWidget->CaCertpathComboBox->hide(); + + ProfileCertOptionsWidget->x509certURLRequester->setURL( it->getX509Certificate() ); + ProfileCertOptionsWidget->CaCertpathURLRequester->setURL( it->getCaCertificate() ); + ProfileCertOptionsWidget->certpathURLRequester->setURL( it->getCertPath() ); + ProfileCertOptionsWidget->PrivkeyPasswordEdit->setText( it->getPrivateKeyPass() ); + ProfileCertOptionsWidget->SavePrivateKeyPasswordCheckBox->setChecked( it->getSavePrivateKeyPassword() ); + ProfileCertOptionsWidget->privkeypathURLRequester->setURL( it->getPrivateKey() ); + ProfilePskOptionsWidget->PSKLineEdit->setText( it->getPreSharedKey() ); + ProfilePskOptionsWidget->PskInFileCheckBox->setChecked( it->getPskIsInFile() ); + ProfilePskOptionsWidget->CheckSavePsk->setChecked( it->getSavePsk() ); + ProfileNetworkGeneralOptionsWidget->PingCheckBox->setChecked( it->getDoPingIP() ); + ProfileNetworkGeneralOptionsWidget->PingIPLineEdit->setText( it->getPingHostIP() ); + + ProfileNetworkVirtualIpOptionsWidget->LocalVirtualIpEdit->setText( it->getLocalVirtualIP() ); + ProfileNetworkVirtualIpOptionsWidget->RemoteVirtualIpLineEdit->setText( it->getRemoteVirtualIP() ); + ProfileNetworkVirtualIpOptionsWidget->UseVirtualIPCheckBox->setChecked(it->getUseVirtualIP()); + + if (it->getUseVirtualIP()) + { + ProfileNetworkVirtualIpOptionsWidget->LocalVirtualIpEdit->setEnabled(true); + ProfileNetworkVirtualIpOptionsWidget->RemoteVirtualIpLineEdit->setEnabled(true); + tunnelDeviceTypeChanged(it->getTunnelDeviceType()); + } + else + { + ProfileNetworkVirtualIpOptionsWidget->LocalVirtualIpEdit->setEnabled(false); + ProfileNetworkVirtualIpOptionsWidget->RemoteVirtualIpLineEdit->setEnabled(false); + } + // ProfileNetworkGeneralOptionsWidget->RemoteNetAddrLineEdit->setText( it->getRemoteNetAddr() ); + // + // if (!it->getRemoteNetMask().isEmpty()) + // ProfileNetworkGeneralOptionsWidget->RemoteNetMaskComboBox->setCurrentText( it->getRemoteNetMask() ); + + + if ( it->getUseUdp() ) + ProfileNetworkNatOptionsWidget->UseUdpCheckbox->setChecked( true ); + else + ProfileNetworkNatOptionsWidget->UseUdpCheckbox->setChecked( false ); + + ProfileNetworkNatOptionsWidget->UdpPortSpinbox->setValue( it->getUdpPort() ); + if ( it->getUseUdpPort() ) + ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setChecked( true ); + else + ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setChecked( false ); + + ProfileNetworkNatOptionsWidget->UseUdpCheckbox->setEnabled( true ); + ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setEnabled( true ); + if ( it->getUseUdp() ) + ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setEnabled( true ); + else + ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setEnabled( false ); + + ProfileNetworkVirtualIpOptionsWidget->setEnabled( true ); + + ProfilePptpOptionsWidget->setEnabled( false ); + ProfileOpenvpnOptionsWidget->setEnabled( true ); + ProfileCiscoOptionsWidget->setEnabled( false ); + ProfileRacoonOptionsWidget->setEnabled( false ); + ProfileIpsecOptionsWidget->setEnabled( false ); + ProfileSshOptionsWidget->setEnabled( false ); + ProfileNetworkHttpProxyOptionsWidget ->setEnabled( true ); + ProfileNetworkVirtualIpOptionsWidget->SourceIpgroupBox->hide(); + + if ( GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) + ProfileUserOptionsWidget->setEnabled( true ); + else + ProfileUserOptionsWidget->setEnabled( false ); + +// ProfileNetworkVirtualIpOptionsWidget->LocalVirtualIpEdit->setEnabled( false ); +// ProfileNetworkVirtualIpOptionsWidget->RemoteVirtualIpLineEdit->setEnabled( false ); + + if ( GlobalConfig->currentProfile->getUseUserdefinedPort() ) + { + ProfileOpenvpnOptionsWidget->UseUserdefinedPortCheckBox->setChecked( true ); + ProfileOpenvpnOptionsWidget->UserdefinedPortSpinBox->setEnabled( true ); + } + else + { + ProfileOpenvpnOptionsWidget->UseUserdefinedPortCheckBox->setChecked( false ); + ProfileOpenvpnOptionsWidget->UserdefinedPortSpinBox->setEnabled( false ); + } + + if ( it->getAuthType() == VpnAccountData::cert ) + { + ProfileOpenvpnOptionsWidget->UseNsCertTypeCheckBox->setEnabled( true ); + ProfileOpenvpnOptionsWidget->UseTlsRemoteHostCheckBox->setEnabled( true ); + } + else + { + ProfileOpenvpnOptionsWidget->UseNsCertTypeCheckBox->setEnabled( false ); + ProfileOpenvpnOptionsWidget->UseTlsRemoteHostCheckBox->setEnabled( false ); + } + + if ( GlobalConfig->currentProfile->getUseNsCertType() ) + { + ProfileOpenvpnOptionsWidget->UseNsCertTypeCheckBox->setChecked( true ); + ProfileOpenvpnOptionsWidget->NsCertTypeComboBox->setEnabled( true ); + + if ( GlobalConfig->currentProfile->getNsCertType() == "client" ) + ProfileOpenvpnOptionsWidget->NsCertTypeComboBox->setCurrentItem( 0 ); + else + ProfileOpenvpnOptionsWidget->NsCertTypeComboBox->setCurrentItem( 1 ); + } + else + { + ProfileOpenvpnOptionsWidget->UseNsCertTypeCheckBox->setChecked( false ); + ProfileOpenvpnOptionsWidget->NsCertTypeComboBox->setEnabled( false ); + } + ProfileOpenvpnOptionsWidget->UserdefinedPortSpinBox->setValue( GlobalConfig->currentProfile->getUserdefinedPort() ); + + if ( GlobalConfig->currentProfile->getDisableLzoCompression() ) + ProfileOpenvpnOptionsWidget->DisableLzoCompressionCheckBox->setChecked( true ); + else + ProfileOpenvpnOptionsWidget->DisableLzoCompressionCheckBox->setChecked( false ); + + ProfileOpenvpnOptionsWidget->UserdefinedPortSpinBox->setValue( GlobalConfig->currentProfile->getUserdefinedPort() ); + + if ( GlobalConfig->currentProfile->getAuthWithUsernameAndPassword() ) + ProfileOpenvpnOptionsWidget->AuthWithUsernameAndPasswordCheckBox->setChecked ( true ); + else + ProfileOpenvpnOptionsWidget->AuthWithUsernameAndPasswordCheckBox->setChecked ( false ); + + if ( GlobalConfig->currentProfile->getUseTlsRemoteHost() ) + { + ProfileOpenvpnOptionsWidget->UseTlsRemoteHostCheckBox->setChecked( true ); + ProfileOpenvpnOptionsWidget->TlsRemoteHostLineEdit->setEnabled( true ); + } + else + { + ProfileOpenvpnOptionsWidget->UseTlsRemoteHostCheckBox->setChecked( false ); + ProfileOpenvpnOptionsWidget->TlsRemoteHostLineEdit->setEnabled( false ); + } + + + if ( GlobalConfig->currentProfile->getUseTlsAuth() ) + { + ProfileOpenvpnOptionsWidget->UseTlsAuthCheckBox->setChecked( true ); + ProfileOpenvpnOptionsWidget->TlsAuthURLRequester->setEnabled( true ); + } + else + { + ProfileOpenvpnOptionsWidget->UseTlsAuthCheckBox->setChecked( false ); + ProfileOpenvpnOptionsWidget->TlsAuthURLRequester->setEnabled( false ); + } + + ProfileNetworkVirtualIpOptionsWidget->UseVirtualIPCheckBox->setEnabled( true ); + + ProfileNetworkVirtualIpOptionsWidget->UseVirtualIPCheckBox->setChecked( GlobalConfig->currentProfile->getUseVirtualIP() ); + + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::openvpn ) + ProfileNetworkVirtualIpOptionsWidget->setEnabled( true ); + else + { + ProfileNetworkVirtualIpOptionsWidget->setEnabled( false ); + + ProfileNetworkVirtualIpOptionsWidget->RemoteVirtualIpLineEdit->setText( GlobalConfig->currentProfile->getRemoteVirtualIP() ); + ProfileNetworkVirtualIpOptionsWidget->LocalVirtualIpEdit->setText( GlobalConfig->currentProfile->getLocalVirtualIP() ); + } + + ProfilePskOptionsWidget->CheckSavePsk->setChecked( it->getSavePsk() ); + ProfileUserOptionsWidget->CheckUserPass->setChecked ( it->getSaveUserPassword() ); + ProfileUserOptionsWidget->UsernameLineEdit->setText ( it->getUserName() ); + ProfileUserOptionsWidget->PasswordEdit->setText ( it->getUserPassword() ); + ProfileUserOptionsWidget->DontSaveUsernameCheckBox->setChecked(it->getDontSaveUsername() ); + + ProfileOpenvpnOptionsWidget->TlsAuthURLRequester->setURL ( it->getTlsAuthFile() ); + ProfileOpenvpnOptionsWidget->TlsRemoteHostLineEdit->setText( it->getTlsRemoteHost() ); + + ProfileOpenvpnOptionsWidget->UseUserdefinedRemotePortCheckBox->setChecked( it->getUseRemotePort() ); + ProfileOpenvpnOptionsWidget->UserdefinedRemotePortSpinBox->setValue( it->getRemotePort() ); + + ProfileOpenvpnOptionsWidget->UserdefinedFragmentSizeSpinBox->setValue( it->getFragment() ); + + ProfileOpenvpnOptionsWidget->UseUserdefinedFragmentationSizeCheckBox->setChecked( it->getUseFragment() ); + + ProfileNetworkHttpProxyOptionsWidget->UseHttpProxyCheckBox->setChecked( GlobalConfig->currentProfile->getUseHttpProxy() ); + ProfileNetworkHttpProxyOptionsWidget->HttpProxyLineEdit->setText( GlobalConfig->currentProfile->getHttpProxy() ); + ProfileNetworkHttpProxyOptionsWidget->HttpProxyTimeoutIntSpinBox->setValue( GlobalConfig->currentProfile->getHttpProxyTimeout() ); + ProfileNetworkHttpProxyOptionsWidget->HttpProxyPortIntNumInput->setValue( GlobalConfig->currentProfile->getHttpProxyPort() ); + + if ( GlobalConfig->currentProfile->getHttpProxyAuthType() == "basic" ) + ProfileNetworkHttpProxyOptionsWidget->HttpProxyAuthTypeComboBox->setCurrentText( "Basic" ); + else if ( GlobalConfig->currentProfile->getHttpProxyAuthType() == "ntlm" ) + ProfileNetworkHttpProxyOptionsWidget->HttpProxyAuthTypeComboBox->setCurrentText( "NTLM" ); + else + ProfileNetworkHttpProxyOptionsWidget->HttpProxyAuthTypeComboBox->setCurrentText( "Basic" ); + + ProfileNetworkHttpProxyOptionsWidget->useHttpProxyToggeled(GlobalConfig->currentProfile->getUseHttpProxy()); + + ProfileNetworkHttpProxyOptionsWidget->HttpProxyUserLineEdit->setText( GlobalConfig->currentProfile->getHttpProxyUser() ); + ProfileNetworkHttpProxyOptionsWidget->HttpProxyAuthPasswordEdit->setText( GlobalConfig->currentProfile->getHttpProxyPass() ); + + ProfileNetworkHttpProxyOptionsWidget->UseHttpProxyAuthCheckBox->setChecked( GlobalConfig->currentProfile->getUseHttpProxyAuth() ); + + if ( GlobalConfig->currentProfile->getUseHttpProxyAuth() ) + ProfileNetworkHttpProxyOptionsWidget->HttpProxyGroupBox->setEnabled(true); + else + ProfileNetworkHttpProxyOptionsWidget->HttpProxyGroupBox->setEnabled(false); + + + if ( GlobalConfig->currentProfile->getUseOnlyCaCertAndUserAuth() ) + ProfileOpenvpnOptionsWidget->UseOnlyCaCertAndUserAuthCheckBox->setChecked( true ); + else + ProfileOpenvpnOptionsWidget->UseOnlyCaCertAndUserAuthCheckBox->setChecked( false ); + + + ProfileOpenvpnOptionsWidget->UserdefiniedDigestComboBox->setCurrentText(GlobalConfig->currentProfile->getAuthenticationAlgorithm()); + ProfileOpenvpnOptionsWidget->UserdefiniedDigestComboBox->setEnabled(GlobalConfig->currentProfile->getUseAuthenticationAlgorithm()); + ProfileOpenvpnOptionsWidget->UseAuthenticationAlgorithmCheckBox->setChecked(GlobalConfig->currentProfile->getUseAuthenticationAlgorithm()); + + ProfileSmartcardOptionsWidget->UseSmartcardCheckBox->setEnabled( true ); + + //FIXME + // ProfileNetworkRouteOptionsWidget->InterfaceComboBox->insertItem("tun0"); + ProfileNetworkGeneralOptionsWidget->TunnelDeviceTypeComboBox->setEnabled(true); + ProfileNetworkGeneralOptionsWidget->TunnelDeviceTypeLabel->setEnabled(true); + + + if (GlobalConfig->currentProfile->getAuthenticationDirection() == "none") + ProfileOpenvpnOptionsWidget->AuthenticationDirectionComboBox->setCurrentText(i18n("none")); + if (GlobalConfig->currentProfile->getAuthenticationDirection() == "0") + ProfileOpenvpnOptionsWidget->AuthenticationDirectionComboBox->setCurrentText(i18n("0")); + if (GlobalConfig->currentProfile->getAuthenticationDirection() == "1") + ProfileOpenvpnOptionsWidget->AuthenticationDirectionComboBox->setCurrentText(i18n("1")); + + ProfileUserOptionsWidget->HideGroupPasswordInAccountDataDialogCheckBox->hide(); + + + if (GlobalConfig->currentProfile->getUseRenegSec()) + ProfileOpenvpnOptionsWidget->RenegSecCheckBox->setChecked(true); + else + ProfileOpenvpnOptionsWidget->RenegSecCheckBox->setChecked(false); + + ProfileOpenvpnOptionsWidget->RenegSecSpinBox->setValue(GlobalConfig->currentProfile->getRenegSec()); + + if (GlobalConfig->currentProfile->getUseTunnelPing()) + { + ProfileOpenvpnOptionsWidget->TunnelPingCheckBox->setChecked(true); + ProfileOpenvpnOptionsWidget->TunnelPingSpinBox->setValue(GlobalConfig->currentProfile->getTunnelPing()); + } + + if (GlobalConfig->currentProfile->getUseTunnelPingRestart()) + ProfileOpenvpnOptionsWidget->TunnelPingRestartCheckBox->setChecked(true); + else + ProfileOpenvpnOptionsWidget->TunnelPingRestartCheckBox->setChecked(false); + + ProfileOpenvpnOptionsWidget->TunnelPingRestartSpinBox->setValue(GlobalConfig->currentProfile->getTunnelPingRestart()); + + + ProfileOpenvpnOptionsWidget->DisableSocketBindCheckBox->setChecked(GlobalConfig->currentProfile->getDisableBind()); + + } // openvpn + + if ( it->getConnectionType() == VpnAccountData::vtun ) + { + + ProfileVtunOptionsWidget->setEnabled( true ); + + ProfileVtunOptionsWidget->PortCheckbox->setChecked(GlobalConfig->currentProfile->getUseLocalPort()); + ProfileVtunOptionsWidget->PortSpinbox->setValue(GlobalConfig->currentProfile->getLocalPort()); + + ProfileVtunOptionsWidget->VtunProfileLineEdit->setText(GlobalConfig->currentProfile->getVtunProfile()); + + ProfileUserOptionsWidget->UsernameLineEdit->setEnabled(false); + + ProfileNetworkVirtualIpOptionsWidget->setEnabled( true ); + ProfileNetworkVirtualIpOptionsWidget->SourceIpgroupBox->hide(); + ProfileNetworkVirtualIpOptionsWidget->UseVirtualIPCheckBox->setEnabled( true ); + ProfileNetworkVirtualIpOptionsWidget->UseVirtualIPCheckBox->setChecked( GlobalConfig->currentProfile->getUseVirtualIP() ); + + ProfileNetworkVirtualIpOptionsWidget->RemoteVirtualIpLineEdit->setText( GlobalConfig->currentProfile->getRemoteVirtualIP() ); + ProfileNetworkVirtualIpOptionsWidget->LocalVirtualIpEdit->setText( GlobalConfig->currentProfile->getLocalVirtualIP() ); + + ProfileUserOptionsWidget->HideGroupPasswordInAccountDataDialogCheckBox->hide(); + } // vtun + if ( it->getConnectionType() == VpnAccountData::ssh ) + { + + ProfileVtunOptionsWidget->setEnabled( true ); + + ProfileVtunOptionsWidget->PortCheckbox->setChecked(it->getUseLocalPort()); + ProfileVtunOptionsWidget->PortSpinbox->setValue(it->getLocalPort()); + ProfileUserOptionsWidget->UsernameLineEdit->setEnabled(true); + ProfileNetworkVirtualIpOptionsWidget->setEnabled( true ); + ProfileNetworkVirtualIpOptionsWidget->SourceIpgroupBox->hide(); + ProfileNetworkVirtualIpOptionsWidget->UseVirtualIPCheckBox->setEnabled( true ); + ProfileNetworkVirtualIpOptionsWidget->UseVirtualIPCheckBox->setChecked( it->getUseVirtualIP() ); + ProfileNetworkVirtualIpOptionsWidget->RemoteVirtualIpLineEdit->setText( it->getRemoteVirtualIP() ); + ProfileNetworkVirtualIpOptionsWidget->LocalVirtualIpEdit->setText( it->getLocalVirtualIP() ); + + ProfileNetworkGeneralOptionsWidget->TunnelDeviceTypeComboBox->setEnabled(true); + ProfileNetworkGeneralOptionsWidget->TunnelDeviceTypeLabel->setEnabled(true); + + ProfileCertOptionsWidget->setEnabled(false); + ProfileCiscoOptionsWidget->setEnabled(false); + ProfileIpsecOptionsWidget->setEnabled(false); + ProfileRacoonOptionsWidget->setEnabled(false); + ProfileOpenvpnOptionsWidget->setEnabled(false); + ProfilePptpOptionsWidget->setEnabled(false); + ProfileVtunOptionsWidget->setEnabled(false); + ProfileSshOptionsWidget->setEnabled(true); + + ProfileUserOptionsWidget->HideGroupPasswordInAccountDataDialogCheckBox->hide(); + + ProfileSshOptionsWidget->UseUserdefinedRemotePortCheckBox->setChecked(it->getUseRemotePort( ) ); + ProfileSshOptionsWidget->UserdefinedRemotePortSpinBox->setValue(it->getRemotePort ( ) ); + + ProfileNetworkVirtualIpOptionsWidget->SourceIpgroupBox->hide(); + + ProfileNetworkGeneralOptionsWidget->LabelRemoteNetwork->hide(); + ProfileNetworkGeneralOptionsWidget->RemoteNetMaskComboBox->hide(); + ProfileNetworkGeneralOptionsWidget->RemoteNetAddrLineEdit->hide(); + ProfileNetworkGeneralOptionsWidget->RemoteNetDividetextLabel->hide(); + ProfileNetworkGeneralOptionsWidget->UseRemoteNetworkCheckBox->hide(); + + if (it->getAuthWithUsernameAndPassword()) + { +// KMessageBox::information(0,"auth pass",Name); + ProfileSshOptionsWidget->AuthPassRadioButton->setChecked(true); + ProfileSshOptionsWidget->AuthKeyRadioButton->setChecked(false); +// ProfileSshOptionsWidget->SshkeyButtonGroup->setEnabled(false); + ProfileUserOptionsWidget->PasswordEdit->setEnabled(true); + } + else + { +// KMessageBox::information(0,"auth key",Name); + ProfileSshOptionsWidget->SshKeyComboBox->setEnabled(true); + ProfileSshOptionsWidget->AuthPassRadioButton->setChecked(false); + ProfileSshOptionsWidget->AuthKeyRadioButton->setChecked(true); +// ProfileSshOptionsWidget->SshkeyButtonGroup->setEnabled(true); + ProfileUserOptionsWidget->PasswordEdit->setEnabled(false); + + if (it->getPskIsInFile()) + { + ProfileSshOptionsWidget->CostumkeyURLRequester->setURL(it->getPreSharedKeyFile()); + ProfileSshOptionsWidget->CostumKeyRadioButton->setChecked(true); + ProfileSshOptionsWidget->AutoKeyRadioButton->setChecked(false); + } + else + { + ProfileSshOptionsWidget->CostumKeyRadioButton->setChecked(false); + ProfileSshOptionsWidget->AutoKeyRadioButton->setChecked(true); + if (!it->getPreSharedKey().isEmpty()) + ProfileSshOptionsWidget->SshKeyComboBox->setCurrentText(it->getPreSharedKey()); + } + ProfileSshOptionsWidget->sshAuthToggled(true); + } + + ProfileNetworkVirtualIpOptionsWidget->LocalVirtualIpEdit->setText( it->getLocalVirtualIP() ); + ProfileNetworkVirtualIpOptionsWidget->RemoteVirtualIpLineEdit->setText( it->getRemoteVirtualIP() ); + ProfileNetworkVirtualIpOptionsWidget->UseVirtualIPCheckBox->setChecked(it->getUseVirtualIP()); + + if (it->getUseVirtualIP()) + { + ProfileNetworkVirtualIpOptionsWidget->LocalVirtualIpEdit->setEnabled(true); + ProfileNetworkVirtualIpOptionsWidget->RemoteVirtualIpLineEdit->setEnabled(true); + tunnelDeviceTypeChanged(it->getTunnelDeviceType()); + } + else + { + ProfileNetworkVirtualIpOptionsWidget->LocalVirtualIpEdit->setEnabled(false); + ProfileNetworkVirtualIpOptionsWidget->RemoteVirtualIpLineEdit->setEnabled(false); + } + + if (it->getUseSshConfigRemoteScript() && !it->getSshConfigRemoteScript().isEmpty()) + { + ProfileSshOptionsWidget->UseSshConfigRemoteScriptCheckBox->setChecked(true); + ProfileSshOptionsWidget->SshConfigRemoteScriptLineEdit->setText(it->getSshConfigRemoteScript()); + } + + } // ssh + + /* all types */ + + ProfileNetworkVirtualIpOptionsWidget->UseVirtualIPCheckBox->setChecked( it->getUseVirtualIP() ); + ProfileNetworkVirtualIpOptionsWidget->UseVirtualIPCheckBox->setEnabled( true ); + + // ProfileNetworkNatOptionsWidget->UseUdpCheckbox->setChecked(it->getUseUdp()); + // ProfileNetworkNatOptionsWidget->UdpPortSpinbox->setValue(it->getUdpPort()); + // if (it->getUseUdpPort() ) + // ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setChecked(true); + // else + // ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setChecked(false); + + + ProfileNetworkNatOptionsWidget->UseUdpCheckbox->setEnabled( true ); + ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setEnabled( true ); + if ( it->getUseUdp() ) + ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setEnabled( true ); + else + ProfileNetworkNatOptionsWidget->UdpPortCheckbox->setEnabled( false ); + + + ProfileCertOptionsWidget->ImportCertificatePushButton->setEnabled( true ); + + ProfileCiscoOptionsWidget->IDLineEdit->setEnabled( false ); + ProfileCiscoOptionsWidget->LabelID->setEnabled( false ); + ProfileUserOptionsWidget->UsernameLineEdit->setEnabled(true); + + + if ( it->getConnectionType() == VpnAccountData::l2tpd_freeswan || it->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { + ProfilePptpOptionsWidget->L2tpDaemonComboBox->setEnabled(true); + if (it->getL2tpDaemon() == VpnAccountData::l2tpd ) + ProfilePptpOptionsWidget->L2tpDaemonComboBox->setCurrentItem(0); // l2tpd + else + ProfilePptpOptionsWidget->L2tpDaemonComboBox->setCurrentItem(1); //openl2tp + } + else + { + ProfilePptpOptionsWidget->L2tpDaemonComboBox->setEnabled(false); + } + + if ( it->getReplaceDefaultRoute() == false ) + ProfileNetworkRouteOptionsWidget->DefaultRouteComboBox->setCurrentItem( 0 ); + else + ProfileNetworkRouteOptionsWidget->DefaultRouteComboBox->setCurrentItem( 1 ); + + ProfileSmartcardOptionsWidget->UseSmartcardCheckBox->setChecked( it->getUseSmartcard() ); + + ProfileCmdExecBeforeConnectOptionsWidget->ExcuteCmdBeforeConnectCheckBox->setChecked( it->getExecuteCmdBeforeConnect() ); + ProfileCmdExecAfterConnectOptionsWidget->ExcuteCmdAfterConnectCheckBox->setChecked( it->getExecuteCmdAfterConnect() ); + ProfileCmdExecBeforeDisconnectOptionsWidget->ExcuteCmdBeforeDisconnectCheckBox->setChecked( it->getExecuteCmdBeforeDisconnect() ); + ProfileCmdExecAfterDisconnectOptionsWidget->ExcuteCmdAfterDisconnectCheckBox->setChecked( it->getExecuteCmdAfterDisconnect() ); + ProfileCmdExecBeforeConnectOptionsWidget->CmdBeforeConnectTextEdit->setText( it->getCommandBeforeConnect() ); + ProfileCmdExecAfterConnectOptionsWidget->CmdAfterConnectTextEdit->setText( it->getCommandAfterConnect() ); + ProfileCmdExecBeforeDisconnectOptionsWidget->CmdBeforeDisconnectTextEdit->setText ( it->getCommandBeforeDisconnect() ); + ProfileCmdExecAfterDisconnectOptionsWidget->CmdAfterDisconnectTextEdit->setText ( it->getCommandAfterDisconnect() ); + ProfileCmdExecBeforeConnectOptionsWidget->CmdBeforeConnectTextEdit->setEnabled( it->getExecuteCmdBeforeConnect() ); + ProfileCmdExecAfterConnectOptionsWidget->CmdAfterConnectTextEdit->setEnabled( it->getExecuteCmdAfterConnect() ); + ProfileCmdExecBeforeDisconnectOptionsWidget->CmdBeforeDisconnectTextEdit->setEnabled( it->getExecuteCmdBeforeDisconnect() ); + ProfileCmdExecAfterDisconnectOptionsWidget->CmdAfterDisconnectTextEdit->setEnabled( it->getExecuteCmdAfterDisconnect() ); + ProfileCmdExecAfterConnectOptionsWidget->CommandAfterConnectDelayTimeNumInput->setValue(it->getCommandAfterConnectDelayTime()); + + if ( GlobalConfig->currentProfile->getDoPingIP() ) + ProfileNetworkGeneralOptionsWidget->PingIPLineEdit->setEnabled( true ); + else + ProfileNetworkGeneralOptionsWidget->PingIPLineEdit->setEnabled( false ); + + ProfileCertOptionsWidget->AllowEmptyPrivateKeyPasswordCheckBox->setChecked(it->getAllowEmptyPrivateKeyPassword()); + ProfileOpenvpnOptionsWidget->AllowIpAddressChangeOfPeerCheckBox->setChecked(it->getAllowIpAddressChangeOfPeer()); + + ProfileNetworkGeneralOptionsWidget->PingIPLineEdit->setText( GlobalConfig->currentProfile->getPingHostIP() ); + ProfileNetworkGeneralOptionsWidget->PingCheckBox ->setChecked( GlobalConfig->currentProfile->getDoPingIP() ); + ProfileNetworkGeneralOptionsWidget->UseConnectionStatusCheckCheckBox->setChecked( GlobalConfig->currentProfile->getUseConnectionStatusCheck() ); + ProfileNetworkGeneralOptionsWidget->ConnectionStatusSuccessCountNumInput->setValue( GlobalConfig->currentProfile->getConnectionStatusCheckSuccessCount() ); + ProfileNetworkGeneralOptionsWidget->ConnectionStatusCheckIntervalNumInput->setValue( GlobalConfig->currentProfile->getConnectionStatusInterval() ); + ProfileNetworkGeneralOptionsWidget->DoReconnectAfterConnectionLostCheckBox->setChecked( GlobalConfig->currentProfile->getDoReconnectAfterConnectionLost() ); + ProfileNetworkGeneralOptionsWidget->UseDnsUpdateCheckBox->setChecked( GlobalConfig->currentProfile->getUseDnsUpdate() ); + + ProfileNetworkRouteOptionsWidget->UseExtraNetworkRoutesCheckbox->setChecked( it->getUseAdditionalNetworkRoutes() ); + QStringList AdditionalNetworkRoutes = it->getAdditionalNetworkRoutes(); + // example entry: + // /# + + for ( QStringList::Iterator it2 = AdditionalNetworkRoutes.begin() ; it2 != AdditionalNetworkRoutes.end(); ++it2 ) + { + QString networkstring = *it2; + QString Network = networkstring.section( '#', 0, 0 ).section( '/', 0, 0 ); + QString Netmask = networkstring.section( '#', 0, 0 ).section( '/', 1, 1 ); + QString Gateway = networkstring.section( '#', 1, 1 ).section( '/', 0, 0 ); + QString Interface = networkstring.section( '#', 2, 2 ); + + ProfileNetworkRouteOptionsWidget->NetworkListView->insertItem( new QListViewItem( ProfileNetworkRouteOptionsWidget->NetworkListView, Network, Netmask, Gateway, Interface ) ); + + ProfileNetworkRouteOptionsWidget->checkList(); + + } + + ProfileNetworkGeneralOptionsWidget->RemoteNetAddrLineEdit->setText( it->getRemoteNetAddr() ); + if ( !it->getRemoteNetMask().isEmpty() ) + ProfileNetworkGeneralOptionsWidget->RemoteNetMaskComboBox->setCurrentText( it->getRemoteNetMask() ); + + connectionTypeChanged( ProfileGeneralOptionsWidget->ConnectionTypeComboBox->currentItem() ); +// ProfileCertOptionsWidget->AuthTypeComboBox->setCurrentItem( it->getAuthType() ); +// ProfilePskOptionsWidget->AuthTypeComboBox->setCurrentItem( it->getAuthType() ); + ProfileCertOptionsWidget->x509certURLRequester->setFilter( "*.pem *.crt *.der" ); + ProfileCertOptionsWidget->certpathURLRequester->setMode( KFile::Directory ); + + + ProfileSmartcardOptionsWidget->UsePkcs11ProvidersCheckBox->setChecked(it->getUsePkcs11Providers()); + + + if (!it->getPkcs11Id().isEmpty()) + ProfileSmartcardOptionsWidget->Pkcs11IdComboBox->insertItem(it->getPkcs11Id()); + if (!it->getPkcs11Slot().isEmpty()) + ProfileSmartcardOptionsWidget->Pkcs11SlotComboBox->insertItem(it->getPkcs11Slot()); + +// QString Pkcs11SlotType = it->getPkcs11SlotType(); +// if (Pkcs11SlotType == "id") +// ProfileSmartcardOptionsWidget->Pkcs11SlotTypeComboBox->setCurrentText(i18n("ID")); +// else if (Pkcs11SlotType == "name") +// ProfileSmartcardOptionsWidget->Pkcs11SlotTypeComboBox->setCurrentText(i18n("Name")); +// else +// ProfileSmartcardOptionsWidget->Pkcs11SlotTypeComboBox->setCurrentText(i18n("Label")); + ProfileSmartcardOptionsWidget->Pkcs11SlotTypeComboBox->setCurrentText(i18n("ID")); + ProfileSmartcardOptionsWidget->Pkcs11SlotTypeComboBox->setEnabled(false); + ProfileSmartcardOptionsWidget->Pkcs11SlotTypeLabel->setEnabled(false); + + QString Pkcs11IdType = it->getPkcs11IdType(); + if (Pkcs11IdType == "id") + ProfileSmartcardOptionsWidget->Pkcs11IdTypeComboBox->setCurrentText(i18n("ID")); + else if (Pkcs11IdType == "label") + ProfileSmartcardOptionsWidget->Pkcs11IdTypeComboBox->setCurrentText(i18n("Label")); + else + ProfileSmartcardOptionsWidget->Pkcs11IdTypeComboBox->setCurrentText(i18n("Subject")); + +// ProfileSmartcardOptionsWidget->Pkcs11IdTypeComboBox->setCurrentText(i18n("ID")); +// ProfileSmartcardOptionsWidget->Pkcs11IdTypeComboBox->setEnabled(false); + + QString Pkcs11SignMode = it->getPkcs11SignMode(); + if (Pkcs11SignMode == "auto") + ProfileSmartcardOptionsWidget->Pkcs11SignModeComboBox->setCurrentText(i18n("auto")); + else if (Pkcs11SignMode == "sign") + ProfileSmartcardOptionsWidget->Pkcs11SignModeComboBox->setCurrentText(i18n("sign")); + else if (Pkcs11SignMode == "recover") + ProfileSmartcardOptionsWidget->Pkcs11SignModeComboBox->setCurrentText(i18n("recover")); + else + ProfileSmartcardOptionsWidget->Pkcs11SignModeComboBox->setCurrentText(i18n("any")); + + ProfileSmartcardOptionsWidget->Pkcs11ProvidersURLRequester->setURL(it->getPkcs11Providers()); + +// authTypeChanged(it->getAuthType()); + + } + else + { + // ProfileGeneralOptionsWidget->ProfileComboBox->setCurrentText( "" ); + // ProfileNetworkRouteOptionsWidget->ProfileComboBox->setCurrentText( "" ); + // ProfileNetworkNatOptionsWidget->ProfileComboBox->setCurrentText( "" ); + // ProfileNetworkVirtualIpOptionsWidget->ProfileComboBox->setCurrentText( "" ); + // ProfileCertPskOptionsWidget->ProfileComboBox->setCurrentText( "" ); + // ProfileUserOptionsWidget->ProfileComboBox->setCurrentText( "" ); + // ProfileOpenvpnOptionsWidget->ProfileComboBox->setCurrentText( "" ); + // ProfilePptpOptionsWidget->ProfileComboBox->setCurrentText( "" ); + // ProfileRacoonOptionsWidget->ProfileComboBox->setCurrentText( "" ); + // ProfileCiscoOptionsWidget->ProfileComboBox->setCurrentText( "" ); + // ProfileCmdExecBeforeConnectOptionsWidget->ProfileComboBox->setCurrentText( "" ); + // ProfileCmdExecBeforeDisconnectOptionsWidget->ProfileComboBox->setCurrentText( "" ); + // ProfileCmdExecAfterConnectOptionsWidget->ProfileComboBox->setCurrentText( "" ); + // ProfileCmdExecAfterDisconnectOptionsWidget->ProfileComboBox->setCurrentText( "" ); + + ProfileGeneralOptionsWidget->setEnabled( false ); + ProfileNetworkRouteOptionsWidget->setEnabled( false ); + ProfileNetworkNatOptionsWidget->setEnabled( false ); + ProfileNetworkVirtualIpOptionsWidget->setEnabled( false ); + ProfileCertOptionsWidget->setEnabled( false ); + ProfilePskOptionsWidget->setEnabled( false ); + ProfileUserOptionsWidget->setEnabled( false ); + ProfileOpenvpnOptionsWidget->setEnabled( false ); + ProfilePptpOptionsWidget->setEnabled( false ); + ProfileRacoonOptionsWidget->setEnabled( false ); + ProfileCiscoOptionsWidget->setEnabled( false ); + ProfileSshOptionsWidget->setEnabled( false ); + ProfileCmdExecBeforeConnectOptionsWidget->setEnabled( false ); + ProfileCmdExecBeforeDisconnectOptionsWidget->setEnabled( false ); + ProfileCmdExecAfterConnectOptionsWidget->setEnabled( false ); + ProfileCmdExecAfterDisconnectOptionsWidget->setEnabled( false ); + ProfileGeneralOptionsWidget->NewSessionPushButton->setEnabled( true ); + + } +} + +void PreferencesDialog::saveSessionClicked() +{ + if ( !showOnlyProfiles ) + { + GlobalConfig->pathToVpnc =ConfigDaemonOptionsWidget->VpncPathInput->url(); + GlobalConfig->pathToIpsec =ConfigDaemonOptionsWidget->FreeswanPathInput->url(); + GlobalConfig->pathToRacoon =ConfigDaemonOptionsWidget->RacoonPathInput->url(); + + if (ConfigDaemonOptionsWidget->PptpLogLevelComboBox->currentText() == "low" ) + GlobalConfig->PptpLogLevel = 0; + else if (ConfigDaemonOptionsWidget->PptpLogLevelComboBox->currentText() == "default" ) + GlobalConfig->PptpLogLevel = 1; + else if (ConfigDaemonOptionsWidget->PptpLogLevelComboBox->currentText() == "high" ) + GlobalConfig->PptpLogLevel = 2; + + if (ConfigDaemonOptionsWidget->PppdKernelLogLevelComboBox->currentText() ==i18n("none") ) + GlobalConfig->PppdKernelLogLevel =0; + if (ConfigDaemonOptionsWidget->PppdKernelLogLevelComboBox->currentText() ==i18n("general") ) + GlobalConfig->PppdKernelLogLevel =1; + if (ConfigDaemonOptionsWidget->PppdKernelLogLevelComboBox->currentText() ==i18n("general + packets") ) + GlobalConfig->PppdKernelLogLevel =4; + + GlobalConfig->pathToPppd =ConfigDaemonOptionsWidget->PppdPathInput->url(); + GlobalConfig->pathToPptp =ConfigDaemonOptionsWidget->PptpPathInput->url(); + GlobalConfig->pathToOpenvpn =ConfigDaemonOptionsWidget->OpenvpnPathInput->url(); + GlobalConfig->pathToVtund =ConfigDaemonOptionsWidget->VtundPathInput->url(); + GlobalConfig->pathToSsh =ConfigDaemonOptionsWidget->SshPathInput->url(); + + + GlobalConfig->pathToIptables = HelperProgramOptionsWidget->IptablesPathInput->url(); + GlobalConfig->pathToOpenssl = HelperProgramOptionsWidget->OpenSSLPathInput->url(); + GlobalConfig->pathToKill = HelperProgramOptionsWidget->KillPathInput->url(); + GlobalConfig->pathToKillall = HelperProgramOptionsWidget->KillallPathInput->url(); + GlobalConfig->pathToPing = HelperProgramOptionsWidget->PingPathInput->url(); + GlobalConfig->pathToIp = HelperProgramOptionsWidget->IpPathInput->url(); + GlobalConfig->pathToIfconfig = HelperProgramOptionsWidget->IfconfigPathInput->url(); + GlobalConfig->pathToRoute = HelperProgramOptionsWidget->RoutePathInput->url(); + GlobalConfig->pathToPkcs11Tool = HelperProgramOptionsWidget->Pkcs11ToolPathInput->url(); + + GlobalConfig->minimizeAfterConnect = ConnectOptionsWidget->checkMinimizeAfterConnectCheck->isChecked(); + GlobalConfig->showDebugConsole = DebugOptionsWidget->showDebugCheck->isChecked(); + GlobalConfig->writeLogFile = DebugOptionsWidget->WriteLogCheck->isChecked(); + GlobalConfig->KvpncDebugLevel = DebugOptionsWidget->spinKvpncDebugLevel->value (); + GlobalConfig->RacoonDebugLevel =ConfigDaemonOptionsWidget->RacoonDebugLevelComboBox->currentText (); + GlobalConfig->VpncDebugLevel =ConfigDaemonOptionsWidget->spinVpncDebugLevel->value (); + GlobalConfig->OpenvpnDebugLevel =ConfigDaemonOptionsWidget->spinOpenvpnDebugLevel->value () + 1; + GlobalConfig->SshDebugLevel =ConfigDaemonOptionsWidget->spinSshDebugLevel->value (); + GlobalConfig->enableDebugPppd =ConfigDaemonOptionsWidget->DebugPppdcheckBox->isChecked(); + GlobalConfig->enableDebugPptpd =ConfigDaemonOptionsWidget->DebugPptpdcheckBox->isChecked(); + + GlobalConfig->enableDebugXl2tpdtunnel = ConfigDaemonOptionsWidget->EnableDebugXl2tpdtunnelCheckBox->isChecked( ); + GlobalConfig->enableDebugXl2tpdstate = ConfigDaemonOptionsWidget->EnableDebugXl2tpdstateCheckBox ->isChecked( ); + GlobalConfig->enableDebugXl2tpdpacket = ConfigDaemonOptionsWidget->EnableDebugXl2tpdpacketCheckBox->isChecked( ); + GlobalConfig->enableDebugXl2tpdNetwork = ConfigDaemonOptionsWidget->EnableDebugXl2tpdNetworkCheckBox->isChecked( ); + + GlobalConfig->enableDebugOpenl2tp = ConfigDaemonOptionsWidget->DebugOpenl2tpCheckBox->isChecked( ); + + GlobalConfig->PlutoDebug.clear(); + if (ConfigDaemonOptionsWidget->IpsecRawDebugCheckBox->isChecked()) + GlobalConfig->PlutoDebug.append("raw"); + if (ConfigDaemonOptionsWidget->IpsecCryptDebugCheckBox->isChecked()) + GlobalConfig->PlutoDebug.append("crypt"); + if (ConfigDaemonOptionsWidget->IpsecParsingDebugCheckBox->isChecked()) + GlobalConfig->PlutoDebug.append("parsing"); + if (ConfigDaemonOptionsWidget->IpsecEmittingDebugCheckBox->isChecked()) + GlobalConfig->PlutoDebug.append("emitting"); + if (ConfigDaemonOptionsWidget->IpsecControlDebugCheckBox->isChecked()) + GlobalConfig->PlutoDebug.append("control"); + if (ConfigDaemonOptionsWidget->IpsecKlipsDebugCheckBox->isChecked()) + GlobalConfig->PlutoDebug.append("klips"); + if (ConfigDaemonOptionsWidget->IpsecPrivateDebugCheckBox->isChecked()) + GlobalConfig->PlutoDebug.append("private"); + + GlobalConfig->KlipsDebug.clear(); + if (ConfigDaemonOptionsWidget->KlipsDebugTunnel_xmitCheckBox->isChecked()) + GlobalConfig->KlipsDebug.append("tunnel-xmit"); + if (ConfigDaemonOptionsWidget->KlipsDebugPfkeyCheckBox->isChecked()) + GlobalConfig->KlipsDebug.append("pfkey"); + if (ConfigDaemonOptionsWidget->KlipsDebugXformCheckBox->isChecked()) + GlobalConfig->KlipsDebug.append("xform"); + if (ConfigDaemonOptionsWidget->KlipsDebugErouteCheckBox->isChecked()) + GlobalConfig->KlipsDebug.append("eroute"); + if (ConfigDaemonOptionsWidget->KlipsDebugSpiCheckBox->isChecked()) + GlobalConfig->KlipsDebug.append("spi"); + if (ConfigDaemonOptionsWidget->KlipsDebugRadijCheckBox->isChecked()) + GlobalConfig->KlipsDebug.append("radij"); + if (ConfigDaemonOptionsWidget->KlipsDebugEspCheckBox->isChecked()) + GlobalConfig->KlipsDebug.append("esp"); + if (ConfigDaemonOptionsWidget->KlipsDebugAhCheckBox->isChecked()) + GlobalConfig->KlipsDebug.append("ah"); + if (ConfigDaemonOptionsWidget->KlipsDebugIpcompCheckBox->isChecked()) + GlobalConfig->KlipsDebug.append("ipcomp"); + if (ConfigDaemonOptionsWidget->KlipsDebugVerboseCheckBox->isChecked()) + GlobalConfig->KlipsDebug.append("verbose"); + + GlobalConfig->tryConnectTimeout = ProfileCiscoOptionsWidget->PeerTimeoutIntNumInput->value(); + GlobalConfig->useSilentQuit = ConnectOptionsWidget->SilentQuitcheckBox->isChecked(); + GlobalConfig->dontQuitOnCloseEvent = GeneralOptionsWidget->DontQuitOnCloseEventCheckBox->isChecked(); + GlobalConfig->hideMainWindow = GeneralOptionsWidget->HideOnStartupCheckBox->isChecked (); + GlobalConfig->useKwallet = GeneralOptionsWidget->useKwalletCheckBox->isChecked(); + GlobalConfig->programsInPath =ConfigDaemonOptionsWidget->ProgramsInPathcheckBox->isChecked(); + GlobalConfig->holdGeneratedScripts = DebugOptionsWidget->KeepConnectionFilesCheckBox->isChecked(); + GlobalConfig->InfoLogColor = LogOptionsWidget->InfoLogLabel->paletteBackgroundColor (); + GlobalConfig->RemoteLogColor = LogOptionsWidget->RemoteLogLabel->paletteBackgroundColor (); + GlobalConfig->ErrorLogColor = LogOptionsWidget->ErrorLogLabel->paletteBackgroundColor (); + GlobalConfig->SuccessLogColor = LogOptionsWidget->SuccessLogLabel->paletteBackgroundColor (); + GlobalConfig->DebugLogColor = LogOptionsWidget->DebugLogLabel->paletteBackgroundColor (); + GlobalConfig->useColorizedLogOutput = LogOptionsWidget->UseColorizedLogOutputcheckBox->isChecked(); + GlobalConfig->showInterfaceIPinTooltip =ConfigDaemonOptionsWidget->ShowInterfaceIPinTooltipCheckBox->isChecked(); + GlobalConfig->doAutoConnectAtStartup = ConnectOptionsWidget->DoAutoConnectCheckBox->isChecked(); + GlobalConfig->LogViewerFontSize = LogOptionsWidget->LogFontSizeSpinBox->value(); + GlobalConfig->doKillL2tpdIfStillRunning =ConfigDaemonOptionsWidget->DoKillL2tpdIfStillRunningCheckBox->isChecked(); + GlobalConfig->doKillXl2tpdIfStillRunning =ConfigDaemonOptionsWidget->DoKillXl2tpdIfStillRunningCheckBox->isChecked(); + GlobalConfig->doKillRacoonIfStillRunning =ConfigDaemonOptionsWidget->DoKillRacoonIfStillRunningCheckBox->isChecked(); + } + + canAccept = true; + configChanged=true; + + + if ( GlobalConfig->currentProfile == 0 || GlobalConfig->AccountList->isEmpty()) + return ; + + GlobalConfig->appPointer->setOverrideCursor( QCursor( Qt::WaitCursor ) ); + + VpnAccountData *profile = GlobalConfig->currentProfile; + + //QString itemString=ConnectionTypeComboBox->currentText(); + int item = ProfileGeneralOptionsWidget->ConnectionTypeComboBox->currentItem() ; + GlobalConfig->currentProfile->setConnectionType( ( VpnAccountData::ConnectionType ) ( item ) ); + +// KMessageBox::information(0,"connection type changed: "+QString().setNum(item),QString("type set")); + + profile->setDescription( ProfileGeneralOptionsWidget->DescriptionLineEdit->text() ); + + // cisco + if ( item == VpnAccountData::cisco || item == VpnAccountData::ciscoorig ) + { + + // std::cout << "currentItem: " << ProfileGeneralOptionsWidget->ConnectionTypeComboBox->currentItem() << ", guessed type: cisco" << std::endl; + + if ( ProfileCertOptionsWidget->AuthTypeComboBox->currentText() == i18n( "X.509 Certificate" )) + profile->setAuthType(VpnAccountData::cert); + if ( ProfileCertOptionsWidget->AuthTypeComboBox->currentText() == i18n( "Pre Shared Key" )) + profile->setAuthType(VpnAccountData::psk); + if ( ProfileCertOptionsWidget->AuthTypeComboBox->currentText() == i18n( "Hybrid" )) + profile->setAuthType(VpnAccountData::hybrid); + + if ( ProfileUserOptionsWidget->CheckUserPass->isChecked() && ! ProfileUserOptionsWidget->UsernameLineEdit->text().isEmpty() ) + { + profile->setSaveUserPassword( true ); + profile->setUserPassword( ProfileUserOptionsWidget->UsernameLineEdit->text() ); + } + else + { + profile->setSaveUserPassword( false ); + } + + if ( ProfilePskOptionsWidget->CheckSavePsk->isChecked() && !ProfilePskOptionsWidget->PSKLineEdit->text().isEmpty() ) + { + profile->setSavePsk( true ); + profile->setPreSharedKey( ProfilePskOptionsWidget->PSKLineEdit->text() ); + } + else + { + profile->setSavePsk( false ); + } + profile->setAllowEmptyGroupPassword( ProfileCiscoOptionsWidget->AllowEmptyGroupPasswordCheckBox->isChecked() ); + profile->setUseXauthInteractive( ProfileCiscoOptionsWidget->UseXauthInteractiveCheckBox->isChecked() ); + profile->setUseGlobalIpsecSecret( ProfileCiscoOptionsWidget->UseGlobalIpsecSecretCheckbox->isChecked()); + profile->setID( ProfileCiscoOptionsWidget->IDLineEdit->text() ); + profile->setNtDomainName(ProfileUserOptionsWidget->NtDomainNameLineedit->text() ); + + if ( ProfileUserOptionsWidget->NtDomainNameCheckbox->isChecked() ) + { + profile->setNtDomainName( ProfileUserOptionsWidget->NtDomainNameLineedit->text() ); + profile->setUseNtDomainName( true ); + } + else + { + profile->setUseNtDomainName( false ); + } + + profile->setUseSearchDomainInResolvConf(ProfilePptpOptionsWidget->UseSearchDomainInResolvConfCheckbox->isChecked()); + profile->setUseDomainInResolvConf(ProfilePptpOptionsWidget->UseDomainInResolvConfCheckbox->isChecked()); + profile->setSearchDomainInResolvConf(ProfilePptpOptionsWidget->SearchDomainInResolvConfLineedit->text()); + profile->setDomainInResolvConf(ProfilePptpOptionsWidget->DomainInResolvConfLineedit->text()); + + profile->setUseLocalPort(ProfileCiscoOptionsWidget->LocalPortCheckbox->isChecked ( ) ); + profile->setLocalPort(ProfileCiscoOptionsWidget->LocalPortSpinbox->value( ) ); + + profile->setPeerTimeout( ProfileCiscoOptionsWidget->PeerTimeoutIntNumInput->value() ); + + + if (item == VpnAccountData::cisco) + { + profile->setDisableDataEncryption(ProfileCiscoOptionsWidget->DisableDataEncryptionCheckbox->isChecked()); + profile->setUseDpdIdleTimeout(ProfileCiscoOptionsWidget->EnableDpdIdleTimeoutCheckbox->isChecked()); + if ( profile->getAuthType() == VpnAccountData::hybrid) + { + profile->setCaCertificate(ProfileCertOptionsWidget->CaCertpathURLRequester->url()); + profile->setCertPath(ProfileCertOptionsWidget->certpathURLRequester->url()); + profile->setPrivateKeyPass( ProfileCertOptionsWidget->PrivkeyPasswordEdit->text()); + profile->setSavePrivateKeyPassword( ProfileCertOptionsWidget->SavePrivateKeyPasswordCheckBox->isChecked()); + } + } + + if ( item == VpnAccountData::ciscoorig) + { + if (profile->getAuthType() == VpnAccountData::cert || profile->getAuthType() == VpnAccountData::hybrid) + { + profile->setUseCiscoCertStore(ProfileCertOptionsWidget->UseCiscoCertStoreCheckBox->isChecked()); + if (ProfileCertOptionsWidget->UseCiscoCertStoreCheckBox->isChecked()) + { + profile->setX509Certificate( ProfileCertOptionsWidget->x509certComboBox->currentText()); + profile->setCaCertificate(ProfileCertOptionsWidget->CaCertpathComboBox->currentText()); + } + else + { + profile->setX509Certificate( ProfileCertOptionsWidget->x509certURLRequester->url()); + profile->setCaCertificate(ProfileCertOptionsWidget->CaCertpathURLRequester->url()); + profile->setCertPath(ProfileCertOptionsWidget->certpathURLRequester->url()); + } + profile->setPrivateKeyPass( ProfileCertOptionsWidget->PrivkeyPasswordEdit->text()); + profile->setSavePrivateKeyPassword( ProfileCertOptionsWidget->SavePrivateKeyPasswordCheckBox->isChecked()); + } + profile->setUseDpdIdleTimeout(true); + } + profile->setDpdIdleTimeout(ProfileCiscoOptionsWidget->DpdIdleTimeoutSpinbox->value()); + profile->setCiscoNatMode(ProfileCiscoOptionsWidget->CiscoNatModeComboBox->currentText()); + + + if ( ProfileCiscoOptionsWidget->ApplicationVersionCheckbox->isChecked() ) + { + profile->setApplicationVersion ( ProfileCiscoOptionsWidget->ApplicationVersionLineedit->text() ); + profile->setUseApplicationVersion ( true ); + } + else + { + profile->setUseApplicationVersion ( false ); + } + + if ( ProfileCiscoOptionsWidget->IkeGroupCheckbox->isChecked() ) + { + profile->setIkeGroup ( ProfileCiscoOptionsWidget->IkeGroupCombobox->currentText() ); + profile->setUseIkeGroup ( true ); + } + else + { + profile->setUseIkeGroup ( false ); + } + + if ( ProfileCiscoOptionsWidget->PerfectForwardSecurityCheckbox->isChecked() ) + { + profile->setPerfectForwardSecrety ( ProfileCiscoOptionsWidget->PerfectForwardSecrecyCombobox->currentText() ); + profile->setUsePerfectForwardSecrety ( true ); + } + else + { + profile->setUsePerfectForwardSecrety ( false ); + } + + + if ( ProfileCiscoOptionsWidget->SingleDesCheckbox->isChecked() ) + { + profile->setUseSingleDes ( true ); + } + else + { + profile->setUseSingleDes ( false ); + } + + + profile->setHideGroupPasswordInAccountDataDialog(ProfileUserOptionsWidget->HideGroupPasswordInAccountDataDialogCheckBox->isChecked()); + } + else if ( item == VpnAccountData::racoon || item == VpnAccountData::l2tpd_racoon || item == VpnAccountData::freeswan || item == VpnAccountData::l2tpd_freeswan ) + { + + bool validAddr = true; + + if (ProfileNetworkGeneralOptionsWidget->UseRemoteNetworkCheckBox->isChecked()) + { + if ( ProfileNetworkGeneralOptionsWidget->RemoteNetAddrLineEdit->text().contains( '.' ) != 3 ) + { + KMessageBox::error ( this, i18n( "No remote network entered!" ), i18n( "No remote network" ) ); + GlobalConfig->appendLogEntry( i18n( "No remote network entered!" ) , GlobalConfig->error ); + validAddr = false; + } + else + { + QString addr = ProfileNetworkGeneralOptionsWidget->RemoteNetAddrLineEdit->text(); + int part0 = addr.section( '.', 0, 0 ).toInt(); + int part1 = addr.section( '.', 1, 1 ).toInt(); + int part2 = addr.section( '.', 2, 2 ).toInt(); + int part3 = addr.section( '.', 3, 3 ).toInt(); + + /* + LogOutput->append ("part0: "+QString().setNum(part0)); + LogOutput->append ("part1: "+QString().setNum(part1)); + LogOutput->append ("part2: "+QString().setNum(part2)); + LogOutput->append ("part3: "+QString().setNum(part3)); + */ + if ( ( part0 < 1 || part0 > 254 ) || ( part1 < 0 || part1 > 254 ) || ( part2 < 0 || part2 > 254 ) || ( part3 < 0 || part3 > 254 ) ) + { + KMessageBox::error ( this, i18n( "IP address (remote net) is not valid!" ), i18n( "Invalid IP Address" ) ); + // GlobalConfig->appendLogEntry( i18n( "IP address (remote net) is not valid!" ) ,GlobalConfig->error); + canAccept = false; + validAddr = false; + } + if ( validAddr == true ) + { + profile->setUseRemoteNetwork(true); + profile->setRemoteNetAddr( addr ); + profile->setRemoteNetMask( ProfileNetworkGeneralOptionsWidget->RemoteNetMaskComboBox->currentText() ); + } + } + } + else + { + profile->setUseRemoteNetwork(false); + } + + if ( item == VpnAccountData::racoon || item == VpnAccountData::l2tpd_racoon) + { + if (ProfileRacoonOptionsWidget->RemoteIdTypeCombobox->currentText() != "none") + profile->setUseSpecialRemoteID( true ); + else + profile->setUseSpecialRemoteID( false ); + + if (ProfileRacoonOptionsWidget->LocalIdTypeCombobox->currentText() != "none") + profile->setUseSpecialLocalID( true ); + else + profile->setUseSpecialLocalID( false ); + + if ( ProfileCertOptionsWidget->AuthTypeComboBox->currentItem() == 0 ) + profile->setAuthType( VpnAccountData::cert ); + if ( ProfileCertOptionsWidget->AuthTypeComboBox->currentItem() == 1 ) + profile->setAuthType( VpnAccountData::psk ); + if ( ProfileCertOptionsWidget->AuthTypeComboBox->currentItem() == 2 ) + profile->setAuthType( VpnAccountData::hybrid ); + + if ( ProfilePskOptionsWidget->AuthTypeComboBox->currentItem() == 0 ) + profile->setAuthType( VpnAccountData::cert ); + if ( ProfilePskOptionsWidget->AuthTypeComboBox->currentItem() == 1 ) + profile->setAuthType( VpnAccountData::psk ); + if ( ProfilePskOptionsWidget->AuthTypeComboBox->currentItem() == 2 ) + profile->setAuthType( VpnAccountData::hybrid ); + + profile->setLocalIDType( ProfileRacoonOptionsWidget->LocalIdTypeCombobox->currentText()); + profile->setSpecialLocalID(ProfileRacoonOptionsWidget->LocalIDLineEdit->text()); + + profile->setRemoteIDType( ProfileRacoonOptionsWidget->RemoteIdTypeCombobox->currentText()); + profile->setSpecialRemoteID(ProfileRacoonOptionsWidget->RemoteIDLineEdit->text()); + + if (item == VpnAccountData::l2tpd_racoon) + { + if (ProfilePptpOptionsWidget->AuthMethodComboBox->currentItem() == 0) + profile->setAuthMethod("chap"); + if (ProfilePptpOptionsWidget->AuthMethodComboBox->currentItem() == 1) + profile->setAuthMethod("pap"); + if (ProfilePptpOptionsWidget->AuthMethodComboBox->currentItem() == 2) + profile->setAuthMethod("mschap"); + if (ProfilePptpOptionsWidget->AuthMethodComboBox->currentItem() == 3) + profile->setAuthMethod("mschap-v2"); + } + + // xauth + if (profile->getConnectionType() == VpnAccountData::racoon && ProfileRacoonOptionsWidget->UseXauthCheckBox->isChecked()) + { + if (ProfilePskOptionsWidget->CheckSavePsk->isChecked()) + { + QString Psk=ProfilePskOptionsWidget->PSKLineEdit->text(); + if (ProfilePskOptionsWidget->PskInFileCheckBox->isChecked()) + { + QString PskFileName = ProfilePskOptionsWidget->PSKFileURLRequester->url(); + QFile PskFile (PskFileName); + if (PskFile.open(IO_WriteOnly)) + { + QTextStream stream ( &PskFile ); + stream << Psk; + profile->setPskIsInFile(true); + profile->setSavePsk(true); + PskFile.close(); + } + else + { + profile->setSavePsk(false); + } + } + else + { + if (!Psk.isEmpty()) + { + profile->setPreSharedKey(Psk); + profile->setSavePsk(true); + } + } + } + profile->setAuthWithUsernameAndPassword(true); + profile->setUserName(ProfileUserOptionsWidget->UsernameLineEdit->text()); + if (ProfileUserOptionsWidget->CheckUserPass->isChecked()) + { + QString UserPassword = ProfileUserOptionsWidget->PasswordEdit->text(); + if (!UserPassword.isEmpty()) + { + profile->setUserPassword(UserPassword); + profile->setSaveUserPassword(true); + } + else + profile->setSaveUserPassword(false); + } + +// if ( ProfileIpsecOptionsWidget->LocalIDLineEdit->text().isEmpty() ) +// { +// KMessageBox::error ( this, i18n( "Local ID (Group ID) is empty!" ), i18n( "Local ID (Group ID) is empty" ) ); +// GlobalConfig->appendLogEntry( i18n( "Local ID (Group ID) is empty!" ) , GlobalConfig->error ); +// canAccept = false; +// } + + } + else + { + profile->setAuthWithUsernameAndPassword(false); + } + + if (GlobalConfig->currentProfile->getAuthType() == VpnAccountData::hybrid) + { + profile->setCaCertificate(ProfileCertOptionsWidget->CaCertpathURLRequester->url()); + profile->setVerifyCaCert(ProfileCertOptionsWidget->VerifyCaCertCheckBox->isChecked()); + profile->setAuthWithUsernameAndPassword(true); + profile->setUserName(ProfileUserOptionsWidget->UsernameLineEdit->text()); + if (ProfileUserOptionsWidget->CheckUserPass->isChecked()) + { + QString UserPassword = ProfileUserOptionsWidget->PasswordEdit->text(); + if (!UserPassword.isEmpty()) + { + profile->setUserPassword(UserPassword); + profile->setSaveUserPassword(true); + } + else + profile->setSaveUserPassword(false); + } + } + + profile->setUseModeConfig(ProfileRacoonOptionsWidget->UseModeConfigCheckBox->isChecked( ) ); + + profile->setUseLeftSourceIp(ProfileNetworkVirtualIpOptionsWidget->UseLeftSourceIpCheckBox->isChecked( )); + profile->setUseRightSourceIp(ProfileNetworkVirtualIpOptionsWidget->UseRightSourceIpCheckBox->isChecked()); + + if (ProfileNetworkVirtualIpOptionsWidget->UseLeftSourceIpCheckBox->isChecked( ) &&ProfileNetworkVirtualIpOptionsWidget->LeftSourceIpLineEdit->text().isEmpty() ) + { + KMessageBox::error ( this, i18n( "Local Source IP address is empty!" ), i18n( "Local Source IP empty" ) ); + GlobalConfig->appendLogEntry( i18n( "Local Source IP address is empty!" ) , GlobalConfig->error ); + canAccept = false; + } + else + profile->setLeftSourceIp(ProfileNetworkVirtualIpOptionsWidget->LeftSourceIpLineEdit->text()); + + if (ProfileNetworkVirtualIpOptionsWidget->UseRightSourceIpCheckBox->isChecked( ) &&ProfileNetworkVirtualIpOptionsWidget->RightSourceIpLineEdit->text().isEmpty() ) + { + KMessageBox::error ( this, i18n( "Remote Source IP address is empty!" ), i18n( "Remote Source IP empty" ) ); + GlobalConfig->appendLogEntry( i18n( "Remote Source IP address is empty!" ) , GlobalConfig->error ); + canAccept = false; + } + else + profile->setRightSourceIp(ProfileNetworkVirtualIpOptionsWidget->LeftSourceIpLineEdit->text()); + + } + if ( item == VpnAccountData::freeswan || item == VpnAccountData::l2tpd_freeswan) + { + + if (ProfileIpsecOptionsWidget->RemoteIdTypeCombobox->currentText() != "none") + profile->setUseSpecialRemoteID( true ); + else + profile->setUseSpecialRemoteID( false ); + + if (ProfileIpsecOptionsWidget->LocalIdTypeCombobox->currentText() != "none") + profile->setUseSpecialLocalID( true ); + else + profile->setUseSpecialLocalID( false ); + + if ( ProfileCertOptionsWidget->AuthTypeComboBox->currentItem() == 0 ) + profile->setAuthType( VpnAccountData::cert ); + if ( ProfileCertOptionsWidget->AuthTypeComboBox->currentItem() == 1 ) + profile->setAuthType( VpnAccountData::psk ); + + if ( ProfilePskOptionsWidget->AuthTypeComboBox->currentItem() == 0 ) + profile->setAuthType( VpnAccountData::cert ); + if ( ProfilePskOptionsWidget->AuthTypeComboBox->currentItem() == 1 ) + profile->setAuthType( VpnAccountData::psk ); + + profile->setDisableOpportunisticEncryption( ProfileIpsecOptionsWidget->DisableOpportunisticEncryptionCheckBox->isChecked( ) ); + if (ProfileIpsecOptionsWidget->IpsecVpnModeCombobox->currentText() == "transport" ) + profile->setIpsecVpnMode("transport"); + else + profile->setIpsecVpnMode("tunnel"); + + profile->setPrivateKey( ProfileCertOptionsWidget->privkeypathURLRequester->url() ); + profile->setPrivateKeyPass( ProfileCertOptionsWidget->PrivkeyPasswordEdit->text() ); + profile->setSaveUserPassword ( ProfileCertOptionsWidget->SavePrivateKeyPasswordCheckBox->isChecked() ); + + // ike + esp + QStringList IkeList; + QStringList EspList; + + if (ProfileIpsecOptionsWidget->IkeAes256Sha1CheckBox->isChecked()) + IkeList.append("aes256-sha1"); + if (ProfileIpsecOptionsWidget->IkeAes128Sha1CheckBox->isChecked()) + IkeList.append("aes128-sha1"); + if (ProfileIpsecOptionsWidget->IkeDesSha1Modp2048CheckBox->isChecked()) + IkeList.append("3des-sha1-modp2048"); + if (ProfileIpsecOptionsWidget->IkeDesMd5CheckBox->isChecked()) + IkeList.append("3des-md5"); + if (ProfileIpsecOptionsWidget->IkeDesSha1CheckBox->isChecked()) + IkeList.append("3des-sha1"); + + if (!ProfileIpsecOptionsWidget->OtherIkeLineEdit->text().isEmpty()) + IkeList.append(ProfileIpsecOptionsWidget->OtherIkeLineEdit->text()); + + if (ProfileIpsecOptionsWidget->Esp3desMd5CheckBox->isChecked()) + EspList.append("3des-md5"); + if (ProfileIpsecOptionsWidget->EspDesSha1CheckBox->isChecked()) + EspList.append("3des-sha1"); + if (ProfileIpsecOptionsWidget->EspAes128Sha1CheckBox->isChecked()) + EspList.append( "aes128-sha1"); + if (ProfileIpsecOptionsWidget->EspAes256Sha1CheckBox->isChecked()) + EspList.append( "aes256-sha1"); + + if (!ProfileIpsecOptionsWidget->OtherEspLineEdit->text().isEmpty()) + EspList.append(ProfileIpsecOptionsWidget->OtherEspLineEdit->text()); + + if(ProfileIpsecOptionsWidget->UseCustomIkeCheckBox->isChecked() && IkeList.isEmpty()) + { + KMessageBox::error ( this, i18n( "Use custom IKE checked but none selected!" ), i18n( "No custom IKE" ) ); + canAccept = false; + } + + if(ProfileIpsecOptionsWidget->UseCustomEspCheckBox->isChecked() && EspList.isEmpty()) + { + KMessageBox::error ( this, i18n( "Use custom ESP checked but none selected!" ), i18n( "No custom ESP" ) ); + canAccept = false; + } + + + + profile->setIpsecEsp(EspList.join(",")); + profile->setIpsecIke(IkeList.join(",")); + + for ( QStringList::Iterator ikeit = IkeList.begin(); ikeit != IkeList.end(); ++ikeit ) + std::cout << "ike: " << *ikeit << ":" << std::endl; + + for ( QStringList::Iterator espit = EspList.begin(); espit != EspList.end(); ++espit ) + std::cout << "esp: " << *espit << ":" << std::endl; + + if(ProfileIpsecOptionsWidget->UseCustomEspCheckBox->isChecked() && !EspList.isEmpty()) + profile->setUseCustomEsp(true); + else + profile->setUseCustomEsp(false); + + if(ProfileIpsecOptionsWidget->UseCustomIkeCheckBox->isChecked() && !IkeList.isEmpty()) + profile->setUseCustomIke(true); + else + profile->setUseCustomIke(false); + + if (item == VpnAccountData::l2tpd_freeswan) + { + if (ProfilePptpOptionsWidget->AuthMethodComboBox->currentItem() == 0) + profile->setAuthMethod("chap"); + if (ProfilePptpOptionsWidget->AuthMethodComboBox->currentItem() == 1) + profile->setAuthMethod("pap"); + if (ProfilePptpOptionsWidget->AuthMethodComboBox->currentItem() == 2) + profile->setAuthMethod("mschap"); + if (ProfilePptpOptionsWidget->AuthMethodComboBox->currentItem() == 3) + profile->setAuthMethod("mschap-v2"); + } + else + { + profile->setAuthWithUsernameAndPassword(ProfileIpsecOptionsWidget->UseXauthCheckBox->isChecked()); + profile->setUserName(ProfileUserOptionsWidget->UsernameLineEdit->text()); + + if (!ProfileUserOptionsWidget->PasswordEdit->text().isEmpty()) + profile->setUserPassword(ProfileUserOptionsWidget->PasswordEdit->text()); + } + +// if (ProfileIpsecOptionsWidget->ExchangeModeComboBox->currentItem() == 0) +// profile->setExchangeMode("main"); +// +// if (ProfileIpsecOptionsWidget->ExchangeModeComboBox->currentItem() == 1) +// profile->setExchangeMode("aggressive"); +// +// if (ProfileIpsecOptionsWidget->ExchangeModeComboBox->currentItem() == 2) +// profile->setExchangeMode("base"); + profile->setExchangeMode(ProfileIpsecOptionsWidget->ExchangeModeComboBox->currentText()); + + // xauth + if (profile->getConnectionType() == VpnAccountData::freeswan && ProfileIpsecOptionsWidget->UseXauthCheckBox->isChecked()) + { + if (ProfilePskOptionsWidget->CheckSavePsk->isChecked()) + { + QString Psk=ProfilePskOptionsWidget->PSKLineEdit->text(); + if (ProfilePskOptionsWidget->PskInFileCheckBox->isChecked()) + { + QString PskFileName = ProfilePskOptionsWidget->PSKFileURLRequester->url(); + QFile PskFile (PskFileName); + if (PskFile.open(IO_WriteOnly)) + { + QTextStream stream ( &PskFile ); + stream << Psk; + profile->setPskIsInFile(true); + profile->setSavePsk(true); + PskFile.close(); + } + else + { + profile->setSavePsk(false); + } + } + else + { + if (!Psk.isEmpty()) + { + profile->setPreSharedKey(Psk); + profile->setSavePsk(true); + } + } + } + profile->setAuthWithUsernameAndPassword(true); + profile->setUserName(ProfileUserOptionsWidget->UsernameLineEdit->text()); + if (ProfileUserOptionsWidget->CheckUserPass->isChecked()) + { + QString UserPassword = ProfileUserOptionsWidget->PasswordEdit->text(); + if (!UserPassword.isEmpty()) + { + profile->setUserPassword(UserPassword); + profile->setSaveUserPassword(true); + } + else + profile->setSaveUserPassword(false); + } + + if ( ProfileIpsecOptionsWidget->LocalIDLineEdit->text().isEmpty() ) + { + KMessageBox::error ( this, i18n( "Local ID (Group ID) is empty!" ), i18n( "Local ID (Group ID) is empty" ) ); + GlobalConfig->appendLogEntry( i18n( "Local ID (Group ID) is empty!" ) , GlobalConfig->error ); + canAccept = false; + } + + } + else + { + profile->setAuthWithUsernameAndPassword(false); + } + + profile->setUseLeftSourceIp(ProfileNetworkVirtualIpOptionsWidget->UseLeftSourceIpCheckBox->isChecked( )); + profile->setUseRightSourceIp(ProfileNetworkVirtualIpOptionsWidget->UseRightSourceIpCheckBox->isChecked()); + + if (ProfileNetworkVirtualIpOptionsWidget->UseLeftSourceIpCheckBox->isChecked( ) &&ProfileNetworkVirtualIpOptionsWidget->LeftSourceIpLineEdit->text().isEmpty() ) + { + KMessageBox::error ( this, i18n( "Local Source IP address is empty!" ), i18n( "Local Source IP empty" ) ); + GlobalConfig->appendLogEntry( i18n( "Local Source IP address is empty!" ) , GlobalConfig->error ); + canAccept = false; + } + else + profile->setLeftSourceIp(ProfileNetworkVirtualIpOptionsWidget->LeftSourceIpLineEdit->text()); + + profile->setUseVirtualIP(ProfileNetworkVirtualIpOptionsWidget->UseVirtualIPCheckBox->isChecked()); + profile->setLocalVirtualIP(ProfileNetworkVirtualIpOptionsWidget->LocalVirtualIpEdit->text()); + profile->setRemoteVirtualIP(ProfileNetworkVirtualIpOptionsWidget->RemoteVirtualIpLineEdit->text()); + + if (ProfileNetworkVirtualIpOptionsWidget->UseVirtualIPCheckBox->isChecked( ) &&ProfileNetworkVirtualIpOptionsWidget->RemoteVirtualIpLineEdit->text().isEmpty() ) + { + KMessageBox::error ( this, i18n( "Remote virtual IP address is empty!" ), i18n( "Remote virtual IP empty" ) ); + GlobalConfig->appendLogEntry( i18n( "Remote virtual IP address is empty!" ) , GlobalConfig->error ); + canAccept = false; + } + + + + } // freeswan + + + profile->setX509Certificate( ProfileCertOptionsWidget->x509certURLRequester->url() ); + profile->setCertPath( ProfileCertOptionsWidget->certpathURLRequester->url() ); + profile->setCaCertificate( ProfileCertOptionsWidget->CaCertpathURLRequester->url() ); + profile->setPrivateKey ( ProfileCertOptionsWidget->privkeypathURLRequester->url() ); + profile->setPrivateKeyPass ( ProfileCertOptionsWidget->PrivkeyPasswordEdit->text() ); + profile->setPreSharedKey( ProfilePskOptionsWidget->PSKLineEdit->text() ); + + if (ProfileNetworkVirtualIpOptionsWidget->UseRightSourceIpCheckBox->isChecked( ) &&ProfileNetworkVirtualIpOptionsWidget->RightSourceIpLineEdit->text().isEmpty() ) + { + KMessageBox::error ( this, i18n( "Remote Source IP address is empty!" ), i18n( "Remote Source IP empty" ) ); + GlobalConfig->appendLogEntry( i18n( "Remote Source IP address is empty!" ) , GlobalConfig->error ); + canAccept = false; + } + else + profile->setRightSourceIp(ProfileNetworkVirtualIpOptionsWidget->RightSourceIpLineEdit->text()); + + if (ProfileNetworkVirtualIpOptionsWidget->UseVirtualSubnetsCheckBox->isChecked()) + { + if(ProfileNetworkVirtualIpOptionsWidget->VirtualSubnetsLineEdit->text().isEmpty()) + { + KMessageBox::error ( this, i18n( "Virtual subnets are empty!" ), i18n( "Virtual subnets empty" ) ); + GlobalConfig->appendLogEntry( i18n( "Virtual subnets are empty!" ) , GlobalConfig->error ); + canAccept = false; + } + } + profile->setVirtualSubnetworks(ProfileNetworkVirtualIpOptionsWidget->VirtualSubnetsLineEdit->text()); //FIXME hacking subnets list from linedit! + profile->setUseVirtualSubnetworks(ProfileNetworkVirtualIpOptionsWidget->UseVirtualSubnetsCheckBox->isChecked()); + + if ( ProfileNetworkVirtualIpOptionsWidget->UseVirtualIPCheckBox->isChecked() && !ProfileNetworkVirtualIpOptionsWidget->LocalVirtualIpEdit->text().isEmpty() ) + { + // do check for vailid IP + if ( !Utils( GlobalConfig ).isValidIPv4Address( ProfileNetworkVirtualIpOptionsWidget->LocalVirtualIpEdit->text() ) ) + { + KMessageBox::error ( this, i18n( "No valid IP address entered!" ), i18n( "No Valid IP Address" ) ); + GlobalConfig->appendLogEntry( i18n( "No valid IP address entered!" ) , GlobalConfig->error ); + canAccept = false; + } + else + { + profile->setVirtualIP( ProfileNetworkVirtualIpOptionsWidget->LocalVirtualIpEdit->text() ); + profile->setUseVirtualIP( ProfileNetworkVirtualIpOptionsWidget->UseVirtualIPCheckBox->isChecked() ); + } + } + else + { + if ( ProfileNetworkVirtualIpOptionsWidget->UseVirtualIPCheckBox->isChecked()) + { + if( ProfileNetworkVirtualIpOptionsWidget->LocalVirtualIpEdit->text().isEmpty() && ProfileNetworkVirtualIpOptionsWidget->RemoteVirtualIpLineEdit->text().isEmpty()) + { + KMessageBox::error ( this, i18n( "No IP address (virtual IP) entered!" ), i18n( "No IP Address" ) ); + // GlobalConfig->appendLogEntry(i18n( "No IP address (virtual IP) entered!" ) ,GlobalConfig->error); + canAccept = false; + } + } + else + { + profile->setVirtualIP( "" ); + profile->setUseVirtualIP( false ); + } + } + + + + + if ( ProfileGeneralOptionsWidget->ConnectionTypeComboBox->currentItem() == VpnAccountData::racoon || + ProfileGeneralOptionsWidget->ConnectionTypeComboBox->currentItem() == VpnAccountData::l2tpd_racoon + ) + { + + // phase 1 + profile->setIpsecIke(ProfileRacoonOptionsWidget->EncryptionAlgorithmComboBox->currentText()); + profile->setHashAlgo( ProfileRacoonOptionsWidget->HashAlgoComboBox->currentText()); + profile->setUseAuthenticationAlgorithm(true); + profile->setIkeGroup( ProfileRacoonOptionsWidget->DHGroupComboBox->currentText() ); + + + profile->setEncryptionAlgorithm( ProfileRacoonOptionsWidget->EncryptionAlgorithm2ComboBox->currentText() ); + profile->setAuthenticationAlgorithm( ProfileRacoonOptionsWidget->AuthenticationAlgorithm2ComboBox->currentText() ); + + + if ( ProfileGeneralOptionsWidget->ConnectionTypeComboBox->currentItem() == VpnAccountData::l2tpd_racoon ) + { + profile->setUserName( ProfileUserOptionsWidget->UsernameLineEdit->text() ); + + if ( ProfileUserOptionsWidget->CheckUserPass->isChecked() ) + { + profile->setSaveUserPassword( true ); + profile->setUserPassword( ProfileUserOptionsWidget->PasswordEdit->text() ); + } + else + profile->setSaveUserPassword( true ); + } + + if ( ProfileRacoonOptionsWidget->IkeGroupCheckbox->isChecked() ) + { + profile->setIkeGroup ( ProfileRacoonOptionsWidget->DHGroupComboBox->currentText() ); + profile->setUseIkeGroup ( true ); + } + else + { + profile->setUseIkeGroup ( false ); + } + + if ( ProfileRacoonOptionsWidget->PerfectForwardSecurityCheckbox->isChecked() ) + { + profile->setPerfectForwardSecrety ( ProfileRacoonOptionsWidget->PerfectForwardSecrecyCombobox->currentText() ); + profile->setUsePerfectForwardSecrety ( true ); + } + else + { + profile->setUsePerfectForwardSecrety ( false ); + } + + +// if (ProfileRacoonOptionsWidget->UseSpecialLocalIDcheckBox->isChecked()) +// { +// profile->setSpecialLocalID(ProfileRacoonOptionsWidget->LocalIDLineEdit->text()); +// profile->setUseSpecialLocalID(true); +// } +// else +// { +// profile->setUseSpecialLocalID(false); +// } + profile->setLocalIDType( ProfileRacoonOptionsWidget->LocalIdTypeCombobox->currentText()); + profile->setSpecialLocalID(ProfileRacoonOptionsWidget->LocalIDLineEdit->text()); + profile->setRemoteIDType( ProfileRacoonOptionsWidget->RemoteIdTypeCombobox->currentText()); + profile->setSpecialRemoteID(ProfileRacoonOptionsWidget->RemoteIDLineEdit->text()); + + profile->setExchangeMode( ProfileRacoonOptionsWidget->ExchangeModeComboBox->currentText() ); + profile->setVerifyCaCert(ProfileCertOptionsWidget->VerifyCaCertCheckBox->isChecked()); + } + if ( ProfileGeneralOptionsWidget->ConnectionTypeComboBox->currentItem() == VpnAccountData::freeswan || + ProfileGeneralOptionsWidget->ConnectionTypeComboBox->currentItem() == VpnAccountData::l2tpd_freeswan + ) + { + + if ( ProfileGeneralOptionsWidget->ConnectionTypeComboBox->currentItem() == VpnAccountData::l2tpd_freeswan ) + { + profile->setUserName( ProfileUserOptionsWidget->UsernameLineEdit->text() ); + + if ( ProfileUserOptionsWidget->CheckUserPass->isChecked() ) + { + profile->setSaveUserPassword( true ); + profile->setUserPassword( ProfileUserOptionsWidget->PasswordEdit->text() ); + } + else + profile->setSaveUserPassword( true ); + } + + if ( ProfileIpsecOptionsWidget->PerfectForwardSecurityCheckbox->isChecked() ) + { + profile->setUsePerfectForwardSecrety ( true ); + } + else + { + profile->setUsePerfectForwardSecrety ( false ); + } + profile->setPerfectForwardSecrety( ProfileIpsecOptionsWidget->PerfectForwardSecrecyCombobox->currentText() ); + + if (ProfileIpsecOptionsWidget->RemoteIdTypeCombobox->currentText() != "none" && !ProfileIpsecOptionsWidget->RemoteIDLineEdit->text().isEmpty()) + { + profile->setUseSpecialRemoteID(true); + + } + else + profile->setUseSpecialRemoteID(false); + } + + + + if ( profile->getConnectionType() == VpnAccountData::l2tpd_freeswan || profile->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { + if (ProfilePptpOptionsWidget->L2tpDaemonComboBox->currentItem() == 0) + profile->setL2tpDaemon(VpnAccountData::l2tpd); + if (ProfilePptpOptionsWidget->L2tpDaemonComboBox->currentItem() == 1) + profile->setL2tpDaemon(VpnAccountData::openl2tp); + } + + } + else if ( item == VpnAccountData::pptp ) + { + + bool validAddr = true; + if ( !ProfileNetworkGeneralOptionsWidget->RemoteNetAddrLineEdit->text().isEmpty() ) + { + if ( ProfileNetworkGeneralOptionsWidget->RemoteNetAddrLineEdit->text().contains( '.' ) != 3 ) + { + //KMessageBox::error ( this, i18n( "No IP address entered!" ), i18n( "No IP Address" ) ); + validAddr = false; + } + else + { + QString addr = ProfileNetworkGeneralOptionsWidget->RemoteNetAddrLineEdit->text(); + int part0 = addr.section( '.', 0, 0 ).toInt(); + int part1 = addr.section( '.', 1, 1 ).toInt(); + int part2 = addr.section( '.', 2, 2 ).toInt(); + int part3 = addr.section( '.', 3, 3 ).toInt(); + + /* + LogOutput->append ("part0: "+QString().setNum(part0)); + LogOutput->append ("part1: "+QString().setNum(part1)); + LogOutput->append ("part2: "+QString().setNum(part2)); + LogOutput->append ("part3: "+QString().setNum(part3)); + */ + + if ( ( part0 < 1 || part0 > 254 ) || ( part1 < 0 || part1 > 254 ) || ( part2 < 0 || part2 > 254 ) || ( part3 < 0 || part3 > 254 ) ) + { + KMessageBox::error ( this, i18n( "Invalid values in IP address (remote net)!" ), i18n( "Invalid Values in IP Address" ) ); + GlobalConfig->appendLogEntry( i18n( "Invalid values in IP address (remote net)!" ) , GlobalConfig->error ); + validAddr = false; + } + + + if ( validAddr == true ) + { + profile->setRemoteNetAddr( addr ); + profile->setRemoteNetMask( ProfileNetworkGeneralOptionsWidget->RemoteNetMaskComboBox->currentText() ); + } + + } + } + else + { + profile->setRemoteNetAddr( "" ); + profile->setRemoteNetMask( "" ); + } + + // if (ProfileNetworkRouteOptionsWidget->DefaultRouteComboBox->currentText() == i18n("Keep default route")) + if ( ProfileNetworkRouteOptionsWidget->DefaultRouteComboBox->currentItem() == 0 ) + { + profile->setReplaceDefaultRoute( false ); + } + + profile->setAllowStatefulMode( ProfilePptpOptionsWidget->AllowStatefulModeCheckbox->isChecked() ); + profile->setUseNoIpDefault( ProfilePptpOptionsWidget->UseNoIpDefaultCheckbox->isChecked() ); + profile->setDisableMPPEComp( ProfilePptpOptionsWidget->UseNoMPPECompressionCheckbox->isChecked() ); + profile->setRequireMppe( ProfilePptpOptionsWidget->RequireMppeCheckbox->isChecked() ); + profile->setRefuse128BitEncryption( ProfilePptpOptionsWidget->Refuse128BitEncryptionCheckbox->isChecked() ); + profile->setRefuse40BitEncryption( ProfilePptpOptionsWidget->Refuse40BitEncryptionCheckbox->isChecked() ); + profile->setDisableMPPEComp( ProfilePptpOptionsWidget->UseNoMPPECompressionCheckbox->isChecked() ); + profile->setUseDnsServer( ProfilePptpOptionsWidget->DnsServerCheckbox->isChecked() ); + profile->setDnsServer( ProfilePptpOptionsWidget->DnsServerLineedit->text() ); + profile->setUseNoBsdComp( ProfilePptpOptionsWidget->UseNoBsdCompCheckbox->isChecked() ); + profile->setUseNoDeflate( ProfilePptpOptionsWidget->UseNoDeflateCheckbox->isChecked() ); + profile->setDisableHeaderCompression(ProfilePptpOptionsWidget->DisableHeaderCompressionCheckbox->isChecked()); + profile->setDisableMagicNumberNegotiation(ProfilePptpOptionsWidget->DisableMagicNumberNegotiationCheckbox->isChecked()); + profile->setDisableIpx(ProfilePptpOptionsWidget->DisableIpxCheckbox->isChecked()); + profile->setDisableAdressControlCompression(ProfilePptpOptionsWidget->DisableAdressControlCompressionCheckbox->isChecked()); + profile->setDisableProtocolFieldCompression(ProfilePptpOptionsWidget->DisableProtocolFieldCompressionCheckbox->isChecked()); + profile->setRequireEap(ProfilePptpOptionsWidget->RequireEapCheckbox->isChecked()); + + // if (ProfileNetworkRouteOptionsWidget->DefaultRouteComboBox->currentText() == i18n("Keep default route")) + + profile->setNtDomainName(ProfileUserOptionsWidget->NtDomainNameLineedit->text() ); + profile->setUseSearchDomainInResolvConf(ProfilePptpOptionsWidget->UseSearchDomainInResolvConfCheckbox->isChecked()); + profile->setUseDomainInResolvConf(ProfilePptpOptionsWidget->UseDomainInResolvConfCheckbox->isChecked()); + profile->setSearchDomainInResolvConf(ProfilePptpOptionsWidget->SearchDomainInResolvConfLineedit->text()); + profile->setDomainInResolvConf(ProfilePptpOptionsWidget->DomainInResolvConfLineedit->text()); + + if ( ProfileUserOptionsWidget->NtDomainNameCheckbox->isChecked() && !ProfileUserOptionsWidget->NtDomainNameLineedit->text().isEmpty() ) + { + profile->setNtDomainName( ProfileUserOptionsWidget->NtDomainNameLineedit->text() ); + profile->setUseNtDomainName( true ); + } + else + { + profile->setUseNtDomainName( false ); + } + if (ProfilePptpOptionsWidget->AuthMethodComboBox->currentItem() == 0) + profile->setAuthMethod("chap"); + if (ProfilePptpOptionsWidget->AuthMethodComboBox->currentItem() == 1) + profile->setAuthMethod("pap"); + if (ProfilePptpOptionsWidget->AuthMethodComboBox->currentItem() == 2) + profile->setAuthMethod("mschap"); + if (ProfilePptpOptionsWidget->AuthMethodComboBox->currentItem() == 3) + profile->setAuthMethod("mschap-v2"); + + bool IPOk=true; + if ( ProfileNetworkVirtualIpOptionsWidget->UseVirtualIPCheckBox->isChecked()) + { + QString LocalVirtualIp = ProfileNetworkVirtualIpOptionsWidget->LocalVirtualIpEdit->text(); + if (Utils( GlobalConfig ).isValidIPv4Address (LocalVirtualIp) == false) + { + KMessageBox::error ( this, i18n( "No valid IP address entered!" ), i18n( "No Valid IP Address" ) ); + IPOk=false; + } + else + { + profile->setLocalVirtualIP( LocalVirtualIp); + } + + QString RemoteVirtualIp = ProfileNetworkVirtualIpOptionsWidget->RemoteVirtualIpLineEdit->text(); + if (Utils( GlobalConfig ).isValidIPv4Address(RemoteVirtualIp) == false) + { + KMessageBox::error ( this, i18n( "No valid IP address entered!" ), i18n( "No Valid IP Address" ) ); + IPOk=false; + } + else + { + profile->setRemoteVirtualIP( RemoteVirtualIp); + } + } + if (IPOk ) + profile->setUseVirtualIP( ProfileNetworkVirtualIpOptionsWidget->UseVirtualIPCheckBox->isChecked()); + else + profile->setUseVirtualIP( false ); + + } + else if ( item == VpnAccountData::openvpn ) + { + + ProfileNetworkGeneralOptionsWidget->RemoteNetAddrLineEdit->setEnabled( false ); + ProfileNetworkGeneralOptionsWidget->RemoteNetMaskComboBox->setEnabled( false ); + + bool validAddr = true; + if ( ProfileNetworkGeneralOptionsWidget->PingCheckBox->isChecked() && ProfileNetworkGeneralOptionsWidget->PingIPLineEdit->text().contains( '.' ) != 3 ) + { + KMessageBox::error ( this, i18n( "No IP address entered!" ), i18n( "No IP Address" ) ); + GlobalConfig->appendLogEntry( i18n( "No IP address entered!" ) , GlobalConfig->error ); + validAddr = false; + } + else + { + QString addr = ProfileNetworkGeneralOptionsWidget->PingIPLineEdit->text(); + // int part0 = addr.section( '.', 0, 0 ).toInt(); + // int part1 = addr.section( '.', 1, 1 ).toInt(); + // int part2 = addr.section( '.', 2, 2 ).toInt(); + // int part3 = addr.section( '.', 3, 3 ).toInt(); + + /* + LogOutput->append ("part0: "+QString().setNum(part0)); + LogOutput->append ("part1: "+QString().setNum(part1)); + LogOutput->append ("part2: "+QString().setNum(part2)); + LogOutput->append ("part3: "+QString().setNum(part3)); + */ + // if ( ( part0 < 1 || part0 > 254 ) || ( part1 < 0 || part1 > 254 ) || ( part2 < 0 || part2 > 254 ) || ( part3 < 0 || part3 > 254 ) ) + // { + // KMessageBox::error ( this, i18n( "IP address (remote net) is invalid!" ), i18n( "Invalid IP Address" ) ); + // GlobalConfig->appendLogEntry(i18n( "IP address (remote net) is invalid!" ) ,GlobalConfig->error); + // validAddr = false; + // } + + + } + + bool IPOk=true; + if (ProfileNetworkVirtualIpOptionsWidget->UseVirtualIPCheckBox->isChecked()) + { + QString LocalVirtualIp = ProfileNetworkVirtualIpOptionsWidget->LocalVirtualIpEdit->text(); + if (Utils( GlobalConfig ).isValidIPv4Address (LocalVirtualIp) == false) + { + KMessageBox::error ( this, i18n( "No valid IP address entered!" ), i18n( "No Valid IP Address" ) ); + IPOk=false; + } + else + { + profile->setLocalVirtualIP( LocalVirtualIp); + } + + QString RemoteVirtualIp = ProfileNetworkVirtualIpOptionsWidget->RemoteVirtualIpLineEdit->text(); + + if (ProfileNetworkGeneralOptionsWidget->TunnelDeviceTypeComboBox->currentText().lower() == "tun") + { + if (Utils( GlobalConfig ).isValidIPv4Address(RemoteVirtualIp) == false) + { + KMessageBox::error ( this, i18n( "No valid IP address entered!" ), i18n( "No valid IP address" ) ); + IPOk=false; + } + else + { + profile->setRemoteVirtualIP( RemoteVirtualIp); + } + } + if (ProfileNetworkGeneralOptionsWidget->TunnelDeviceTypeComboBox->currentText().lower() == "tap") + { + if (Utils( GlobalConfig ).isValidIPv4Netmask (RemoteVirtualIp) == false) + { + KMessageBox::error ( this, i18n( "No valid netmask entered!" ), i18n( "No valid netmask" ) ); + IPOk=false; + } + else + { + profile->setRemoteVirtualIP( RemoteVirtualIp); + } + } + } + if (IPOk ) + profile->setUseVirtualIP( ProfileNetworkVirtualIpOptionsWidget->UseVirtualIPCheckBox->isChecked()); + else + profile->setUseVirtualIP( false ); + + if ( ProfileCertOptionsWidget->AuthTypeComboBox->currentItem() == 0 ) + profile->setAuthType( VpnAccountData::cert ); + if ( ProfileCertOptionsWidget->AuthTypeComboBox->currentItem() == 1 ) + profile->setAuthType( VpnAccountData::psk ); + + if ( ProfilePskOptionsWidget->AuthTypeComboBox->currentItem() == 0 ) + profile->setAuthType( VpnAccountData::cert ); + if ( ProfilePskOptionsWidget->AuthTypeComboBox->currentItem() == 1 ) + profile->setAuthType( VpnAccountData::psk ); + + + + profile->setPreSharedKeyFile( ProfilePskOptionsWidget->PSKFileURLRequester->url() ); + profile->setPskIsInFile( ProfilePskOptionsWidget->PskInFileCheckBox->isChecked() ); + profile->setX509Certificate( ProfileCertOptionsWidget->x509certURLRequester->url() ); + profile->setCaCertificate( ProfileCertOptionsWidget->CaCertpathURLRequester->url() ); + profile->setCertPath( ProfileCertOptionsWidget->certpathURLRequester->url() ); + profile->setPrivateKey ( ProfileCertOptionsWidget->privkeypathURLRequester->url() ); + profile->setPrivateKeyPass ( ProfileCertOptionsWidget->PrivkeyPasswordEdit->text() ); + profile->setSavePrivateKeyPassword( ProfileCertOptionsWidget->SavePrivateKeyPasswordCheckBox->isChecked() ); + + if (ProfileNetworkGeneralOptionsWidget->TunnelDeviceTypeComboBox->currentItem() == 1) + profile->setTunnelDeviceType( "tap"); + else + profile->setTunnelDeviceType("tun"); + + profile->setUserdefinedPort( ProfileOpenvpnOptionsWidget->UserdefinedPortSpinBox->value() ); + profile->setUseUserdefinedPort( ProfileOpenvpnOptionsWidget->UseUserdefinedPortCheckBox->isChecked() ); + profile->setDisableLzoCompression ( ProfileOpenvpnOptionsWidget->DisableLzoCompressionCheckBox->isChecked() ); + profile->setUserdefinedPort( ProfileOpenvpnOptionsWidget->UserdefinedPortSpinBox->value() ); + profile->setAuthWithUsernameAndPassword( ProfileOpenvpnOptionsWidget->AuthWithUsernameAndPasswordCheckBox->isChecked () ); + profile->setUserName( ProfileUserOptionsWidget->UsernameLineEdit->text() ); + profile->setUserPassword( ProfileUserOptionsWidget->PasswordEdit->text() ); + + + profile->setUserdefiniedCipher( ProfileOpenvpnOptionsWidget->UserdefiniedCipherComboBox->currentText() ); + profile->setUseUserdefiniedCipher( ProfileOpenvpnOptionsWidget->UseUserdefiniedCipherCheckBox->isChecked() ); + + profile->setUseTlsAuth( ProfileOpenvpnOptionsWidget->UseTlsAuthCheckBox->isChecked() ); + profile->setTlsAuthFile( ProfileOpenvpnOptionsWidget->TlsAuthURLRequester->url() ); + + profile->setUseTlsRemoteHost( ProfileOpenvpnOptionsWidget->UseTlsRemoteHostCheckBox->isChecked() ); + profile->setTlsRemoteHost( ProfileOpenvpnOptionsWidget->TlsRemoteHostLineEdit->text() ); + + GlobalConfig->currentProfile->setMssfix( ProfileOpenvpnOptionsWidget->UserdefinedPacketSizeSpinBox->value() ); + GlobalConfig->currentProfile->setFragment( ProfileOpenvpnOptionsWidget->UserdefinedFragmentSizeSpinBox->value() ); + GlobalConfig->currentProfile->setUseMssfix( ProfileOpenvpnOptionsWidget->UseUserdefinedPacketSizeCheckBox->isChecked() ); + GlobalConfig->currentProfile->setUseFragment( ProfileOpenvpnOptionsWidget->UseUserdefinedFragmentationSizeCheckBox->isChecked() ); + + if ( ProfilePskOptionsWidget->AuthTypeComboBox->currentItem() == 1 && ProfilePskOptionsWidget->PskInFileCheckBox->isChecked() && ProfilePskOptionsWidget->PSKFileURLRequester->url().isEmpty() ) + { + KMessageBox::error ( this, i18n( "PSK file can't be empty!" ), i18n( "Empty PSK file" ) ); + // GlobalConfig->appendLogEntry(i18n( "PSK file can't be empty!" ) ,GlobalConfig->error); + canAccept = false; + } + + if ( ProfilePskOptionsWidget->AuthTypeComboBox->currentItem() == 1 && ( !ProfilePskOptionsWidget->PskInFileCheckBox->isChecked() && ProfilePskOptionsWidget->CheckSavePsk->isChecked() ) && ProfilePskOptionsWidget->PSKLineEdit->text().isEmpty() ) + { + KMessageBox::error ( this, i18n( "PSK can't be empty!" ), i18n( "Empty PSK" ) ); + // GlobalConfig->appendLogEntry(i18n( "PSK can't be empty!" ) ,GlobalConfig->error); + canAccept = false; + } + + if ( ProfileOpenvpnOptionsWidget->UseTlsAuthCheckBox->isChecked() && ProfileOpenvpnOptionsWidget->TlsAuthURLRequester->url().isEmpty() ) + { + KMessageBox::error ( this, i18n( "TLS authentication file can't be empty!" ), i18n( "Empty TLS authentication file" ) ); + // GlobalConfig->appendLogEntry(i18n( "TLS authentication file can't be empty!" ) ,GlobalConfig->error); + canAccept = false; + } + + if ( ProfileOpenvpnOptionsWidget->UseUserdefinedRemotePortCheckBox->isChecked() ) + profile->setUseRemotePort( true ); + else + profile->setUseRemotePort( false ); + profile->setRemotePort( ProfileOpenvpnOptionsWidget->UserdefinedRemotePortSpinBox->value() ); + + + + profile->setUseOnlyCaCertAndUserAuth( ProfileOpenvpnOptionsWidget->UseOnlyCaCertAndUserAuthCheckBox->isChecked() ); + + profile->setAuthenticationAlgorithm(ProfileOpenvpnOptionsWidget->UserdefiniedDigestComboBox->currentText()); + profile->setUseAuthenticationAlgorithm(ProfileOpenvpnOptionsWidget->UseAuthenticationAlgorithmCheckBox->isChecked()); + + + if (ProfileOpenvpnOptionsWidget->AuthenticationDirectionComboBox->currentText()==i18n("none")) + profile->setAuthenticationDirection("none"); + if (ProfileOpenvpnOptionsWidget->AuthenticationDirectionComboBox->currentText() == i18n("0")) + profile->setAuthenticationDirection("0"); + if (ProfileOpenvpnOptionsWidget->AuthenticationDirectionComboBox->currentText()==i18n("1")) + profile->setAuthenticationDirection("1"); + + if (ProfileOpenvpnOptionsWidget->RenegSecCheckBox->isChecked()) + profile->setUseRenegSec(true); + else + profile->setUseRenegSec(false); + GlobalConfig->currentProfile->setRenegSec(ProfileOpenvpnOptionsWidget->RenegSecSpinBox->value()); + + + if (ProfileOpenvpnOptionsWidget->TunnelPingCheckBox->isChecked()) + profile->setUseTunnelPing(true); + profile->setTunnelPing(ProfileOpenvpnOptionsWidget->TunnelPingSpinBox->value()); + + if (ProfileOpenvpnOptionsWidget->TunnelPingRestartCheckBox->isChecked()) + profile->setUseTunnelPingRestart(true); + profile->setTunnelPing(ProfileOpenvpnOptionsWidget->TunnelPingSpinBox->value()); + + profile->setDisableBind(ProfileOpenvpnOptionsWidget->DisableSocketBindCheckBox->isChecked()); + + profile->setUseNsCertType( ProfileOpenvpnOptionsWidget->UseNsCertTypeCheckBox->isChecked() ); + + if ( ProfileOpenvpnOptionsWidget->NsCertTypeComboBox->currentText() == "client" ) + profile->setNsCertType( "client" ); + else + profile->setNsCertType( "server" ); + } // openvpn + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::vtun ) + { + + + if ( ProfileCertOptionsWidget->AuthTypeComboBox->currentItem() == 0 ) + profile->setAuthType( VpnAccountData::cert ); + if ( ProfileCertOptionsWidget->AuthTypeComboBox->currentItem() == 1 ) + profile->setAuthType( VpnAccountData::psk ); + + if ( ProfilePskOptionsWidget->AuthTypeComboBox->currentItem() == 0 ) + profile->setAuthType( VpnAccountData::cert ); + if ( ProfilePskOptionsWidget->AuthTypeComboBox->currentItem() == 1 ) + profile->setAuthType( VpnAccountData::psk ); + + profile->setUseLocalPort( ProfileVtunOptionsWidget->PortCheckbox->isChecked()); + profile->setLocalPort ( ProfileVtunOptionsWidget->PortSpinbox->value()); + + if (ProfileVtunOptionsWidget->VtunProfileLineEdit->text().isEmpty()) + { + KMessageBox::error ( this, i18n( "No profile name entered!" ), i18n( "No profile name" ) ); + canAccept = false; + } + else + profile->setVtunProfile(ProfileVtunOptionsWidget->VtunProfileLineEdit->text()); + + bool IPOk=true; + if (ProfileNetworkVirtualIpOptionsWidget->UseVirtualIPCheckBox->isChecked()) + { + QString LocalVirtualIp = ProfileNetworkVirtualIpOptionsWidget->LocalVirtualIpEdit->text(); + if (Utils( GlobalConfig ).isValidIPv4Address (LocalVirtualIp) == false) + { + KMessageBox::error ( this, i18n( "No valid IP address entered!" ), i18n( "No Valid IP Address" ) ); + IPOk=false; + } + else + { + profile->setLocalVirtualIP( LocalVirtualIp); + } + + QString RemoteVirtualIp = ProfileNetworkVirtualIpOptionsWidget->RemoteVirtualIpLineEdit->text(); + + if (ProfileNetworkGeneralOptionsWidget->TunnelDeviceTypeComboBox->currentText().lower() == "tun") + { + if (Utils( GlobalConfig ).isValidIPv4Address(RemoteVirtualIp) == false) + { + KMessageBox::error ( this, i18n( "No valid IP address entered!" ), i18n( "No valid IP address" ) ); + IPOk=false; + } + else + { + profile->setRemoteVirtualIP( RemoteVirtualIp); + } + } + if (IPOk) + profile->setUseVirtualIP(true); + else + profile->setUseVirtualIP(false); + } + } // vtun + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ssh ) + { + + if ( ProfileCertOptionsWidget->AuthTypeComboBox->currentItem() == 0 ) + profile->setAuthType( VpnAccountData::cert ); + if ( ProfileCertOptionsWidget->AuthTypeComboBox->currentItem() == 1 ) + profile->setAuthType( VpnAccountData::psk ); + + if ( ProfilePskOptionsWidget->AuthTypeComboBox->currentItem() == 0 ) + profile->setAuthType( VpnAccountData::cert ); + if ( ProfilePskOptionsWidget->AuthTypeComboBox->currentItem() == 1 ) + profile->setAuthType( VpnAccountData::psk ); + + profile->setUseLocalPort( ProfileSshOptionsWidget->UseUserdefinedRemotePortCheckBox->isChecked()); + profile->setLocalPort ( ProfileSshOptionsWidget->UserdefinedRemotePortSpinBox->value()); + + bool IPOk=true; + + profile->setUseVirtualIP(ProfileNetworkVirtualIpOptionsWidget->UseVirtualIPCheckBox->isChecked()); + + if (ProfileNetworkVirtualIpOptionsWidget->UseVirtualIPCheckBox->isChecked()) + { + QString LocalVirtualIp = ProfileNetworkVirtualIpOptionsWidget->LocalVirtualIpEdit->text(); + if (Utils( GlobalConfig ).isValidIPv4Address (LocalVirtualIp) == false) + { + KMessageBox::error ( this, i18n( "No valid IP address entered!" ), i18n( "No Valid IP Address" ) ); + IPOk=false; + } + else + { + profile->setLocalVirtualIP( LocalVirtualIp); + } + + + QString RemoteVirtualIp = ProfileNetworkVirtualIpOptionsWidget->RemoteVirtualIpLineEdit->text(); + + if (ProfileNetworkGeneralOptionsWidget->TunnelDeviceTypeComboBox->currentText().lower() == "tun") + { + if (Utils( GlobalConfig ).isValidIPv4Address(RemoteVirtualIp) == false) + { + KMessageBox::error ( this, i18n( "No valid IP address entered!" ), i18n( "No valid IP address" ) ); + IPOk=false; + } + else + { + profile->setRemoteVirtualIP( RemoteVirtualIp); + } + } + if (IPOk) + profile->setUseVirtualIP(true); + else + profile->setUseVirtualIP(false); + } + else + { + KMessageBox::error ( this, i18n( "Virtual IP address must be enabled!" ), i18n( "Virtual IP address disabled" ) ); + IPOk=false; + } + profile->setUseRemotePort( ProfileSshOptionsWidget->UseUserdefinedRemotePortCheckBox->isChecked() ); + profile->setRemotePort ( ProfileSshOptionsWidget->UserdefinedRemotePortSpinBox->value() ); + + // password or key auth + if (ProfileSshOptionsWidget->AuthPassRadioButton->isChecked()) + { + profile->setAuthWithUsernameAndPassword(true); +// KMessageBox::error ( this,"save: pass", "pass" ); + } + else + { + profile->setAuthWithUsernameAndPassword(false); +// KMessageBox::error ( this,"save: key", "key" ); + } + profile->setPreSharedKey(ProfileSshOptionsWidget->SshKeyComboBox->currentText()); + profile->setPreSharedKeyFile(ProfileSshOptionsWidget->CostumkeyURLRequester->url()); + + if (ProfileSshOptionsWidget->CostumKeyRadioButton->isChecked()) + { + profile->setPskIsInFile(true); + } + else + { + profile->setPskIsInFile(false); + } + + if (ProfileSshOptionsWidget->UseSshConfigRemoteScriptCheckBox->isChecked() && !ProfileSshOptionsWidget->SshConfigRemoteScriptLineEdit->text().isEmpty()) + { + profile->setUseSshConfigRemoteScript(true); + profile->setSshConfigRemoteScript(ProfileSshOptionsWidget->SshConfigRemoteScriptLineEdit->text()); + } + else + profile->setUseSshConfigRemoteScript(false); + + if (ProfileSshOptionsWidget->UseSshConfigRemoteScriptCheckBox->isChecked() && ProfileSshOptionsWidget->SshConfigRemoteScriptLineEdit->text().isEmpty()) + { + KMessageBox::error ( this, i18n( "%1 cant be empty!" ).arg(i18n("ssh config remote script")), i18n( "%1 empty" ).arg(i18n("ssh config remote script")) ); + IPOk=false; + } + + } // ssh + + if ( ProfileNetworkGeneralOptionsWidget->PingCheckBox->isChecked() && !ProfileNetworkGeneralOptionsWidget->PingIPLineEdit->text().isEmpty() ) + { + profile->setPingHostIP( ProfileNetworkGeneralOptionsWidget->PingIPLineEdit->text() ); + profile->setDoPingIP( ProfileNetworkGeneralOptionsWidget->PingCheckBox->isChecked() ); + } + else + { + if ( ProfileNetworkGeneralOptionsWidget->PingCheckBox->isChecked() && ProfileNetworkGeneralOptionsWidget->PingIPLineEdit->text() == QString( "" ) ) + { + KMessageBox::error ( this, i18n( "No hostname/IP address (ping host) entered!" ), i18n( "No hostname/IP address" ) ); + GlobalConfig->appendLogEntry( i18n( "No hostname/IP address (ping host) entered!" ) , GlobalConfig->error ); + canAccept = false; + } + else + profile->setPingHostIP( "" ); + } + + if ( ProfileNetworkRouteOptionsWidget->DefaultRouteComboBox->currentItem() == 1 ) + { + profile->setReplaceDefaultRoute( true ); + } + else + { + profile->setReplaceDefaultRoute( false ); + } + + profile->setUseSmartcard( ProfileSmartcardOptionsWidget->UseSmartcardCheckBox->isChecked() ); + + profile->setAllowEmptyPrivateKeyPassword( ProfileCertOptionsWidget->AllowEmptyPrivateKeyPasswordCheckBox->isChecked()); + profile->setAllowIpAddressChangeOfPeer(ProfileOpenvpnOptionsWidget->AllowIpAddressChangeOfPeerCheckBox->isChecked()); + + profile->setUseConnectionStatusCheck( ProfileNetworkGeneralOptionsWidget->UseConnectionStatusCheckCheckBox->isChecked() ); + profile->setConnectionStatusCheckSuccessCount( ProfileNetworkGeneralOptionsWidget->ConnectionStatusSuccessCountNumInput->value() ); + profile->setConnectionStatusInterval( ProfileNetworkGeneralOptionsWidget->ConnectionStatusCheckIntervalNumInput->value() ); + profile->setDoReconnectAfterConnectionLost( ProfileNetworkGeneralOptionsWidget->DoReconnectAfterConnectionLostCheckBox->isChecked() ); + profile->setUseReconnectDelay( ProfileNetworkGeneralOptionsWidget->UseReconnectDelayCheckBox->isChecked() ); + profile->setReconnectDelay( ProfileNetworkGeneralOptionsWidget->ReconnectDelayNumInput->value() ); + profile->setUseDnsUpdate( ProfileNetworkGeneralOptionsWidget->UseDnsUpdateCheckBox->isChecked() ); + + profile->setLeftNextHop( ProfileIpsecOptionsWidget->LeftNextHopLineEdit->text() ); //TODO check valid IP + profile->setRightNextHop( ProfileIpsecOptionsWidget->RightNextHopLineEdit->text( ) ); //TODO check valid IP + profile->setUseRightNextHop(ProfileIpsecOptionsWidget->UseRightNextHopCheckBox->isChecked()); + profile->setUseLeftNextHop(ProfileIpsecOptionsWidget->UseLeftNextHopCheckBox->isChecked()); + + profile->setSavePsk( ProfilePskOptionsWidget->CheckSavePsk->isChecked() ); + profile->setSaveUserPassword( ProfileUserOptionsWidget->CheckUserPass->isChecked () ); + profile->setUserName( ProfileUserOptionsWidget->UsernameLineEdit->text () ); + + if ( ProfileUserOptionsWidget->CheckUserPass->isChecked() ) + profile->setUserPassword( ProfileUserOptionsWidget->PasswordEdit->text ( ) ); + else + profile->setUserPassword( "" ); + + if ( ProfilePskOptionsWidget->CheckSavePsk->isChecked() ) + profile->setPreSharedKey( ProfilePskOptionsWidget->PSKLineEdit->text( ) ); + else + profile->setPreSharedKey( "" ); + + profile->setUseMailAddressAsIdentifier( ProfileCertOptionsWidget->UseMailAddressAsIdentifierCheckBox->isChecked() ); + + profile->setGateway( ProfileGeneralOptionsWidget->gatewayLineEdit->text() ); + // std::cout << "save: set gateway to: " << ProfileGeneralOptionsWidget->gatewayLineEdit->text() << ", now it is in profile: " << profile->getGateway() << std::endl; + profile->setPreSharedKey( ProfilePskOptionsWidget->PSKLineEdit->text() ); + profile->setX509Certificate( ProfileCertOptionsWidget->x509certURLRequester->url() ); + profile->setCertPath( ProfileCertOptionsWidget->certpathURLRequester->url() ); + profile->setPrivateKeyPass( ProfileCertOptionsWidget->PrivkeyPasswordEdit->text() ); + profile->setSavePrivateKeyPassword( ProfileCertOptionsWidget->SavePrivateKeyPasswordCheckBox->isChecked() ); + profile->setNetworkDevice( ProfileNetworkGeneralOptionsWidget->NetworkDeviceComboBox->currentText() ); + + profile->setDoPingIP( ProfileNetworkGeneralOptionsWidget->PingCheckBox->isChecked() ); + + if ( ProfileNetworkNatOptionsWidget->UseNatCheckbox->isChecked() ) + profile->setUseNat( true ); + else + profile->setUseNat( false ); + + if ( ProfileNetworkNatOptionsWidget->UseUdpCheckbox->isChecked() ) + profile->setUseUdp( true ); + else + profile->setUseUdp( false ); + + if ( ProfileNetworkNatOptionsWidget->UdpPortCheckbox->isChecked() ) + { + profile->setUdpPort( ProfileNetworkNatOptionsWidget->UdpPortSpinbox->value() ); + profile->setUseUdpPort( true ); + } + else + { + profile->setUdpPort( 0 ); + profile->setUseUdpPort( false ); + } + + profile->setUseMtu( ProfileNetworkGeneralOptionsWidget->MtuCheckbox->isChecked() ); + profile->setMtu ( ProfileNetworkGeneralOptionsWidget->MtuSpinbox->value() ); + profile->setUseMru( ProfileNetworkGeneralOptionsWidget->MruCheckbox->isChecked() ); + profile->setMru ( ProfileNetworkGeneralOptionsWidget->MruSpinbox->value() ); + profile->setFixPathMtuDiscoveryProblem(ProfileNetworkGeneralOptionsWidget->FixPathMtuDiscoveryProblemCheckBox->isChecked()); + + profile->setExecuteCmdBeforeConnect( ( ProfileCmdExecBeforeConnectOptionsWidget->ExcuteCmdBeforeConnectCheckBox->isChecked() ) ); + profile->setExecuteCmdAfterConnect( ( ProfileCmdExecAfterConnectOptionsWidget->ExcuteCmdAfterConnectCheckBox->isChecked() ) ); + profile->setExecuteCmdBeforeDisconnect( ( ProfileCmdExecBeforeDisconnectOptionsWidget->ExcuteCmdBeforeDisconnectCheckBox->isChecked() ) ); + profile->setExecuteCmdAfterDisconnect( ( ProfileCmdExecAfterDisconnectOptionsWidget->ExcuteCmdAfterDisconnectCheckBox->isChecked() ) ); + + profile->setCommandBeforeConnect( ProfileCmdExecBeforeConnectOptionsWidget->CmdBeforeConnectTextEdit->text() ); + profile->setCommandAfterConnect( ProfileCmdExecAfterConnectOptionsWidget->CmdAfterConnectTextEdit->text() ); + profile->setCommandBeforeDisconnect( ProfileCmdExecBeforeDisconnectOptionsWidget->CmdBeforeDisconnectTextEdit->text() ); + profile->setCommandAfterDisconnect( ProfileCmdExecAfterDisconnectOptionsWidget->CmdAfterDisconnectTextEdit->text() ); + profile->setCommandAfterConnectDelayTime(ProfileCmdExecAfterConnectOptionsWidget->CommandAfterConnectDelayTimeNumInput->value()); + + if ( ProfileNetworkHttpProxyOptionsWidget->HttpProxyAuthTypeComboBox->currentText() == "Basic" ) + profile->setHttpProxyAuthType( "basic" ); + if ( ProfileNetworkHttpProxyOptionsWidget->HttpProxyAuthTypeComboBox->currentText() == "NTLM" ) + profile->setHttpProxyAuthType( "ntlm" ); + + + profile->setUseHttpProxy( ProfileNetworkHttpProxyOptionsWidget->UseHttpProxyCheckBox->isChecked() ); + profile->setHttpProxy( ProfileNetworkHttpProxyOptionsWidget->HttpProxyLineEdit->text( ) ); + profile->setHttpProxyPort( ProfileNetworkHttpProxyOptionsWidget->HttpProxyPortIntNumInput->value( ) ); + profile->setHttpProxyTimeout( ProfileNetworkHttpProxyOptionsWidget->HttpProxyTimeoutIntSpinBox->value() ); + profile->setHttpProxyPass( ProfileNetworkHttpProxyOptionsWidget->HttpProxyAuthPasswordEdit->text() ); + profile->setHttpProxyUser( ProfileNetworkHttpProxyOptionsWidget->HttpProxyUserLineEdit->text() ); + + if (ProfileNetworkHttpProxyOptionsWidget->UseHttpProxyCheckBox->isChecked()) + { + if(ProfileNetworkHttpProxyOptionsWidget->HttpProxyLineEdit->text().isEmpty()) + { + KMessageBox::error ( this, i18n( "HTTP proxy server can't be empty!" ), i18n( "Empty HTTP proxy server" ) ); + // GlobalConfig->appendLogEntry(i18n( "HTTP proxy server can't be empty!" ) ,GlobalConfig->error); + canAccept = false; + profile->setUseHttpProxy( false ); + } + else + profile->setUseHttpProxy( ProfileNetworkHttpProxyOptionsWidget->UseHttpProxyCheckBox->isChecked() ); + + if ( ProfileNetworkHttpProxyOptionsWidget->UseHttpProxyAuthCheckBox->isChecked()) + { + if ( ProfileNetworkHttpProxyOptionsWidget->HttpProxyAuthPasswordEdit->text().isEmpty() ) + { + KMessageBox::error ( this, i18n( "Password for HTTP proxy authentication can't be empty!" ), i18n( "Empty HTTP proxy password for authentication" ) ); + // GlobalConfig->appendLogEntry(i18n( "Password for HTTP proxy authentication can't be empty!" ) ,GlobalConfig->error); + canAccept = false; + profile->setUseHttpProxyAuth( false ); + } + + if(ProfileNetworkHttpProxyOptionsWidget->HttpProxyUserLineEdit->text().isEmpty() ) + { + KMessageBox::error ( this, i18n( "Username for HTTP proxy authentication can't be empty!" ), i18n( "Empty HTTP proxy username for authentication" ) ); + // GlobalConfig->appendLogEntry(i18n( "Username for HTTP proxy authentication can't be empty!" ) ,GlobalConfig->error); + canAccept = false; + profile->setUseHttpProxyAuth( false ); + } + if (canAccept==true) + profile->setUseHttpProxyAuth( ProfileNetworkHttpProxyOptionsWidget->UseHttpProxyAuthCheckBox->isChecked() ); + } + + + } + + QStringList AdditionalNetworkRoutes; + if ( ProfileNetworkRouteOptionsWidget->UseExtraNetworkRoutesCheckbox->isChecked() ) + profile->setUseAdditionalNetworkRoutes( true ); + else + profile->setUseAdditionalNetworkRoutes( false ); + + if (ProfileNetworkRouteOptionsWidget->NetworkListView->childCount() > 0) + { + QListViewItemIterator it( ProfileNetworkRouteOptionsWidget->NetworkListView ); + for ( ; it.current(); ++it ) + { + // example entry: + // /# + QString network = QString( it.current() ->text( 0 ) + "/" + it.current() ->text( 1 ) ); + network.append( "#" ); + network.append( it.current() ->text( 2 ) ); // gateway + network.append( "#" ); + network.append( it.current() ->text( 3 ) ); // interface + AdditionalNetworkRoutes.append( network ); + } + } + + profile->setAdditionalNetworkRoutes( AdditionalNetworkRoutes ); + + profile->setUseSpecialServerCertificate( ProfileCertOptionsWidget->UseSpecialServerCertificateCheckBox->isChecked() ); + + if ( ProfileCertOptionsWidget->UseSpecialServerCertificateCheckBox->isChecked() ) + { + if ( !ProfileCertOptionsWidget->SpecialServerCertificateURLRequester->url().isEmpty() ) + profile->setSpecialServerCertificate( ProfileCertOptionsWidget->SpecialServerCertificateURLRequester->url() ); + else + { + KMessageBox::error ( this, i18n( "Special server certificate can't be empty!" ), i18n( "No Server Certificate" ) ); + // GlobalConfig->appendLogEntry( i18n( "Special server certificate can't be empty!" ) ,GlobalConfig->error); + canAccept = false; + } + } + + + + if ( GlobalConfig->currentProfile->getAuthType() == VpnAccountData::cert && + ProfileSmartcardOptionsWidget->UseSmartcardCheckBox->isEnabled() && + ProfileSmartcardOptionsWidget->UseSmartcardCheckBox->isChecked() ) + { + if ( !ProfileSmartcardOptionsWidget->Pkcs11SlotComboBox->currentText().isEmpty() ) + profile->setPkcs11Slot(ProfileSmartcardOptionsWidget->Pkcs11SlotComboBox->currentText()); + else + { + KMessageBox::error ( this, i18n( "Slot at smartcard can't be empty!" ), i18n( "No smartcard slot" ) ); + // GlobalConfig->appendLogEntry( i18n( "Slot at smartcard can't be empty!" ) ,GlobalConfig->error); + canAccept = false; + } + if ( !ProfileSmartcardOptionsWidget->Pkcs11IdComboBox->currentText().isEmpty() ) + profile->setPkcs11Id(ProfileSmartcardOptionsWidget->Pkcs11IdComboBox->currentText()); + else + { + KMessageBox::error ( this, i18n( "ID for certificate at smartcard can't be empty!" ), i18n( "No certificate ID" ) ); + // GlobalConfig->appendLogEntry( i18n( "ID for certificate at smartcard can't be empty!" ) ,GlobalConfig->error); + canAccept = false; + } + QString Pkcs11SlotType = ProfileSmartcardOptionsWidget->Pkcs11SlotTypeComboBox->currentText(); + if (Pkcs11SlotType == i18n("ID")) + profile->setPkcs11SlotType("id"); + else if (Pkcs11SlotType == i18n("Name")) + profile->setPkcs11SlotType("name"); + else + profile->setPkcs11SlotType("label"); + + QString Pkcs11IdType = ProfileSmartcardOptionsWidget->Pkcs11IdTypeComboBox->currentText(); + if (Pkcs11IdType == i18n("ID")) + profile->setPkcs11IdType("id"); + else if (Pkcs11IdType == i18n("Label")) + profile->setPkcs11IdType("label"); + else + profile->setPkcs11IdType("subject"); + + QString Pkcs11SignMode = ProfileSmartcardOptionsWidget->Pkcs11SignModeComboBox->currentText(); + if (Pkcs11SignMode == i18n("auto")) + profile->setPkcs11SignMode("auto"); + else if (Pkcs11SignMode == i18n("sign")) + profile->setPkcs11SignMode("sign"); + else if (Pkcs11SignMode == i18n("recover")) + profile->setPkcs11SignMode("recover"); + else + profile->setPkcs11SignMode("any"); + } + + if (ProfileSmartcardOptionsWidget->UsePkcs11ProvidersCheckBox->isChecked()) + { + if ( !ProfileSmartcardOptionsWidget->Pkcs11ProvidersURLRequester->url().isEmpty() ) + profile->setPkcs11Providers(ProfileSmartcardOptionsWidget->Pkcs11ProvidersURLRequester->url()); + else + { + KMessageBox::error ( this, i18n( "Library path to lib for use with smartcard can't be empty!" ), i18n( "No providers lib" ) ); + // GlobalConfig->appendLogEntry( i18n( "Library path to lib for use with smartcard can't be empty!" ) ,GlobalConfig->error); + canAccept = false; + } + } + + profile->setUsePkcs11Providers (ProfileSmartcardOptionsWidget->UsePkcs11ProvidersCheckBox->isChecked()); + profile->setDontSaveUsername( ProfileUserOptionsWidget->DontSaveUsernameCheckBox->isChecked() ); + profile->setDisableCcp( ProfilePptpOptionsWidget->DisableCcpCheckbox->isChecked() ); + + if (!GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ssh) + profile->setPskIsInFile ( ProfilePskOptionsWidget->PskInFileCheckBox->isChecked() ); + + + if (ProfileNetworkGeneralOptionsWidget->TunnelDeviceTypeComboBox->currentItem() == 1) + GlobalConfig->currentProfile->setTunnelDeviceType("tap"); + else + GlobalConfig->currentProfile->setTunnelDeviceType("tun"); + + GlobalConfig->currentProfile->setAskUserPasswordOnEachConnect( ProfileUserOptionsWidget->AskUserPasswordOnEachConnectCheckBox->isChecked()); + + GlobalConfig->saveOptions(true, GlobalConfig->currentProfile->getName()); + GlobalConfig->config->sync(); + GlobalConfig->appPointer->restoreOverrideCursor(); + + //GlobalConfig->appendLogEntry( i18n( "Profile \"%1\" saved." ).arg( newName ),GlobalConfig->debug); + // enableButtonApply(false); + +} + +void PreferencesDialog::deleteSessionClicked() +{ + QString Name = ProfileGeneralSelector->currentText(); + + + ToolInfo *IpsecToolInfo = Utils ( GlobalConfig ).getToolInfo ( "ipsec" ) ; + QString IpsecType; + + QString TypeString = i18n ( "unknown" ); + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::cisco ) + TypeString = i18n("Cisco"); + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ciscoorig ) + TypeString = i18n("Cisco (propritary)"); + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::pptp ) + TypeString = i18n("PPTP"); + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::freeswan ) + { + if ( IpsecToolInfo->Version.contains ( "Openswan" ) ) + IpsecType = TypeString = i18n("Openswan"); + else if ( IpsecToolInfo->Version.contains ( "strongSwan" ) ) + IpsecType = TypeString = i18n("strongSwan"); + else + IpsecType = TypeString = i18n("FreeS/WAN"); + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon ) + TypeString = "racoon"; + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::openvpn ) + TypeString = "OpenVPN"; + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon ) + { + TypeString = "L2TP (racoon)"; + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_freeswan ) + { + if ( IpsecToolInfo->Version.contains ( "Openswan" ) ) + IpsecType = TypeString = "L2TP (Openswan)"; + else if ( IpsecToolInfo->Version.contains ( "strongSwan" ) ) + IpsecType = TypeString = "L2TP (strongSwan)"; + else + IpsecType = TypeString = "L2TP (FreeS/WAN)"; + } + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::vtun ) + TypeString = "Vtun"; + else if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ssh ) + TypeString = "SSH"; + + if ( !ProfileGeneralSelector->currentText().isEmpty() ) + { + int result = KMessageBox::questionYesNo ( this, i18n ( "Really delete profile \"%1\" (type: %2, Server: %3)?" ).arg ( GlobalConfig->currentProfile->getName() ).arg(TypeString).arg(GlobalConfig->currentProfile->getGateway()), i18n ( "Delete?" ), KStdGuiItem::del(), KStdGuiItem::cancel() ); + //LogOutput->append( "Result: "+ QString().setNum(result) ) ; + if ( result == 3 ) // Yes + { + VpnAccountData * it; + if ( !GlobalConfig->AccountList->isEmpty() ) + { + for ( it = GlobalConfig->AccountList->first(); it; it = GlobalConfig->AccountList->next() ) + { + if ( ProfileGeneralSelector->currentText().isEmpty() ) + { + // this->deleteSessionAction->setEnabled ( FALSE ); + // this->advancedSessionAction->setEnabled ( FALSE ); + // this->saveSessionAction->setEnabled ( FALSE ); + } + else + { + if ( it->getName() == Name ) + { + profileAddedOrDeleted=true; + GlobalConfig->removeEntry( GlobalConfig->currentProfile->getName() ); + ProfileGeneralSelector->removeItem( ProfileGeneralSelector->currentItem() ); + ProfileNetworkRouteSelector->removeItem( ProfileGeneralSelector->currentItem() ); + ProfileNetworkNatSelector->removeItem( ProfileGeneralSelector->currentItem() ); + ProfileNetworkHttpProxySelector->removeItem( ProfileGeneralSelector->currentItem() ); + ProfileNetworkVirtualIpSelector->removeItem( ProfileGeneralSelector->currentItem() ); + ProfileCertSelector->removeItem( ProfileGeneralSelector->currentItem() ); + ProfileSmartcardSelector->removeItem( ProfileGeneralSelector->currentItem() ); + ProfilePskSelector->removeItem( ProfileGeneralSelector->currentItem() ); + ProfileUserSelector->removeItem( ProfileGeneralSelector->currentItem() ); + ProfileOpenvpnSelector->removeItem( ProfileGeneralSelector->currentItem() ); + ProfilePptpSelector->removeItem( ProfileGeneralSelector->currentItem() ); + ProfileVtunSelector->removeItem( ProfileGeneralSelector->currentItem() ); + ProfileSshSelector->removeItem( ProfileGeneralSelector->currentItem() ); + ProfileRacoonSelector->removeItem( ProfileGeneralSelector->currentItem() ); + ProfileIpsecSelector->removeItem( ProfileGeneralSelector->currentItem() ); + ProfileCiscoSelector->removeItem( ProfileGeneralSelector->currentItem() ); + ProfileCmdExecBeforeConnectSelector->removeItem( ProfileGeneralSelector->currentItem() ); + ProfileCmdExecBeforeDisconnectSelector->removeItem( ProfileGeneralSelector->currentItem() ); + ProfileCmdExecAfterConnectSelector->removeItem( ProfileGeneralSelector->currentItem() ); + ProfileCmdExecAfterDisconnectSelector->removeItem( ProfileGeneralSelector->currentItem() ); + break; + } + } + } + } + + if ( !GlobalConfig->AccountList->isEmpty() ) + { + GlobalConfig->currentProfile = GlobalConfig->AccountList->first(); + GlobalConfig->lastProfile = GlobalConfig->AccountList->first()->getName(); + ProfileGeneralSelector->setCurrentText( GlobalConfig->AccountList->first() ->getName() ); + //ConnectOptionsWidget->ProfileGeneralOptionsWidget->ProfileComboBox->setSelected(0, true); + profileChanged ( GlobalConfig->AccountList->first() ->getName() ); + connectionTypeChanged( GlobalConfig->AccountList->first() ->getConnectionType() ); + authTypeChanged( GlobalConfig->AccountList->first() ->getAuthType() ); + // buttonCancel->setEnabled( true ); + // buttonOk->setEnabled( true ); + } + else + { + ProfileGeneralOptionsWidget->DeleteSessionPushButton->setEnabled ( FALSE ); + ProfileGeneralOptionsWidget->RenameSessionPushButton->setEnabled ( FALSE ); + ProfileGeneralOptionsWidget->SaveSessionPushButton->setEnabled ( FALSE ); + GlobalConfig->lastProfile = ""; + GlobalConfig->currentProfile = 0L; + // CiscoPptpGroupBox->setEnabled( false ); + // FreeswanRacoonGroupBox->setEnabled( false ); + // OpenvpnGroupBox->setEnabled( false ); + // GeneralGroupbox->setEnabled( false ); + // CommandExecutionGroupBox->setEnabled( false ); + } + + // slotStatusMsg ( i18n( "Profile \"%1\" deleted." ).arg( Name ), ID_FLASH_MSG ); + + profileAddedOrDeleted = true; + saveSessionClicked(); + GlobalConfig->removeEntry( Name ); + GlobalConfig->appendLogEntry ( i18n( "Profile \"%1\" deleted." ).arg( Name ), GlobalConfig->debug ); + + + //saveOptions(); // TODO save, currently after closing dialog + // sessionToggled(); + //if ( ConnectOptionsWidget->ProfileGeneralOptionsWidget->ProfileComboBox->currentText().isEmpty() ) + // ConnectOptionsWidget->ProfileGeneralOptionsWidget->ProfileComboBox->setEnabled ( FALSE ); + } + } + +} + +void PreferencesDialog::newSessionClicked() +{ + + // call new profile dialog... + NewProfileDialog newdlg( GlobalConfig->appPointer, this, i18n( "New profile" ), GlobalConfig ); + newdlg.exec(); + if ( newdlg.newProfileCreated ) + { + + VpnAccountData * it; + bool nameOk = false; + bool ok; + QString newName=newdlg.getName(); + QString Oldname = newdlg.getName(); + while ( nameOk == false ) + { + for ( it = GlobalConfig->AccountList->first(); it; it = GlobalConfig->AccountList->next() ) + { + if ( ( it != GlobalConfig->currentProfile ) && ( it->getName() == newName ) ) + { + //account->setName( QString( account->getName() + "_2" ) ); + // KMessageBox::information ( this, i18n( "Profile name exists!\n It will be renamed to \"%1\"." ).arg( account->getName() ), i18n( "Name exist, renamed" ) ); + KMessageBox::error ( this, i18n ( "Profile name exists!" ), i18n ( "Name Exists" ) ); + + newName = KInputDialog::getText ( i18n ( "New Name" ), i18n ( "New name for profile:" ), QString ( Oldname + "_2" ), &ok ); + if ( ok == false ) + { + KMessageBox::information ( 0, i18n ( "Rename at new created profile was canceled." ) ); + GlobalConfig->appendLogEntry ( i18n ( "Rename at new created profile was canceled." ), GlobalConfig->info ); + return ; + } + } + if ( newName.isEmpty() ) + nameOk=false; + else + nameOk = true; + } + if ( newName.isEmpty() ) + nameOk=false; + else + nameOk = true; + } + + if (nameOk) + { + GlobalConfig->AccountList->append(newdlg.profileData); + for ( it = GlobalConfig->AccountList->first(); it; it = GlobalConfig->AccountList->next() ) + { + if ( it->getName() == newName ) + { + if (GlobalConfig->KvpncDebugLevel > 3) + GlobalConfig->appendLogEntry ( i18n( "New created profile \"%1\" found in profile list." ).arg( newName ), GlobalConfig->debug ); + profileAddedOrDeleted=true; + ProfileGeneralSelector->insertItem( newName ); + ProfileNetworkRouteSelector->insertItem( newName ); + ProfileNetworkNatSelector->insertItem( newName ); + ProfileNetworkHttpProxySelector->insertItem( newName ); + ProfileNetworkVirtualIpSelector->insertItem( newName ); + ProfileCertSelector->insertItem( newName ); + ProfileSmartcardSelector->insertItem( newName ); + ProfilePskSelector->insertItem( newName ); + ProfileUserSelector->insertItem( newName ); + ProfileOpenvpnSelector->insertItem( newName ); + ProfilePptpSelector->insertItem( newName ); + ProfileVtunSelector->insertItem( newName ); + ProfileSshSelector->insertItem( newName ); + ProfileRacoonSelector->insertItem( newName ); + ProfileIpsecSelector->insertItem( newName ); + ProfileCiscoSelector->insertItem( newName ); + ProfileCmdExecBeforeConnectSelector->insertItem( newName ); + ProfileCmdExecBeforeDisconnectSelector->insertItem( newName ); + ProfileCmdExecAfterConnectSelector->insertItem( newName ); + ProfileCmdExecAfterDisconnectSelector->insertItem( newName ); + + slotProfileCreated(newName); + + GlobalConfig->currentProfile = it; + break; + } + } + + ProfileGeneralOptionsWidget->RenameSessionPushButton->setEnabled( TRUE ); + ProfileGeneralOptionsWidget->DeleteSessionPushButton->setEnabled( TRUE ); + ProfileGeneralOptionsWidget->SaveSessionPushButton->setEnabled ( TRUE ); + + // CiscoPptpGroupBox->setEnabled( true ); + // // FreeswanRacoonGroupBox->setEnabled( true ); + // OpenvpnGroupBox->setEnabled( true ); + // GeneralGroupbox->setEnabled( true ); + // CommandExecutionGroupBox->setEnabled( true ); + + KMessageBox::information ( this, i18n( "Profile \"%1\" added.\nNow set the right type,\n fill in the fields\nand press \"Save\" to complete the profile." ).arg( newName ), i18n( "Complete Profile" ) ); + //slotStatusMsg ( i18n( "Profile \"%1\" added." ).arg( Name ), ID_FLASH_MSG ); + + GlobalConfig->appendLogEntry ( i18n( "Profile \"%1\" added." ).arg( newName ), GlobalConfig->debug ); + profileAddedOrDeleted = true; + configChanged=true; + NewProfileName = newName; + profileChanged ( newName ); + connectionTypeChanged( ProfileGeneralOptionsWidget->ConnectionTypeComboBox->currentItem() ); + authTypeChanged( ProfileCertOptionsWidget->AuthTypeComboBox->currentItem() ); + authTypeChanged( ProfilePskOptionsWidget->AuthTypeComboBox->currentItem() ); + saveSessionClicked(); + } + else + { + GlobalConfig->appendLogEntry ( i18n ( "Rename at new created profile was canceled." ), GlobalConfig->info ); + slotStatusMsg ( i18n ( "Creating new profile canceled." ), ID_FLASH_MSG ); + GlobalConfig->appendLogEntry ( i18n ( "Creating new profile canceled." ), GlobalConfig->info ); + } + } + else + { + + GlobalConfig->appendLogEntry ( i18n( "Creation of the new profile canceled." ), GlobalConfig->debug ); + } +} + +void PreferencesDialog::renameSessionClicked() +{ + bool ok = true; + bool nameOk = false; + QString oldName = GlobalConfig->currentProfile->getName(); + QString *newName; + + while ( nameOk == false ) + { + newName = new QString( KInputDialog::getText ( i18n( "New Name" ), i18n( "Enter new name for profile:" ), oldName, &ok, this ) ); + if ( newName->contains( ' ' ) ) + { + KMessageBox::error ( this, i18n( "Blanks are not allowed in profile names!" ), i18n( "Illegal Character in Name" ) ); + GlobalConfig->appendLogEntry( i18n( "Blanks are not allowed in profile names!" ) , GlobalConfig->error ); + ok = false; + } + if ( *newName == oldName ) + { +// KMessageBox::error ( this, i18n( "Profile name can be same!" ), i18n( "Same name" ) ); +// GlobalConfig->appendLogEntry( i18n( "Profile name can be same!" ) , GlobalConfig->error ); + ok = false; + nameOk=true; + } + else + nameOk=true; + } + if ( ok ) + { + profileAddedOrDeleted=true; + GlobalConfig->currentProfile->setName( *newName ); + ProfileGeneralSelector->clear(); + ProfileNetworkRouteSelector->clear(); + ProfileNetworkNatSelector->clear(); + ProfileNetworkHttpProxySelector->clear(); + ProfileNetworkVirtualIpSelector->clear(); + ProfileCertSelector->clear(); + ProfileSmartcardSelector->clear(); + ProfilePskSelector->clear(); + ProfileUserSelector->clear(); + ProfileOpenvpnSelector->clear(); + ProfilePptpSelector->clear(); + ProfileVtunSelector->clear(); + ProfileSshSelector->clear(); + ProfileRacoonSelector->clear(); + ProfileIpsecSelector->clear(); + ProfileCiscoSelector->clear(); + ProfileCmdExecBeforeConnectSelector->clear(); + ProfileCmdExecBeforeDisconnectSelector->clear(); + ProfileCmdExecAfterConnectSelector->clear(); + ProfileCmdExecAfterDisconnectSelector->clear(); + + if ( !GlobalConfig->AccountList->isEmpty() ) + { + VpnAccountData * it; + for ( it = GlobalConfig->AccountList->first(); it; it = GlobalConfig->AccountList->next() ) + { + if ( it != 0 ) + { + ProfileGeneralSelector->insertItem( it->getName() ); + ProfileNetworkRouteSelector->insertItem( it->getName() ); + ProfileNetworkNatSelector->insertItem( it->getName() ); + ProfileNetworkHttpProxySelector->insertItem( it->getName() ); + ProfileNetworkVirtualIpSelector->insertItem( it->getName() ); + ProfileCertSelector->insertItem( it->getName() ); + ProfileSmartcardSelector->insertItem( it->getName() ); + ProfilePskSelector->insertItem( it->getName() ); + ProfileUserSelector->insertItem( it->getName() ); + ProfileOpenvpnSelector->insertItem( it->getName() ); + ProfilePptpSelector->insertItem( it->getName() ); + ProfileVtunSelector->insertItem( it->getName() ); + ProfileSshSelector->insertItem( it->getName() ); + ProfileRacoonSelector->insertItem( it->getName() ); + ProfileIpsecSelector->insertItem( it->getName() ); + ProfileCiscoSelector->insertItem( it->getName() ); + ProfileCmdExecBeforeConnectSelector->insertItem( it->getName() ); + ProfileCmdExecBeforeDisconnectSelector->insertItem( it->getName() ); + ProfileCmdExecAfterConnectSelector->insertItem( it->getName() ); + ProfileCmdExecAfterDisconnectSelector->insertItem( it->getName() ); + slotProfileCreated(it->getName()); + break; + } + } + } + + if ( !showOnlyProfiles ) + { + ConnectOptionsWidget->AutoConnectProfileComboBox->clear(); + for ( uint i = 1; i < GlobalConfig->AccountList->count();i++ ) + { + ConnectOptionsWidget->AutoConnectProfileComboBox->insertItem( GlobalConfig->AccountList->at( i ) ->getName() ); + } + } + profileAddedOrDeleted = true; + configChanged=true; + + GlobalConfig->lastProfile = QString(*newName); + + saveSessionClicked(); + GlobalConfig->removeEntry( oldName ); + + KMessageBox::information ( 0, i18n ( "Rename of \"%1\" to \"%2\" was successful." ).arg ( oldName ).arg(GlobalConfig->currentProfile->getName()) ); + GlobalConfig->appendLogEntry ( i18n ( "Rename of \"%1\" to \"%2\" was successful." ).arg ( oldName ).arg(GlobalConfig->currentProfile->getName()), GlobalConfig->info ); + + + } + +} + +void PreferencesDialog::importCertificate() +{ + ImportCertificateDialog dlg( this, i18n( "Import certificate..." ).ascii(), GlobalConfig ); + //int result = + dlg.exec(); +} + +void PreferencesDialog::pageChanged( QWidget* page ) +{ +// std::cout << "page changed, new profile: "<< lastProfileName << std::endl; + + prev_page = current_page; + current_page = page; +// std::cout << "page changed, page: "<< page << std::endl; +// std::cout << "page changed, old page: "<< prev_page << std::endl; + + bool page_data_changed=false; + + if ( !showOnlyProfiles ) + { + if (prev_page == ConfigConnectOptionsFrame && ConnectOptionsWidget->dialogModified ) + { + page_data_changed=true; + ConnectOptionsWidget->dialogModified = false; + } + else if (prev_page == DaemonOptionsFrame && ConfigDaemonOptionsWidget->dialogModified ) + { + page_data_changed=true; + ConfigDaemonOptionsWidget->dialogModified = false; + } + else if (prev_page == DebugFrame && DebugOptionsWidget->dialogModified ) + { + page_data_changed=true; + DebugOptionsWidget->dialogModified = false; + } + else if (prev_page == LogFrame && LogOptionsWidget->dialogModified ) + { + page_data_changed=true; + LogOptionsWidget->dialogModified = false; + } + else if (prev_page == HelperProgramFrame && HelperProgramOptionsWidget->dialogModified ) + { + page_data_changed=true; + HelperProgramOptionsWidget->dialogModified = false; + } + + } + + if (prev_page == ProfileNetworkRouteOptionsFrame && ProfileNetworkRouteOptionsWidget->dialogModified ) + { + page_data_changed=true; + ProfileNetworkRouteOptionsWidget->dialogModified = false; + } + else if (prev_page == ProfileGeneralOptionsFrame && ProfileGeneralOptionsWidget->dialogModified ) + { + page_data_changed=true; + ProfileGeneralOptionsWidget->dialogModified = false; + } + else if (prev_page == ProfileUserOptionsFrame && ProfileUserOptionsWidget->dialogModified ) + { + page_data_changed=true; + ProfileUserOptionsWidget->dialogModified = false; + } + else if (prev_page == ProfileCertOptionsFrame && ProfileCertOptionsWidget->dialogModified ) + { + page_data_changed=true; + ProfileCertOptionsWidget->dialogModified = false; + } + else if (prev_page == ProfileCiscoOptionsFrame && ProfileCiscoOptionsWidget->dialogModified ) + { + page_data_changed=true; + ProfileCiscoOptionsWidget->dialogModified = false; + } + else if (prev_page == ProfileNetworkHttpProxyOptionsFrame && ProfileNetworkHttpProxyOptionsWidget->dialogModified ) + { + page_data_changed=true; + ProfileNetworkHttpProxyOptionsWidget->dialogModified = false; + } + else if (prev_page == ProfileCmdExecAfterConnectOptionsFrame && ProfileCmdExecAfterConnectOptionsWidget->dialogModified ) + { + page_data_changed=true; + ProfileCmdExecAfterConnectOptionsWidget->dialogModified = false; + } + else if (prev_page == ProfileCmdExecAfterDisconnectOptionsFrame && ProfileCmdExecAfterDisconnectOptionsWidget->dialogModified ) + { + page_data_changed=true; + ProfileCmdExecAfterDisconnectOptionsWidget->dialogModified = false; + } + else if (prev_page == ProfileCmdExecBeforeConnectOptionsFrame && ProfileCmdExecBeforeConnectOptionsWidget->dialogModified ) + { + page_data_changed=true; + ProfileCmdExecBeforeConnectOptionsWidget->dialogModified = false; + } + else if (prev_page == ProfileCmdExecBeforeDisconnectOptionsFrame && ProfileCmdExecBeforeDisconnectOptionsWidget->dialogModified ) + { + page_data_changed=true; + ProfileCmdExecBeforeDisconnectOptionsWidget->dialogModified = false; + } + else if (prev_page == ProfileNetworkNatOptionsFrame && ProfileNetworkNatOptionsWidget->dialogModified ) + { + page_data_changed=true; + ProfileNetworkNatOptionsWidget->dialogModified = false; + } + else if (prev_page == ProfileNetworkVirtualIpOptionsFrame && ProfileNetworkVirtualIpOptionsWidget->dialogModified ) + { + page_data_changed=true; + ProfileNetworkVirtualIpOptionsWidget->dialogModified = false; + } + else if (prev_page == ProfileOpenvpnOptionsFrame && ProfileOpenvpnOptionsWidget->dialogModified ) + { + page_data_changed=true; + ProfileOpenvpnOptionsWidget->dialogModified = false; + } + else if (prev_page == ProfilePptpOptionsFrame && ProfilePptpOptionsWidget->dialogModified ) + { + page_data_changed=true; + ProfilePptpOptionsWidget->dialogModified = false; + } + else if (prev_page == ProfilePskOptionsFrame && ProfilePskOptionsWidget->dialogModified ) + { + page_data_changed=true; + ProfilePskOptionsWidget->dialogModified = false; + } + else if (prev_page == ProfileRacoonOptionsFrame && ProfileRacoonOptionsWidget->dialogModified ) + { + page_data_changed=true; + ProfileRacoonOptionsWidget->dialogModified = false; + } + else if (prev_page == ProfileIpsecOptionsFrame && ProfileIpsecOptionsWidget->dialogModified ) + { + page_data_changed=true; + ProfileIpsecOptionsWidget->dialogModified = false; + } + else if (prev_page == ProfileSshOptionsFrame && ProfileSshOptionsWidget->dialogModified ) + { + page_data_changed=true; + ProfileSshOptionsWidget->dialogModified = false; + } + else if (prev_page == ProfileSmartcardOptionsFrame && ProfileSmartcardOptionsWidget->dialogModified ) + { + page_data_changed=true; + ProfileSmartcardOptionsWidget->dialogModified = false; + } + else if (prev_page == ProfileVtunOptionsFrame && ProfileVtunOptionsWidget->dialogModified ) + { + page_data_changed=true; + ProfileVtunOptionsWidget->dialogModified = false; + } + else if (prev_page == ProfileNetworkGeneralOptionsFrame && ProfileNetworkGeneralOptionsWidget->dialogModified ) + { + page_data_changed=true; + ProfileNetworkGeneralOptionsWidget->dialogModified = false; + } + + if (page_data_changed) + { + std::cout << "page data changed => save need" << std::endl; + saveSessionClicked(); + } + + profileChanged( lastProfileName ); + +} + +void PreferencesDialog::userAuthToggled( bool ) +{ + if ( ProfileOpenvpnOptionsWidget->AuthWithUsernameAndPasswordCheckBox->isChecked() ) + ProfileUserOptionsWidget->setEnabled( true ); + else + ProfileUserOptionsWidget->setEnabled( false ); + +} + +void PreferencesDialog::useUdpToggled( bool ) +{ + if ( ProfileNetworkNatOptionsWidget->UseUdpCheckbox->isChecked() ) + { + ProfileOpenvpnOptionsWidget->UseUserdefinedPacketSizeCheckBox->setEnabled( true ); + ProfileOpenvpnOptionsWidget->userdefiniedPacketSizeToggled( ProfileOpenvpnOptionsWidget->UseUserdefinedPacketSizeCheckBox->isChecked() ); + ProfileOpenvpnOptionsWidget->userdefiniedFragmentationSizeToggled( ProfileOpenvpnOptionsWidget->UseUserdefinedFragmentationSizeCheckBox->isChecked() ); + } + else + { + ProfileOpenvpnOptionsWidget->UseUserdefinedPacketSizeCheckBox->setEnabled( false ); + ProfileOpenvpnOptionsWidget->userdefiniedPacketSizeToggled( ProfileOpenvpnOptionsWidget->UseUserdefinedPacketSizeCheckBox->isChecked() ); + ProfileOpenvpnOptionsWidget->userdefiniedFragmentationSizeToggled( ProfileOpenvpnOptionsWidget->UseUserdefinedFragmentationSizeCheckBox->isChecked() ); + } +} + +void PreferencesDialog::OpenvpnPathChanged( const QString& ) +{ + ToolInfo * OpenvpnInfo = Utils( GlobalConfig ).getToolInfo ( "openvpn" ); +// OpenvpnInfo->PathToExec = ConfigDaemonOptionsWidget->OpenvpnPathInput->url(); +// GlobalConfig->pathToOpenvpn = ConfigDaemonOptionsWidget->OpenvpnPathInput->url(); +// OpenvpnInfo->addSearchPath(ConfigDaemonOptionsWidget->OpenvpnPathInput->url()); + OpenvpnInfo->TryPath_first = ConfigDaemonOptionsWidget->OpenvpnPathInput->url(); + OpenvpnInfo->collectToolInfo(); + + ConfigDaemonOptionsWidget->OpenvpnVersionLineEdit->setText( OpenvpnInfo->Version ); + + if ( OpenvpnInfo->found ) + ConfigDaemonOptionsWidget->OpenvpnStatePixmapLabel->setPixmap( ok_icon ); + else + ConfigDaemonOptionsWidget->OpenvpnStatePixmapLabel->setPixmap( wrong_icon ); +} + +void PreferencesDialog::FreeswanPathChanged( const QString& ) +{ + // KMessageBox::information(0,"path changed","ipsec"); + + ToolInfo * IpsecInfo = Utils( GlobalConfig ).getToolInfo ( "ipsec" ); +// IpsecInfo->removeSearchPath( IpsecInfo->PathToExec ); +// IpsecInfo->PathToExec = ConfigDaemonOptionsWidget->FreeswanPathInput->url(); +// GlobalConfig->pathToIpsec = ConfigDaemonOptionsWidget->FreeswanPathInput->url(); +// IpsecInfo->addSearchPath(ConfigDaemonOptionsWidget->FreeswanPathInput->url()); + IpsecInfo->TryPath_first = ConfigDaemonOptionsWidget->FreeswanPathInput->url(); + IpsecInfo->collectToolInfo(); + + ConfigDaemonOptionsWidget->IpsecVersionLineEdit->setText( IpsecInfo->Version ); + + if ( IpsecInfo->found ) + ConfigDaemonOptionsWidget->IpsecStatePixmapLabel->setPixmap( ok_icon ); + else + ConfigDaemonOptionsWidget->IpsecStatePixmapLabel->setPixmap( wrong_icon ); +} + +void PreferencesDialog::PppdPathChanged( const QString& ) +{ + // KMessageBox::information(0,"path changed","Pppd"); + + ToolInfo * PppdInfo = Utils( GlobalConfig ).getToolInfo ( "pppd" ); +// PppdInfo->removeSearchPath( PppdInfo->PathToExec ); +// PppdInfo->PathToExec = ConfigDaemonOptionsWidget->PppdPathInput->url(); +// GlobalConfig->pathToPppd = ConfigDaemonOptionsWidget->PppdPathInput->url(); +// PppdInfo->addSearchPath(ConfigDaemonOptionsWidget->PppdPathInput->url()); + PppdInfo->TryPath_first = ConfigDaemonOptionsWidget->PppdPathInput->url(); + PppdInfo->collectToolInfo(); + + ConfigDaemonOptionsWidget->PppdVersionLineEdit->setText( PppdInfo->Version ); + + if ( PppdInfo->found ) + ConfigDaemonOptionsWidget->PppdStatePixmapLabel->setPixmap( ok_icon ); + else + ConfigDaemonOptionsWidget->PppdStatePixmapLabel->setPixmap( wrong_icon ); +} + +void PreferencesDialog::PptpPathChanged( const QString& ) +{ + // KMessageBox::information(0,"path changed","Pptp"); + + ToolInfo *PptpInfo = Utils( GlobalConfig ).getToolInfo ( "pptp" ); +// PptpInfo->PathToExec = ConfigDaemonOptionsWidget->PptpPathInput->url(); +// GlobalConfig->pathToPptp = ConfigDaemonOptionsWidget->PptpPathInput->url(); +// PptpInfo->removeSearchPath( PptpInfo->PathToExec ); +// PptpInfo->addSearchPath(ConfigDaemonOptionsWidget->PptpPathInput->url()); + PptpInfo->TryPath_first = ConfigDaemonOptionsWidget->PptpPathInput->url(); + PptpInfo->collectToolInfo(); + + ConfigDaemonOptionsWidget->PptpVersionLineEdit->setText( PptpInfo->Version ); + + if ( PptpInfo->found ) + ConfigDaemonOptionsWidget->PptpStatePixmapLabel->setPixmap( ok_icon ); + else + ConfigDaemonOptionsWidget->PptpStatePixmapLabel->setPixmap( wrong_icon ); +} + +void PreferencesDialog::RacoonPathChanged( const QString& ) +{ + // KMessageBox::information(0,"path changed","Racoon"); + + ToolInfo * RacoonInfo = Utils( GlobalConfig ).getToolInfo ( "racoon" ); +// RacoonInfo->removeSearchPath( RacoonInfo->PathToExec ); +// RacoonInfo->PathToExec = ConfigDaemonOptionsWidget->RacoonPathInput->url(); +// GlobalConfig->pathToRacoon = ConfigDaemonOptionsWidget->RacoonPathInput->url(); +// RacoonInfo->addSearchPath(ConfigDaemonOptionsWidget->RacoonPathInput->url()); + RacoonInfo->TryPath_first = ConfigDaemonOptionsWidget->RacoonPathInput->url(); + RacoonInfo->collectToolInfo(); + + ConfigDaemonOptionsWidget->RacoonVersionLineEdit->setText( RacoonInfo->Version ); + + QPixmap ok_icon = KGlobal::iconLoader() ->loadIcon( "button_ok", KIcon::NoGroup ); + QPixmap wrong_icon = KGlobal::iconLoader() ->loadIcon( "button_cancel", KIcon::NoGroup ); + + if ( RacoonInfo->found ) + ConfigDaemonOptionsWidget->RacoonStatePixmapLabel->setPixmap( ok_icon ); + else + ConfigDaemonOptionsWidget->RacoonStatePixmapLabel->setPixmap( wrong_icon ); +} + +void PreferencesDialog::VpncPathChanged( const QString& ) +{ + // KMessageBox::information(0,"path changed","Vpnc"); + + ToolInfo * VpncInfo = Utils( GlobalConfig ).getToolInfo ( "vpnc" ); + +// VpncInfo->removeSearchPath( VpncInfo->PathToExec ); + +// VpncInfo->PathToExec = ConfigDaemonOptionsWidget->VpncPathInput->url(); +// GlobalConfig->pathToVpnc = ConfigDaemonOptionsWidget->VpncPathInput->url(); + // KMessageBox::information(0,VpncInfo->PathToExec,"vpnc path"); +// VpncInfo->addSearchPath(ConfigDaemonOptionsWidget->VpncPathInput->url()); + VpncInfo->TryPath_first = ConfigDaemonOptionsWidget->VpncPathInput->url(); + VpncInfo->collectToolInfo(); + + ConfigDaemonOptionsWidget->VpncVersionLineEdit->setText( VpncInfo->Version ); + // KMessageBox::information(0,VpncInfo->Version,"vpnc version"); + + if ( VpncInfo->found ) + ConfigDaemonOptionsWidget->VpncStatePixmapLabel->setPixmap( ok_icon ); + else + ConfigDaemonOptionsWidget->VpncStatePixmapLabel->setPixmap( wrong_icon ); +} + +void PreferencesDialog::CiscoVpncPathChanged( const QString& ) +{ + // KMessageBox::information(0,"path changed","Vpnc"); + + ToolInfo * CiscoVpncInfo = Utils( GlobalConfig ).getToolInfo ( "vpnclient" ); + +// CiscoVpncInfo->removeSearchPath( CiscoVpncInfo->PathToExec ); + +// CiscoVpncInfo->PathToExec = ConfigDaemonOptionsWidget->CiscoVpncPathInput->url(); +// GlobalConfig->pathToCiscoVpnc = ConfigDaemonOptionsWidget->CiscoVpncPathInput->url(); + // KMessageBox::information(0,VpncInfo->PathToExec,"vpnclient (proprietary) path"); +// CiscoVpncInfo->addSearchPath(ConfigDaemonOptionsWidget->CiscoVpncPathInput->url()); + CiscoVpncInfo->TryPath_first = ConfigDaemonOptionsWidget->CiscoVpncPathInput->url(); + CiscoVpncInfo->collectToolInfo(); + + ConfigDaemonOptionsWidget->CiscoVpncVersionLineEdit->setText( CiscoVpncInfo->Version ); + // KMessageBox::information(0,CiscoVpncInfo->Version,"vpnclient version"); + + if ( CiscoVpncInfo->found ) + ConfigDaemonOptionsWidget->CiscoVpncStatePixmapLabel->setPixmap( ok_icon ); + else + ConfigDaemonOptionsWidget->CiscoVpncStatePixmapLabel->setPixmap( wrong_icon ); +} + +void PreferencesDialog::L2tpdPathChanged( const QString& ) +{ + // KMessageBox::information(0,"path changed","L2tpd"); + + ToolInfo * L2tpdInfo = Utils( GlobalConfig ).getToolInfo ( "l2tpd" ); + +// L2tpdInfo->removeSearchPath( L2tpdInfo->PathToExec ); + +// L2tpdInfo->PathToExec =ConfigDaemonOptionsWidget->L2tpdPathInput->url(); +// GlobalConfig->pathToL2tpd =ConfigDaemonOptionsWidget->L2tpdPathInput->url(); + // KMessageBox::information(0,L2tpdInfo->PathToExec,"l2tpd path"); +// L2tpdInfo->addSearchPath(ConfigDaemonOptionsWidget->L2tpdPathInput->url()); + L2tpdInfo->TryPath_first =ConfigDaemonOptionsWidget->L2tpdPathInput->url(); + + L2tpdInfo->collectToolInfo(); + + ConfigDaemonOptionsWidget->L2tpdVersionLineEdit->setText( L2tpdInfo->Version ); + // KMessageBox::information(0,L2tpdInfo->Version,"l2tpd version"); + + if ( L2tpdInfo->found ) + ConfigDaemonOptionsWidget->L2tpdStatePixmapLabel->setPixmap( ok_icon ); + else + ConfigDaemonOptionsWidget->L2tpdStatePixmapLabel->setPixmap( wrong_icon ); +} + +void PreferencesDialog::Xl2tpdPathChanged( const QString& ) +{ + // KMessageBox::information(0,"path changed","Xl2tpd"); + + ToolInfo * Xl2tpdInfo = Utils( GlobalConfig ).getToolInfo ( "l2tpd" ); + +// Xl2tpdInfo->removeSearchPath( Xl2tpdInfo->PathToExec ); + +// Xl2tpdInfo->PathToExec = ConfigDaemonOptionsWidget->Xl2tpdPathInput->url(); +// GlobalConfig->pathToXl2tpd = ConfigDaemonOptionsWidget->Xl2tpdPathInput->url(); + // KMessageBox::information(0,Xl2tpdInfo->PathToExec,"l2tpd path"); +// Xl2tpdInfo->addSearchPath(ConfigDaemonOptionsWidget->Xl2tpdPathInput->url()); + Xl2tpdInfo->TryPath_first = ConfigDaemonOptionsWidget->Xl2tpdPathInput->url(); + + Xl2tpdInfo->collectToolInfo(); + + ConfigDaemonOptionsWidget->Xl2tpdVersionLineEdit->setText( Xl2tpdInfo->Version ); + // KMessageBox::information(0,Xl2tpdInfo->Version,"l2tpd version"); + + if ( Xl2tpdInfo->found ) + ConfigDaemonOptionsWidget->Xl2tpdStatePixmapLabel->setPixmap( ok_icon ); + else + ConfigDaemonOptionsWidget->Xl2tpdStatePixmapLabel->setPixmap( wrong_icon ); +} + +void PreferencesDialog::Openl2tpPathChanged( const QString& ) +{ + // KMessageBox::information(0,"path changed","Openl2tp"); + + ToolInfo * Openl2tpInfo = Utils( GlobalConfig ).getToolInfo ( "openl2tpd" ); + +// Openl2tpInfo->removeSearchPath( Openl2tpInfo->PathToExec ); + +// Openl2tpInfo->PathToExec = ConfigDaemonOptionsWidget->Openl2tpPathInput->url(); +// GlobalConfig->pathToOpenl2tp = ConfigDaemonOptionsWidget->Openl2tpPathInput->url(); + // KMessageBox::information(0,Openl2tpInfo->PathToExec,"l2tpd path"); +// Openl2tpInfo->addSearchPath(ConfigDaemonOptionsWidget->Openl2tpPathInput->url()); + Openl2tpInfo->TryPath_first = ConfigDaemonOptionsWidget->Openl2tpPathInput->url(); + + Openl2tpInfo->collectToolInfo(); + + ConfigDaemonOptionsWidget->Openl2tpVersionLineEdit->setText( Openl2tpInfo->Version ); + // KMessageBox::information(0,Openl2tpInfo->Version,"openl2tp version"); + + if ( Openl2tpInfo->found ) + ConfigDaemonOptionsWidget->Openl2tpStatePixmapLabel->setPixmap( ok_icon ); + else + ConfigDaemonOptionsWidget->Openl2tpStatePixmapLabel->setPixmap( wrong_icon ); +} + +void PreferencesDialog::VtundPathChanged( const QString& ) +{ + // KMessageBox::information(0,"path changed","vtund"); + + ToolInfo * VtunInfo = Utils( GlobalConfig ).getToolInfo ( "vtund" ); + +// VtunInfo->removeSearchPath( Xl2tpdInfo->PathToExec ); + +// VtunInfo->PathToExec = ConfigDaemonOptionsWidget->VtunddPathInput->url(); +// GlobalConfig->pathToXl2tpd = ConfigDaemonOptionsWidget->VtunddPathInput->url(); + // KMessageBox::information(0,Xl2tpdInfo->PathToExec,"vtund path"); +// VtunInfo->addSearchPath(ConfigDaemonOptionsWidget->VtunddPathInput->url()); + VtunInfo->TryPath_first = ConfigDaemonOptionsWidget->VtundPathInput->url(); + + VtunInfo->collectToolInfo(); + + ConfigDaemonOptionsWidget->VtunVersionLineEdit->setText( VtunInfo->Version ); + // KMessageBox::information(0,Xl2tpdInfo->Version,"vtun version"); + + if ( VtunInfo->found ) + ConfigDaemonOptionsWidget->VtundStatePixmapLabel->setPixmap( ok_icon ); + else + ConfigDaemonOptionsWidget->VtundStatePixmapLabel->setPixmap( wrong_icon ); +} + +void PreferencesDialog::SshPathChanged( const QString& ) +{ + // KMessageBox::information(0,"path changed","ssh"); + + ToolInfo * SshInfo = Utils( GlobalConfig ).getToolInfo ( "ssh" ); + +// SshInfo->removeSearchPath( SshInfo->PathToExec ); + +// SshInfo->PathToExec = ConfigDaemonOptionsWidget->SshdPathInput->url(); +// GlobalConfig->pathToSsh = ConfigDaemonOptionsWidget->SshdPathInput->url(); + // KMessageBox::information(0,SshInfo->PathToExec,"ssh path"); +// SshInfo->addSearchPath(ConfigDaemonOptionsWidget->SshdPathInput->url()); + SshInfo->TryPath_first = ConfigDaemonOptionsWidget->SshPathInput->url(); + + SshInfo->collectToolInfo(); + + ConfigDaemonOptionsWidget->SshVersionLineEdit->setText( SshInfo->Version ); + // KMessageBox::information(0,SshInfo->Version,"ssh version"); + + if ( SshInfo->found ) + ConfigDaemonOptionsWidget->SshStatePixmapLabel->setPixmap( ok_icon ); + else + ConfigDaemonOptionsWidget->SshStatePixmapLabel->setPixmap( wrong_icon ); +} + +void PreferencesDialog::showEvent(QShowEvent* e) +{ + KDialogBase::showEvent(e); + + QSplitter* splitter = ((QSplitter*)child(0, "QSplitter", true)); + KListView* listView = ((KListView*)child(0, "KListView", true)); + + if (splitter && listView) + { + int visible = listView->visibleWidth(); + int content = listView->contentsWidth(); + + if (visible < content) + { + int shiftSplitterBy = content - visible; + resize(width()+shiftSplitterBy, height()); + QValueList oldSizes = splitter->sizes(); + QValueList newSizes; + newSizes << oldSizes[0] + shiftSplitterBy << oldSizes[1] - shiftSplitterBy; + splitter->setSizes(newSizes); + } + } +} + +void PreferencesDialog::detectPkcs11Ids() +{ + GlobalConfig->appPointer->setOverrideCursor( QCursor(Qt::WaitCursor) ); + ProfileSmartcardOptionsWidget->Pkcs11IdComboBox->clear(); + + int Pkcs11IdType = ProfileSmartcardOptionsWidget->Pkcs11IdTypeComboBox->currentItem(); + QString Pkcs11IdTypeTmp; + if (Pkcs11IdType == 0) + { + Pkcs11IdTypeTmp="id"; + + if (KvpncDebugLevel > 1) + GlobalConfig->appendLogEntry(i18n("Pkcs11IdType: %1").arg(Pkcs11IdTypeTmp),KVpncConfig::debug); + } + else if (Pkcs11IdType == 1) + { + Pkcs11IdTypeTmp="label"; + if (KvpncDebugLevel > 1) + GlobalConfig->appendLogEntry(i18n("Pkcs11IdType: %1").arg(Pkcs11IdTypeTmp),KVpncConfig::debug); + } + else + { + Pkcs11IdTypeTmp="subject"; + if (KvpncDebugLevel > 1) + GlobalConfig->appendLogEntry(i18n("Pkcs11IdType: %1").arg(Pkcs11IdTypeTmp),KVpncConfig::debug); + } + + QString ProviderLib=""; + bool isOpenvpn = GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::openvpn; + if (ProfileSmartcardOptionsWidget->UsePkcs11ProvidersCheckBox->isChecked() && !ProfileSmartcardOptionsWidget->Pkcs11ProvidersURLRequester->url().isEmpty()) + ProviderLib = ProfileSmartcardOptionsWidget->Pkcs11ProvidersURLRequester->url(); + + // we have to split slot id and name ("0 : foobar") => 0 + QString Pkcs11Slot = ProfileSmartcardOptionsWidget->Pkcs11SlotComboBox->currentText().section(':',0,0).stripWhiteSpace(); + + + QStringList Pkcs11Ids; + if (isOpenvpn) + Pkcs11Ids = Utils(GlobalConfig).getOpenvpnPkcs11Ids(ProviderLib); + else + Pkcs11Ids = Utils(GlobalConfig).getSmartcardCertsFromSlot(Pkcs11Slot,Pkcs11IdTypeTmp, ProviderLib ); + + for ( QStringList::Iterator it = Pkcs11Ids.begin(); it != Pkcs11Ids.end(); ++it ) + ProfileSmartcardOptionsWidget->Pkcs11IdComboBox->insertItem( QString(*it)); + + GlobalConfig->appPointer->restoreOverrideCursor(); +} + +void PreferencesDialog::detectPkcs11Slots() +{ + GlobalConfig->appPointer->setOverrideCursor( QCursor(Qt::WaitCursor) ); + ProfileSmartcardOptionsWidget->Pkcs11SlotComboBox->clear(); + QString ProviderLib=""; + bool isOpenvpn = GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::openvpn; + if (ProfileSmartcardOptionsWidget->UsePkcs11ProvidersCheckBox->isChecked() && !ProfileSmartcardOptionsWidget->Pkcs11ProvidersURLRequester->url().isEmpty()) + ProviderLib = ProfileSmartcardOptionsWidget->Pkcs11ProvidersURLRequester->url(); + QStringList Pkcs11Slots; + + if (isOpenvpn) + Pkcs11Slots.append("0"); + else + Pkcs11Slots = Utils(GlobalConfig).getSmartcardSlots(ProviderLib); + + for ( QStringList::Iterator it = Pkcs11Slots.begin(); it != Pkcs11Slots.end(); ++it ) + ProfileSmartcardOptionsWidget->Pkcs11SlotComboBox->insertItem( QString(*it)); + + GlobalConfig->appPointer->restoreOverrideCursor(); +} + +void PreferencesDialog::localPortToggled(bool) +{ + if ( ProfileCiscoOptionsWidget->LocalPortCheckbox->isChecked() ) + ProfileCiscoOptionsWidget->LocalPortSpinbox->setEnabled( true ); + else + ProfileCiscoOptionsWidget->LocalPortSpinbox->setEnabled( false ); +} + +void PreferencesDialog::useSpecialServerSmartcardificateToggled(bool) +{ +// if (ProfileCertOptionsWidget->UseSpecialServerSmartcardificateCheckBox->isChecked()) +// { +// ProfileSmartcardOptionsWidget->SpecialServerSmartcardificateURLRequester->setEnabled(TRUE); +// } +// else +// { +// ProfileSmartcardOptionsWidget->SpecialServerSmartcardificateURLRequester->setEnabled(FALSE); +// } +} + +void PreferencesDialog::applicationVersionToggled(bool) +{ + if ( ProfileCiscoOptionsWidget->ApplicationVersionCheckbox->isChecked() ) + ProfileCiscoOptionsWidget->ApplicationVersionLineedit->setEnabled( true ); + else + ProfileCiscoOptionsWidget->ApplicationVersionLineedit->setEnabled( false ); +} + +void PreferencesDialog::IkeGroupToggled(bool) +{ +if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::cisco ) + { + if ( ProfileCiscoOptionsWidget->IkeGroupCheckbox->isChecked() ) + ProfileCiscoOptionsWidget->IkeGroupCombobox->setEnabled( true ); + else + ProfileCiscoOptionsWidget->IkeGroupCombobox->setEnabled( false ); + } +if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon || GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon) + { + if ( ProfileRacoonOptionsWidget->IkeGroupCheckbox->isChecked() ) + ProfileRacoonOptionsWidget->DHGroupComboBox->setEnabled( true ); + else + ProfileRacoonOptionsWidget->DHGroupComboBox->setEnabled( false ); + +} +} + +void PreferencesDialog::perfectForwardSecurityToggled(bool) +{ + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::cisco ) + { + if ( ProfileCiscoOptionsWidget->PerfectForwardSecurityCheckbox->isChecked() ) + ProfileCiscoOptionsWidget->PerfectForwardSecrecyCombobox->setEnabled( true ); + else + ProfileCiscoOptionsWidget->PerfectForwardSecrecyCombobox->setEnabled( false ); + } +if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::racoon || GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::l2tpd_racoon) + { + if ( ProfileRacoonOptionsWidget->PerfectForwardSecurityCheckbox->isChecked() ) + ProfileRacoonOptionsWidget->PerfectForwardSecrecyCombobox->setEnabled( true ); + else + ProfileRacoonOptionsWidget->PerfectForwardSecrecyCombobox->setEnabled( false ); + + } +} + +void PreferencesDialog::singleDesToggled(bool) +{} + +void PreferencesDialog::tunnelDeviceTypeChanged(const QString & string ) +{ + if ( GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::openvpn || GlobalConfig->currentProfile->getConnectionType() == VpnAccountData::ssh) + { + if (string.lower() == "tun") + { + ProfileNetworkVirtualIpOptionsWidget->LabelRemoteVirtualIp->setText(i18n("Remote IP (virtual):")); + } + if (string.lower() == "tap") + { + ProfileNetworkVirtualIpOptionsWidget->LabelRemoteVirtualIp->setText(i18n("Netmask for local IP address:")); + } + } +} + +void PreferencesDialog::natModeToggled( const QString &) +{ + if (ProfileCiscoOptionsWidget->CiscoNatModeComboBox->currentText() == "none") + { + ProfileNetworkNatOptionsWidget->UseNatCheckbox->setChecked(false); + } + else + { + ProfileNetworkNatOptionsWidget->UseNatCheckbox->setChecked(true); + } +} + +void PreferencesDialog::useKwalletToggled(bool) +{ + if (!GeneralOptionsWidget->useKwalletCheckBox->isChecked()) + { + + int result = KMessageBox::questionYesNo ( this, i18n ( "Do you really want disable the use of KWallet? KVpnc will save passwords and psk in config file if requested." ), i18n ( "Disable KWallet?" ) ); + //LogOutput->append( "Result: "+ QString().setNum(result) ) ; + if ( result == 2 || result == 4 ) // No or Cancel + { + GeneralOptionsWidget->useKwalletCheckBox->setChecked(true); + GlobalConfig->useKwallet=true; + } + if (result == 3) //Yes + GlobalConfig->useKwallet=false; + + } +} + +void PreferencesDialog::dpdToggled(bool) +{ + if (ProfileCiscoOptionsWidget->EnableDpdIdleTimeoutCheckbox->isChecked()) + ProfileCiscoOptionsWidget->DpdIdleTimeoutSpinbox->setEnabled(true); + else + ProfileCiscoOptionsWidget->DpdIdleTimeoutSpinbox->setEnabled(false); +} + +void PreferencesDialog::useXauthToggled(bool) +{ + if (ProfileIpsecOptionsWidget->UseXauthCheckBox->isChecked()) + { + ProfileUserOptionsWidget->setEnabled(true); + ProfilePskOptionsWidget->setEnabled(true); + ProfileIpsecOptionsWidget->LocalIdTypeCombobox->setEnabled(true); + ProfileIpsecOptionsWidget->LocalIDLineEdit->setEnabled(true); + ProfileIpsecOptionsWidget->LocalIdTypeCombobox->setCurrentText("keyid"); + } + else + { + ProfileUserOptionsWidget->setEnabled(false); + ProfilePskOptionsWidget->setEnabled(false); + ProfileIpsecOptionsWidget->LocalIdTypeCombobox->setEnabled(true); + ProfileIpsecOptionsWidget->LocalIDLineEdit->setEnabled(false); + ProfileIpsecOptionsWidget->LocalIdTypeCombobox->setCurrentText("asn1dn"); + } +} + +void PreferencesDialog::useCiscoCertStoreToggled(bool) +{ + if (ProfileCertOptionsWidget->UseCiscoCertStoreCheckBox->isChecked()) + { + ProfileCertOptionsWidget->x509certComboBox->show(); + ProfileCertOptionsWidget->x509certURLRequester->hide(); + ProfileCertOptionsWidget->CaCertpathComboBox->show(); + ProfileCertOptionsWidget->CaCertpathURLRequester->hide(); + ProfileCertOptionsWidget->certpathURLRequester->hide(); + ProfileCertOptionsWidget->sizeHint(); + } + else + { + ProfileCertOptionsWidget->x509certComboBox->hide(); + ProfileCertOptionsWidget->x509certURLRequester->show(); + ProfileCertOptionsWidget->CaCertpathComboBox->hide(); + ProfileCertOptionsWidget->CaCertpathURLRequester->show(); + ProfileCertOptionsWidget->certpathURLRequester->show(); + ProfileCertOptionsWidget->sizeHint(); + } +} + +bool PreferencesDialog::getVpncHasHybridSupport() +{ + bool hasHybridSupport = false; + ToolInfo *tool; + for ( tool = GlobalConfig->ToolList->first(); tool; tool = GlobalConfig->ToolList->next() ) + { + if (tool->Name == "vpnc") + { + GlobalConfig->appendLogEntry ( i18n ( "vpnc capabilities: %1" ).arg( tool->Capabilities),GlobalConfig->debug ); + if( tool->Capabilities.find(i18n("openssl (certificate) support"),0,-1) > -1 ) + { + hasHybridSupport = true; + return hasHybridSupport; + } + + } + } + return hasHybridSupport; +} + +void PreferencesDialog::slotStatusMsg ( const QString &text, int id ) +{ + if (!GlobalConfig->statusbar != 0) + { + if ( id != ID_FLASH_MSG ) + { + GlobalConfig->statusbar->clear(); + GlobalConfig->statusbar->changeItem ( text, id ); + } + else + { + GlobalConfig->statusbar->message ( text, 2000 ); + } + } +} + +void PreferencesDialog::slotProfileCreated(QString Name) +{ + ProfileGeneralSelector->insertItem( Name ); + ProfileNetworkRouteSelector->insertItem( Name ); + ProfileNetworkNatSelector->insertItem( Name ); + ProfileNetworkHttpProxySelector->insertItem( Name ); + ProfileNetworkVirtualIpSelector->insertItem( Name ); + ProfileCertSelector->insertItem( Name ); + ProfileSmartcardSelector->insertItem( Name ); + ProfilePskSelector->insertItem( Name ); + ProfileUserSelector->insertItem( Name ); + ProfileOpenvpnSelector->insertItem( Name ); + ProfilePptpSelector->insertItem( Name ); + ProfileVtunSelector->insertItem( Name ); + ProfileSshSelector->insertItem( Name ); + ProfileRacoonSelector->insertItem( Name ); + ProfileIpsecSelector->insertItem( Name ); + ProfileCiscoSelector->insertItem( Name ); + ProfileCmdExecBeforeConnectSelector->insertItem( Name ); + ProfileCmdExecBeforeDisconnectSelector->insertItem( Name ); + ProfileCmdExecAfterConnectSelector->insertItem( Name ); + ProfileCmdExecAfterDisconnectSelector->insertItem( Name ); + + profileChanged( Name ); +} diff --git a/src/preferencesdialog.h b/src/preferencesdialog.h new file mode 100644 index 0000000..20b88db --- /dev/null +++ b/src/preferencesdialog.h @@ -0,0 +1,248 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef PREFERENCESDIALOG_H +#define PREFERENCESDIALOG_H + +#include + +#include +#include +#include +#include +#include + +#include "vpnaccountdata.h" + +// content +#include "configdebugoptions.h" +#include "configgeneraloptions.h" +#include "configconnectoptions.h" +#include "configlogoptions.h" +#include "configdaemonoptions.h" +#include "confighelperprogramoptions.h" +#include "profilecertoptions.h" +#include "profilesmartcardoptions.h" +#include "profilepskoptions.h" +#include "profileciscooptions.h" +#include "profilecmdexecafterconnectoptions.h" +#include "profilecmdexecafterdisconnectoptions.h" +#include "profilecmdexecbeforeconnectoptions.h" +#include "profilecmdexecbeforedisconnectoptions.h" +#include "profilegeneraloptions.h" +#include "profilenetworkgeneraloptions.h" +#include "profilenetworknatoptions.h" +#include "profilenetworkhttpproxyoptions.h" +#include "profilenetworkrouteoptions.h" +#include "profilenetworkvirtualipoptions.h" +#include "profileopenvpnoptions.h" +#include "profilepptpoptions.h" +#include "profileracoonoptions.h" +#include "profileipsecoptions.h" +#include "profilevtunoptions.h" +#include "profilesshoptions.h" +#include "profileuseroptions.h" + + +/** +@author Christoph Thielecke +*/ +class PreferencesDialog : public KDialogBase +{ + Q_OBJECT +public: + + /** + * Constructor + * @param parent parent widget + * @param app pointer to main application + * @param LogOutput textedit for debug messages + * @param GlobalConfig pointer to configuration object + * @param showOnlyProfiles view mode. true: show as profile manager, false: show as preferences dialog + * @return + */ + PreferencesDialog( QWidget *parent, QApplication *app,QTextEdit *LogOutput, KVpncConfig *GlobalConfig, bool showOnlyProfiles); + ~PreferencesDialog(); + +public slots: + void accept(); + void reject(); + void slotApply(); + void authTypeChanged( int authtype ); + void connectionTypeChanged( int connectiontype ); + void profileChanged( const QString& itemtext ); + void saveSessionClicked(); + void deleteSessionClicked(); + void renameSessionClicked(); + void newSessionClicked(); + void importCertificate(); + void pageChanged(QWidget *); + void userAuthToggled(bool); + void useUdpToggled(bool); + void useSpecialServerSmartcardificateToggled(bool); + void applicationVersionToggled(bool); + void IkeGroupToggled(bool); + void perfectForwardSecurityToggled(bool); + void singleDesToggled(bool); + void useKwalletToggled(bool); + void dpdToggled(bool); + void useCiscoCertStoreToggled(bool); + void natModeToggled( const QString &); + void slotProfileCreated(QString Name); + +private slots: + void OpenvpnPathChanged(const QString&); + void FreeswanPathChanged(const QString&); + void PppdPathChanged(const QString&); + void PptpPathChanged(const QString&); + void RacoonPathChanged(const QString&); + void VpncPathChanged(const QString&); + void CiscoVpncPathChanged(const QString&); + void L2tpdPathChanged(const QString&); + void Xl2tpdPathChanged(const QString&); + void Openl2tpPathChanged(const QString&); + void VtundPathChanged(const QString&); + void SshPathChanged(const QString&); + void showEvent(QShowEvent* e); + void detectPkcs11Ids(); + void detectPkcs11Slots(); + void localPortToggled(bool); + void tunnelDeviceTypeChanged(const QString &); + void useXauthToggled(bool); + void slotStatusMsg ( const QString &text, int id ); + bool getVpncHasHybridSupport(); + + +protected: + void setupGui(); + QPtrList *AccountList; + QTextEdit *LogOutput; + VpnAccountData *currentProfile; + KVpncConfig *GlobalConfig; + QString lastProfileName; + int KvpncDebugLevel; + bool canAccept; + bool configChanged; + QPixmap ok_icon; + QPixmap wrong_icon; + QScrollView* DaemonScrollView; + QStringList CiscoCerts; + QStringList CiscoCaCerts; + +private: + QWidget *prev_page; + QWidget *current_page; + +public: + QApplication *app; + + /* -- option pages -- */ + // Kvpnc + ConfigGeneralOptions *GeneralOptionsWidget; + ConfigDebugOptions *DebugOptionsWidget; + ConfigConnectOptions *ConnectOptionsWidget; + ConfigLogOptions *LogOptionsWidget; + + // programs + ConfigDaemonOptions *ConfigDaemonOptionsWidget; + ConfigHelperProgramOptions *HelperProgramOptionsWidget; + + // profile + ProfileGeneralOptions *ProfileGeneralOptionsWidget; + ProfileNetworkRouteOptions *ProfileNetworkRouteOptionsWidget; + ProfileNetworkGeneralOptions *ProfileNetworkGeneralOptionsWidget; + ProfileNetworkNatOptions *ProfileNetworkNatOptionsWidget; + ProfileNetworkVirtualIpOptions *ProfileNetworkVirtualIpOptionsWidget; + ProfileCertOptions *ProfileCertOptionsWidget; + ProfileSmartcardOptions *ProfileSmartcardOptionsWidget; + ProfilePskOptions *ProfilePskOptionsWidget; + ProfileUserOptions *ProfileUserOptionsWidget; + ProfileOpenvpnOptions *ProfileOpenvpnOptionsWidget; + ProfileNetworkHttpProxyOptions *ProfileNetworkHttpProxyOptionsWidget; + ProfilePptpOptions *ProfilePptpOptionsWidget; + ProfileRacoonOptions *ProfileRacoonOptionsWidget; + ProfileIpsecOptions *ProfileIpsecOptionsWidget; + ProfileCiscoOptions *ProfileCiscoOptionsWidget; + ProfileVtunOptions *ProfileVtunOptionsWidget; + ProfileSshOptions *ProfileSshOptionsWidget; + ProfileCmdExecBeforeConnectOptions *ProfileCmdExecBeforeConnectOptionsWidget; + ProfileCmdExecBeforeDisconnectOptions *ProfileCmdExecBeforeDisconnectOptionsWidget; + ProfileCmdExecAfterConnectOptions *ProfileCmdExecAfterConnectOptionsWidget; + ProfileCmdExecAfterDisconnectOptions *ProfileCmdExecAfterDisconnectOptionsWidget; + + QFrame* ProfileNetworkRouteOptionsFrame; + QFrame* ConfigConnectOptionsFrame; + QFrame* DaemonOptionsFrame; + QFrame* DebugFrame; + QFrame* LogFrame; + QFrame* HelperProgramFrame; + QFrame* ProfileGeneralOptionsFrame; + QFrame* ProfileUserOptionsFrame; + QFrame* ProfileCertOptionsFrame; + QFrame* ProfileCiscoOptionsFrame; + QFrame* ProfileNetworkHttpProxyOptionsFrame; + QFrame* ProfileCmdExecAfterConnectOptionsFrame; + QFrame* ProfileCmdExecBeforeDisconnectOptionsFrame; + QFrame* ProfileCmdExecAfterDisconnectOptionsFrame; + QFrame* ProfileCmdExecBeforeConnectOptionsFrame; + QFrame* GeneralFrame; + QFrame* ProfileSmartcardOptionsFrame; + QFrame* ProfilePskOptionsFrame; + QFrame* ProfileNetworkGeneralOptionsFrame; + QFrame* ProfileNetworkNatOptionsFrame; + QFrame* ProfileNetworkVirtualIpOptionsFrame; + QFrame* ProfileRacoonOptionsFrame; + QFrame* ProfileIpsecOptionsFrame; + QFrame* ProfileOpenvpnOptionsFrame; + QFrame* ProfilePptpOptionsFrame; + QFrame* ProfileVtunOptionsFrame; + QFrame* ProfileSshOptionsFrame; + + + QComboBox *ProfileGeneralSelector; + QComboBox *ProfileNetworkRouteSelector; + QComboBox *ProfileNetworkGeneralSelector; + QComboBox *ProfileNetworkNatSelector; + QComboBox *ProfileNetworkVirtualIpSelector; + QComboBox *ProfileCertSelector; + QComboBox *ProfileSmartcardSelector; + QComboBox *ProfilePskSelector; + QComboBox *ProfileUserSelector; + QComboBox *ProfileOpenvpnSelector; + QComboBox *ProfileNetworkHttpProxySelector; + QComboBox *ProfilePptpSelector; + QComboBox *ProfileRacoonSelector; + QComboBox *ProfileIpsecSelector; + QComboBox *ProfileCiscoSelector; + QComboBox *ProfileVtunSelector; + QComboBox *ProfileSshSelector; + QComboBox *ProfileCmdExecBeforeConnectSelector; + QComboBox *ProfileCmdExecBeforeDisconnectSelector; + QComboBox *ProfileCmdExecAfterConnectSelector; + QComboBox *ProfileCmdExecAfterDisconnectSelector; + + + + bool profileAddedOrDeleted; + bool profileHasChanged; + bool showOnlyProfiles; + QString NewProfileName; +}; + +#endif diff --git a/src/profilecertoptions.cpp b/src/profilecertoptions.cpp new file mode 100644 index 0000000..3558144 --- /dev/null +++ b/src/profilecertoptions.cpp @@ -0,0 +1,67 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "profilecertoptions.h" + +#include +#include +#include +#include +#include +#include +#include +#include "widgetnotifyhelper.h" +#include + +ProfileCertOptions::ProfileCertOptions(QWidget *parent) + : ProfileCertOptionsBase(parent) +{ + WidgetNotifyHelper h; + h.setupChangedAction(this); + dialogModified=false; +} + + +ProfileCertOptions::~ProfileCertOptions() +{} + +void ProfileCertOptions::dialogChanged() +{ +// std::cout << "ProfileCertOptions::dialogChanged()" << std::endl; + dialogModified=true; +} + +void ProfileCertOptions::useSpecialServerCertificateToggled(bool) +{ + if (UseSpecialServerCertificateCheckBox->isChecked()) + { + SpecialServerCertificateURLRequester->setEnabled(TRUE); + } + else + { + SpecialServerCertificateURLRequester->setEnabled(FALSE); + } +} + + + + + + + diff --git a/src/profilecertoptions.h b/src/profilecertoptions.h new file mode 100644 index 0000000..6aef6ba --- /dev/null +++ b/src/profilecertoptions.h @@ -0,0 +1,48 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef PROFILECERTOPTIONS_H +#define PROFILECERTOPTIONS_H + +#include "profilecertoptionsbase.h" +#include + +/** +@author Christoph Thielecke +*/ +class ProfileCertOptions : public ProfileCertOptionsBase +{ +Q_OBJECT +public: + ProfileCertOptions(QWidget *parent); + ~ProfileCertOptions(); + bool dialogModified; + +public slots: + void useSpecialServerCertificateToggled(bool); + +private slots: + void dialogChanged(); + +signals: + void changed(); + +}; + +#endif diff --git a/src/profilecertoptionsbase.ui b/src/profilecertoptionsbase.ui new file mode 100644 index 0000000..6fa704c --- /dev/null +++ b/src/profilecertoptionsbase.ui @@ -0,0 +1,749 @@ + +ProfileCertOptionsBase + + + ProfileCertOptionsBase + + + + 0 + 0 + 604 + 517 + + + + + 1 + 1 + 0 + 0 + + + + Certificate + + + + unnamed + + + + layout43 + + + + unnamed + + + + layout42 + + + + unnamed + + + + layout41 + + + + unnamed + + + + layout65 + + + + unnamed + + + + UseMailAddressAsIdentifierCheckBox + + + Use e&mail address as identifier + + + Alt+M + + + + + spacer183 + + + Horizontal + + + Expanding + + + + 80 + 21 + + + + + + + + layout63 + + + + unnamed + + + + spacer44 + + + Horizontal + + + Expanding + + + + 21 + 20 + + + + + + AllowEmptyPrivateKeyPasswordCheckBox + + + Allo&w empty private key passphrase + + + Alt+W + + + + + + + layout38 + + + + unnamed + + + + LabelAuthType + + + Authentication type: + + + + + spacer23 + + + Horizontal + + + Expanding + + + + 330 + 20 + + + + + + AuthTypeComboBox + + + Authentication type + + + + + + + privkeypathURLRequester + + + Path to the private key file + + + + + layout9 + + + + unnamed + + + + LabelCertificatePath + + + Certificates path: + + + + + spacer21 + + + Horizontal + + + Expanding + + + + 115 + 20 + + + + + + + + layout81 + + + + unnamed + + + + x509certURLRequester + + + + 50 + 0 + + + + Path to the certificate file + + + + + x509certComboBox + + + + + + + layout4 + + + + unnamed + + + + LabelPrivateKeyPassword + + + Private key passphrase: + + + + + spacer19 + + + Horizontal + + + Expanding + + + + 75 + 20 + + + + + + + + layout41 + + + + unnamed + + + + spacer103 + + + Horizontal + + + Expanding + + + + 20 + 31 + + + + + + ImportCertificatePushButton + + + + 1 + 0 + 0 + 0 + + + + Import p1&2 Certificate... + + + Alt+2 + + + Import a certificate in P12 format + + + Here you can import a certificate in P12 format. You will get it from your administrator if needed. + + + + + + + UseCiscoCertStoreSpacer + + + Horizontal + + + Expanding + + + + 267 + 21 + + + + + + layout5 + + + + unnamed + + + + LabelPrivateKeyPath + + + Private key path: + + + + + spacer22 + + + Horizontal + + + Expanding + + + + 109 + 20 + + + + + + + + layout37 + + + + unnamed + + + + CaCertpathURLRequester + + + CA certificate path + + + + + CaCertpathComboBox + + + + + + + layout63_2 + + + + unnamed + + + + spacer44_2 + + + Horizontal + + + Expanding + + + + 21 + 20 + + + + + + VerifyCaCertCheckBox + + + false + + + Verify CA certificate of peer + + + + + + + + + + layout6_2 + + + + unnamed + + + + UseCiscoCertStoreCheckBox + + + Use &Cisco certificate store + + + Alt+C + + + + + spacer25_2_3 + + + Horizontal + + + Expanding + + + + 16 + 20 + + + + + + + + PrivkeyPasswordEdit + + + Password + + + Passphrase to decrypt the private key + + + + + layout10 + + + + unnamed + + + + LabelCertificate + + + Certificate: + + + + + spacer17 + + + Horizontal + + + Expanding + + + + 152 + 20 + + + + + + + + layout8 + + + + unnamed + + + + LabelCaCertificatePath + + + CA certificate: + + + + + spacer21_2 + + + Horizontal + + + Expanding + + + + 93 + 20 + + + + + + + + layout6 + + + + unnamed + + + + UseSpecialServerCertificateCheckBox + + + &Use special server certificate + + + Alt+U + + + + + spacer25_2 + + + Horizontal + + + Expanding + + + + 16 + 20 + + + + + + + + certpathURLRequester + + + Path to the certificates, used if no absolute path is given. + + + + + SpecialServerCertificateURLRequester + + + false + + + + + layout64 + + + + unnamed + + + + SavePrivateKeyPasswordCheckBox + + + Save private ke&y passphrase + + + Alt+Y + + + + + spacer25_2_2 + + + Horizontal + + + Expanding + + + + 100 + 20 + + + + + + + + + + spacer14 + + + Vertical + + + Expanding + + + + 21 + 19 + + + + + + + + spacer31 + + + Horizontal + + + Expanding + + + + 16 + 20 + + + + + + + + + + UseSpecialServerCertificateCheckBox + toggled(bool) + ProfileCertOptionsBase + useSpecialServerCertificateToggled(bool) + + + + AuthTypeComboBox + x509certURLRequester + certpathURLRequester + CaCertpathURLRequester + UseSpecialServerCertificateCheckBox + SpecialServerCertificateURLRequester + privkeypathURLRequester + PrivkeyPasswordEdit + SavePrivateKeyPasswordCheckBox + UseMailAddressAsIdentifierCheckBox + AllowEmptyPrivateKeyPasswordCheckBox + ImportCertificatePushButton + + + useSpecialRemoteIDToggled(bool) + useSpecialServerCertificateToggled(bool) + + + + kcombobox.h + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + kcombobox.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + kcombobox.h + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + + diff --git a/src/profileciscooptions.cpp b/src/profileciscooptions.cpp new file mode 100644 index 0000000..fb4513a --- /dev/null +++ b/src/profileciscooptions.cpp @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "profileciscooptions.h" + +#include "widgetnotifyhelper.h" +#include + +ProfileCiscoOptions::ProfileCiscoOptions(QWidget *parent) + : ProfileCiscoOptionsBase(parent) +{ + WidgetNotifyHelper h; + h.setupChangedAction(this); + dialogModified=false; +} + + +ProfileCiscoOptions::~ProfileCiscoOptions() +{} + +void ProfileCiscoOptions::dialogChanged() +{ +// std::cout << "ProfileCiscoOptions::dialogChanged()" << std::endl; + dialogModified=true; +} + + + + diff --git a/src/profileciscooptions.h b/src/profileciscooptions.h new file mode 100644 index 0000000..f68759f --- /dev/null +++ b/src/profileciscooptions.h @@ -0,0 +1,47 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef PROFILECISCOOPTIONS_H +#define PROFILECISCOOPTIONS_H + +#include "profileciscooptionsbase.h" +#include + +/** +@author Christoph Thielecke +*/ +class ProfileCiscoOptions : public ProfileCiscoOptionsBase +{ +Q_OBJECT +public: + ProfileCiscoOptions(QWidget *parent); + ~ProfileCiscoOptions(); + bool dialogModified; + + +private slots: + void dialogChanged(); + +signals: + void changed(); + +}; + + +#endif diff --git a/src/profileciscooptionsbase.ui b/src/profileciscooptionsbase.ui new file mode 100644 index 0000000..452bc20 --- /dev/null +++ b/src/profileciscooptionsbase.ui @@ -0,0 +1,755 @@ + +ProfileCiscoOptionsBase + + + ProfileCiscoOptionsBase + + + + 0 + 0 + 672 + 293 + + + + Cisco + + + + unnamed + + + + layout42 + + + + unnamed + + + + layout41 + + + + unnamed + + + + layout15 + + + + unnamed + + + + LabelID_2 + + + Peer timeout: + + + Peer timeout + + + + + spacer17 + + + Horizontal + + + Expanding + + + + 131 + 20 + + + + + + PeerTimeoutIntNumInput + + + 0 + + + After this number of seconds KVpnc reconnects. Value of 0 disables timeout. + + + + + + + layout36 + + + + unnamed + + + + ApplicationVersionCheckbox + + + Application &version: + + + Alt+V + + + Send an own application version string + + + + + spacer32 + + + Horizontal + + + Expanding + + + + 121 + 21 + + + + + + + + layout16 + + + + unnamed + + + + LocalPortCheckbox + + + Use &local port for ISAKMP: + + + Alt+L + + + + + spacer18 + + + Horizontal + + + Expanding + + + + 81 + 21 + + + + + + LocalPortSpinbox + + + false + + + 65535 + + + 500 + + + Local port number + + + + + + + layout35_2 + + + + unnamed + + + + DisableDataEncryptionCheckbox + + + true + + + Disable &data encryption + + + Alt+D + + + disables the encrytion for data + + + + + spacer31_2 + + + Horizontal + + + Expanding + + + + 91 + 21 + + + + + + + + layout26 + + + + unnamed + + + + CiscoNatModeLabel + + + Cisco NAT mode: + + + + + spacer34_2 + + + Horizontal + + + Expanding + + + + 87 + 20 + + + + + + CiscoNatModeComboBox + + + true + + + Sets the NAT traversal mode for cisco (vpnc >= 0.4.x) + +* natt - NAT-T as defined in RFC3947 +* force-natt - always use NAT-T encapsulation even without presence of a NAT device (useful if the OS captures all ESP traffic) +* cisco-udp - Cisco proprietary UDP encapsulation, commonly over Port 10000 + + Automatic keying has a property called perfect forward secrecy. This is the Diffie Helman group for PFS. + + + Sets the NAT traversal mode for cisco (vpnc >= 0.4.x) + +* natt - NAT-T as defined in RFC3947 +* force-natt - always use NAT-T encapsulation even without presence of a NAT device (useful if the OS captures all ESP traffic) +* cisco-udp - Cisco proprietary UDP encapsulation, commonly over Port 10000 + + + + + + + + layout22 + + + + unnamed + + + + LabelID + + + IPSec ID: + + + + + spacer15 + + + Horizontal + + + Expanding + + + + 50 + 20 + + + + + + IDLineEdit + + + IPSec ID of the remote side + + + + + + + layout18 + + + + unnamed + + + + PerfectForwardSecurityCheckbox + + + Perfect for&ward secrecy (PFS): + + + Alt+W + + + Use perfect forward secrety (PFS) + + + + + spacer34 + + + Horizontal + + + Expanding + + + + 16 + 20 + + + + + + PerfectForwardSecrecyCombobox + + + false + + + Diffie Helman group for Perfect Forward Secrecy + Automatic keying has a property called perfect forward secrecy. This is the Diffie Helman group for PFS. + + + This is the Diffie Helman group for PFS. +The following assignment will is used: +server = DH group is recieved from server (cisco only) +nopfs = no pfs is used +dh1 = modp768 +dh2 = modp1024 +dh5 = modp1536 +d14 = modp2048 (racoon only) +dh15= modp3072 (racoon only) +dh16 = modp4096 (racoon only) +dh17 = modp6144 (racoon only) +dh18 = modp8192 (racoon only) + + + + + + + layout35 + + + + unnamed + + + + UseGlobalIpsecSecretCheckbox + + + &Use global IPSec secret + + + Alt+U + + + Use global IPSec secret from /etc/vpnc/default.conf + + + + + spacer31 + + + Horizontal + + + Expanding + + + + 91 + 21 + + + + + + + + ApplicationVersionLineedit + + + false + + + + + + Application version string + + + + + layout17 + + + + unnamed + + + + IkeGroupCheckbox + + + &IKE DH group: + + + Alt+I + + + Use special Diffie Hellman group + + + + + spacer19 + + + Horizontal + + + Expanding + + + + 141 + 21 + + + + + + IkeGroupCombobox + + + false + + + Diffie Hellman group + + + This define the group used for the Diffie-Hellman exponentiations. The following assignment is used: +dh1 = modp768 +dh2 = modp1024 +dh5 = modp1536 +d14 = modp2048 (only racoon) +dh15 = modp3072 (only racoon) +dh16 = modp4096 (only racoon) +dh17 = modp6144 (only racoon) +dh18 = modp8192 (only racoon) + + + + + + + UseXauthInteractiveCheckBox + + + E&nable interactive extended authentication + + + Alt+N + + + + + + + + layout40 + + + + unnamed + + + + AllowEmptyGroupPasswordCheckBox + + + Allow empt&y group password (insecure!) + + + Alt+Y + + + Allow an empty group password (not recommended, insecure) + + + + + spacer37 + + + Vertical + + + Expanding + + + + 20 + 21 + + + + + + + + layout118 + + + + unnamed + + + + layout9 + + + + unnamed + + + + + + spacer59 + + + Horizontal + + + Expanding + + + + 439 + 21 + + + + + + + + layout40 + + + + unnamed + + + + EnableDpdIdleTimeoutCheckbox + + + Enable DPD idle ti&meout: + + + Alt+M + + + Use DPD (Dead Peer Detection) + + + This enables DPD. Requires vpnc >= 0.5.0. + + + + + spacer34_3 + + + Horizontal + + + Expanding + + + + 51 + 20 + + + + + + DpdIdleTimeoutSpinbox + + + false + + + 86400 + + + 10 + + + 10 + + + 300 + + + DPD idle timeout + + + This is the value of DPD (Dead Peer Detection) timeout. + + + + + + + layout39 + + + + unnamed + + + + SingleDesCheckbox + + + Allow single DES encr&yption + + + Alt+Y + + + Allow single DES encryption (insecure) + + + + + spacer35 + + + Horizontal + + + Expanding + + + + 81 + 21 + + + + + + + + + + spacer4 + + + Vertical + + + Expanding + + + + 20 + 37 + + + + + + + + + IDLineEdit + AllowEmptyGroupPasswordCheckBox + + + + knuminput.h + knuminput.h + kcombobox.h + klineedit.h + kcombobox.h + klineedit.h + kcombobox.h + + diff --git a/src/profilecmdexecafterconnectoptions.cpp b/src/profilecmdexecafterconnectoptions.cpp new file mode 100644 index 0000000..faa9ec8 --- /dev/null +++ b/src/profilecmdexecafterconnectoptions.cpp @@ -0,0 +1,64 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "profilecmdexecafterconnectoptions.h" + +#include +#include +#include +#include +#include "widgetnotifyhelper.h" +#include + +ProfileCmdExecAfterConnectOptions::ProfileCmdExecAfterConnectOptions(QWidget *parent) + : ProfileCmdExecAfterConnectOptionsBase(parent) +{ + WidgetNotifyHelper h; + h.setupChangedAction(this); + dialogModified=false; +} + + +ProfileCmdExecAfterConnectOptions::~ProfileCmdExecAfterConnectOptions() +{} + +void ProfileCmdExecAfterConnectOptions::execCmdAfterConnectToggled(bool) +{ + if (ExcuteCmdAfterConnectCheckBox->isChecked()) + { + CmdAfterConnectTextEdit->setEnabled( TRUE ); + CommandAfterConnectDelayTimeNumInput->setEnabled( TRUE ); + CommandAfterConnectDelayTimeNumInputLabel->setEnabled( TRUE ); + } + else + { + CmdAfterConnectTextEdit->setEnabled( FALSE ); + CommandAfterConnectDelayTimeNumInput->setEnabled( FALSE ); + CommandAfterConnectDelayTimeNumInputLabel->setEnabled( FALSE ); + } +} + +void ProfileCmdExecAfterConnectOptions::dialogChanged() +{ +// std::cout << "ProfileCmdExecAfterConnectOptions::dialogChanged()" << std::endl; + dialogModified=true; +} + + + diff --git a/src/profilecmdexecafterconnectoptions.h b/src/profilecmdexecafterconnectoptions.h new file mode 100644 index 0000000..ad47e45 --- /dev/null +++ b/src/profilecmdexecafterconnectoptions.h @@ -0,0 +1,48 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef PROFILECMDEXECAFTERCONNECTOPTIONS_H +#define PROFILECMDEXECAFTERCONNECTOPTIONS_H + +#include "profilecmdexecafterconnectoptionsbase.h" +#include + +/** +@author Christoph Thielecke +*/ +class ProfileCmdExecAfterConnectOptions : public ProfileCmdExecAfterConnectOptionsBase +{ +Q_OBJECT +public: + ProfileCmdExecAfterConnectOptions(QWidget *parent); + ~ProfileCmdExecAfterConnectOptions(); + bool dialogModified; + +public slots: + void execCmdAfterConnectToggled(bool); + +private slots: + void dialogChanged(); + +signals: + void changed(); + +}; + +#endif diff --git a/src/profilecmdexecafterconnectoptionsbase.ui b/src/profilecmdexecafterconnectoptionsbase.ui new file mode 100644 index 0000000..2dd45ea --- /dev/null +++ b/src/profilecmdexecafterconnectoptionsbase.ui @@ -0,0 +1,152 @@ + +ProfileCmdExecAfterConnectOptionsBase + + + ProfileCmdExecAfterConnectOptionsBase + + + + 0 + 0 + 383 + 425 + + + + + 3 + 3 + 0 + 0 + + + + Command Execution After Connect + + + + unnamed + + + + layout2 + + + + unnamed + + + + ExcuteCmdAfterConnectCheckBox + + + E&xecute command after connect + + + Alt+X + + + Execute specified command after connect + + + Check this to execute specified command after every successful connect. + + + + + CmdAfterConnectTextEdit + + + false + + + + 0 + 300 + + + + 0 + + + Command to execute after sucessful connect. <br>Normal shell commands are accepted. + + + Command to execute after sucessful connect. <br>Normal shell commands are accepted. + + + + + layout1 + + + + unnamed + + + + CommandAfterConnectDelayTimeNumInputLabel + + + Delay time: + + + + + spacer1 + + + Horizontal + + + Expanding + + + + 111 + 20 + + + + + + CommandAfterConnectDelayTimeNumInput + + + 3 + + + 0 + + + 20 + + + + + + + + + + + ExcuteCmdAfterConnectCheckBox + toggled(bool) + ProfileCmdExecAfterConnectOptionsBase + execCmdAfterConnectToggled(bool) + + + + ExcuteCmdAfterConnectCheckBox + CmdAfterConnectTextEdit + + + execCmdAfterConnectToggled(bool) + + + + ktextedit.h + knuminput.h + knuminput.h + + diff --git a/src/profilecmdexecafterdisconnectoptions.cpp b/src/profilecmdexecafterdisconnectoptions.cpp new file mode 100644 index 0000000..eed4bf6 --- /dev/null +++ b/src/profilecmdexecafterdisconnectoptions.cpp @@ -0,0 +1,56 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "profilecmdexecafterdisconnectoptions.h" + +#include +#include +#include "widgetnotifyhelper.h" +#include + + + +ProfileCmdExecAfterDisconnectOptions::ProfileCmdExecAfterDisconnectOptions(QWidget *parent) + : ProfileCmdExecAfterDisconnectOptionsBase(parent) +{ + WidgetNotifyHelper h; + h.setupChangedAction(this); + dialogModified=false; +} + + +ProfileCmdExecAfterDisconnectOptions::~ProfileCmdExecAfterDisconnectOptions() +{} + +void ProfileCmdExecAfterDisconnectOptions::execCmdAfterDisconnectToggled(bool) +{ + if (ExcuteCmdAfterDisconnectCheckBox->isChecked()) + CmdAfterDisconnectTextEdit->setEnabled( TRUE ); + else + CmdAfterDisconnectTextEdit->setEnabled( FALSE ); +} + +void ProfileCmdExecAfterDisconnectOptions::dialogChanged() +{ + std::cout << "ProfileCmdExecAfterDisconnectOptions::dialogChanged()" << std::endl; + dialogModified=true; +} + + + diff --git a/src/profilecmdexecafterdisconnectoptions.h b/src/profilecmdexecafterdisconnectoptions.h new file mode 100644 index 0000000..4ed3d16 --- /dev/null +++ b/src/profilecmdexecafterdisconnectoptions.h @@ -0,0 +1,48 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef PROFILECMDEXECAFTERDISCONNECTOPTIONS_H +#define PROFILECMDEXECAFTERDISCONNECTOPTIONS_H + +#include "profilecmdexecafterdisconnectoptionsbase.h" +#include + +/** +@author Christoph Thielecke +*/ +class ProfileCmdExecAfterDisconnectOptions : public ProfileCmdExecAfterDisconnectOptionsBase +{ +Q_OBJECT +public: + ProfileCmdExecAfterDisconnectOptions(QWidget *parent); + ~ProfileCmdExecAfterDisconnectOptions(); + bool dialogModified; + +public slots: + void execCmdAfterDisconnectToggled(bool); + +private slots: + void dialogChanged(); + +signals: + void changed(); + +}; + +#endif diff --git a/src/profilecmdexecafterdisconnectoptionsbase.ui b/src/profilecmdexecafterdisconnectoptionsbase.ui new file mode 100644 index 0000000..7f859a4 --- /dev/null +++ b/src/profilecmdexecafterdisconnectoptionsbase.ui @@ -0,0 +1,91 @@ + +ProfileCmdExecAfterDisconnectOptionsBase + + + ProfileCmdExecAfterDisconnectOptionsBase + + + + 0 + 0 + 367 + 449 + + + + + 3 + 3 + 0 + 0 + + + + Command Execute After Disconnect + + + + unnamed + + + + ExcuteCmdAfterDisconnectCheckBox + + + Execute co&mmand after disconnect + + + Alt+M + + + Execute specified command after disconnect + + + Check this to execute specified command after every disconnect. + + + + + CmdAfterDisconnectTextEdit + + + false + + + + 0 + 300 + + + + 0 + + + Command to execute after successful disconnect. <br>Normal shell commands are accepted. + + + Command to execute after successful disconnect. <br>Normal shell commands are accepted. + + + + + + + ExcuteCmdAfterDisconnectCheckBox + toggled(bool) + ProfileCmdExecAfterDisconnectOptionsBase + execCmdAfterDisconnectToggled(bool) + + + + ExcuteCmdAfterDisconnectCheckBox + CmdAfterDisconnectTextEdit + + + execCmdAfterDisconnectToggled(bool) + + + + ktextedit.h + + diff --git a/src/profilecmdexecbeforeconnectoptions.cpp b/src/profilecmdexecbeforeconnectoptions.cpp new file mode 100644 index 0000000..44a7da7 --- /dev/null +++ b/src/profilecmdexecbeforeconnectoptions.cpp @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "profilecmdexecbeforeconnectoptions.h" + +#include +#include +#include "widgetnotifyhelper.h" +#include + +ProfileCmdExecBeforeConnectOptions::ProfileCmdExecBeforeConnectOptions(QWidget *parent) + : ProfileCmdExecBeforeConnectOptionsBase(parent) +{ + WidgetNotifyHelper h; + h.setupChangedAction(this); + dialogModified=false; +} + + +ProfileCmdExecBeforeConnectOptions::~ProfileCmdExecBeforeConnectOptions() +{} + +void ProfileCmdExecBeforeConnectOptions::execCmdBeforeConnectToggled(bool) +{ + if (ExcuteCmdBeforeConnectCheckBox->isChecked()) + CmdBeforeConnectTextEdit->setEnabled( TRUE ); + else + CmdBeforeConnectTextEdit->setEnabled( FALSE ); +} + +void ProfileCmdExecBeforeConnectOptions::dialogChanged() +{ +// std::cout << "ProfileCmdExecBeforeConnectOptions::dialogChanged()" << std::endl; + dialogModified=true; +} + + diff --git a/src/profilecmdexecbeforeconnectoptions.h b/src/profilecmdexecbeforeconnectoptions.h new file mode 100644 index 0000000..5515322 --- /dev/null +++ b/src/profilecmdexecbeforeconnectoptions.h @@ -0,0 +1,48 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef PROFILECMDEXECBEFORECONNECTOPTIONS_H +#define PROFILECMDEXECBEFORECONNECTOPTIONS_H + +#include "profilecmdexecbeforeconnectoptionsbase.h" +#include + +/** +@author Christoph Thielecke +*/ +class ProfileCmdExecBeforeConnectOptions : public ProfileCmdExecBeforeConnectOptionsBase +{ +Q_OBJECT +public: + ProfileCmdExecBeforeConnectOptions(QWidget *parent); + ~ProfileCmdExecBeforeConnectOptions(); + bool dialogModified; + +public slots: + void execCmdBeforeConnectToggled(bool); + +private slots: + void dialogChanged(); + +signals: + void changed(); + +}; + +#endif diff --git a/src/profilecmdexecbeforeconnectoptionsbase.ui b/src/profilecmdexecbeforeconnectoptionsbase.ui new file mode 100644 index 0000000..f244c7c --- /dev/null +++ b/src/profilecmdexecbeforeconnectoptionsbase.ui @@ -0,0 +1,91 @@ + +ProfileCmdExecBeforeConnectOptionsBase + + + ProfileCmdExecBeforeConnectOptionsBase + + + + 0 + 0 + 518 + 458 + + + + + 3 + 3 + 0 + 0 + + + + Command Execution Before Connect + + + + unnamed + + + + ExcuteCmdBeforeConnectCheckBox + + + Execu&te command before connect + + + Alt+T + + + Execute specified commands before connect + + + Check this to execute specified command before every successful connect. + + + + + CmdBeforeConnectTextEdit + + + false + + + + 0 + 300 + + + + 0 + + + Command to execute before connect + + + Command to execute before connect. <br>Normal shell commands are accepted. + + + + + + + ExcuteCmdBeforeConnectCheckBox + toggled(bool) + ProfileCmdExecBeforeConnectOptionsBase + execCmdBeforeConnectToggled(bool) + + + + ExcuteCmdBeforeConnectCheckBox + CmdBeforeConnectTextEdit + + + execCmdBeforeConnectToggled(bool) + + + + ktextedit.h + + diff --git a/src/profilecmdexecbeforedisconnectoptions.cpp b/src/profilecmdexecbeforedisconnectoptions.cpp new file mode 100644 index 0000000..b97847a --- /dev/null +++ b/src/profilecmdexecbeforedisconnectoptions.cpp @@ -0,0 +1,52 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "profilecmdexecbeforedisconnectoptions.h" + +#include +#include +#include "widgetnotifyhelper.h" +#include + +ProfileCmdExecBeforeDisconnectOptions::ProfileCmdExecBeforeDisconnectOptions(QWidget *parent) + : ProfileCmdExecBeforeDisconnectOptionsBase(parent) +{ + WidgetNotifyHelper h; + h.setupChangedAction(this); + dialogModified=false; +} + + +ProfileCmdExecBeforeDisconnectOptions::~ProfileCmdExecBeforeDisconnectOptions() +{} + +void ProfileCmdExecBeforeDisconnectOptions::execCmdBeforeDisconnectToggled(bool) +{ + if (ExcuteCmdBeforeDisconnectCheckBox->isChecked()) + CmdBeforeDisconnectTextEdit->setEnabled( TRUE ); + else + CmdBeforeDisconnectTextEdit->setEnabled( FALSE ); +} +void ProfileCmdExecBeforeDisconnectOptions::dialogChanged() +{ +// std::cout << "ProfileCmdExecBeforeDisconnectOptions::dialogChanged()" << std::endl; + dialogModified=true; +} + + diff --git a/src/profilecmdexecbeforedisconnectoptions.h b/src/profilecmdexecbeforedisconnectoptions.h new file mode 100644 index 0000000..1dcfe49 --- /dev/null +++ b/src/profilecmdexecbeforedisconnectoptions.h @@ -0,0 +1,48 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef PROFILECMDEXECBEFOREDISCONNECTOPTIONS_H +#define PROFILECMDEXECBEFOREDISCONNECTOPTIONS_H + +#include "profilecmdexecbeforedisconnectoptionsbase.h" +#include + +/** +@author Christoph Thielecke +*/ +class ProfileCmdExecBeforeDisconnectOptions : public ProfileCmdExecBeforeDisconnectOptionsBase +{ +Q_OBJECT +public: + ProfileCmdExecBeforeDisconnectOptions(QWidget *parent); + ~ProfileCmdExecBeforeDisconnectOptions(); + bool dialogModified; + +public slots: + void execCmdBeforeDisconnectToggled(bool); + +private slots: + void dialogChanged(); + +signals: + void changed(); + +}; + +#endif diff --git a/src/profilecmdexecbeforedisconnectoptionsbase.ui b/src/profilecmdexecbeforedisconnectoptionsbase.ui new file mode 100644 index 0000000..cf5813b --- /dev/null +++ b/src/profilecmdexecbeforedisconnectoptionsbase.ui @@ -0,0 +1,91 @@ + +ProfileCmdExecBeforeDisconnectOptionsBase + + + ProfileCmdExecBeforeDisconnectOptionsBase + + + + 0 + 0 + 469 + 432 + + + + + 3 + 3 + 0 + 0 + + + + Command Execution Before Disconnect + + + + unnamed + + + + ExcuteCmdBeforeDisconnectCheckBox + + + Execute comm&and before disconnect + + + Alt+A + + + Execute specified command before disconnect + + + Check this to execute specified command before every disconnect. + + + + + CmdBeforeDisconnectTextEdit + + + false + + + + 0 + 300 + + + + 0 + + + Command to execute before disconnect. <br>Normal shell commands are accepted. + + + Command to execute before disconnect. <br>Normal shell commands are accepted. + + + + + + + ExcuteCmdBeforeDisconnectCheckBox + toggled(bool) + ProfileCmdExecBeforeDisconnectOptionsBase + execCmdBeforeDisconnectToggled(bool) + + + + ExcuteCmdBeforeDisconnectCheckBox + CmdBeforeDisconnectTextEdit + + + execCmdBeforeDisconnectToggled(bool) + + + + ktextedit.h + + diff --git a/src/profilegeneraloptions.cpp b/src/profilegeneraloptions.cpp new file mode 100644 index 0000000..be04000 --- /dev/null +++ b/src/profilegeneraloptions.cpp @@ -0,0 +1,55 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "profilegeneraloptions.h" +#include +#include +#include +#include +#include +#include + +#include "widgetnotifyhelper.h" +#include + +ProfileGeneralOptions::ProfileGeneralOptions(QWidget *parent, KVpncConfig *GlobalConfig) : ProfileGeneralOptionsBase(parent) +{ + this->GlobalConfig = GlobalConfig; + WidgetNotifyHelper h; + h.setupChangedAction(this); + dialogModified=false; +} + + +ProfileGeneralOptions::~ProfileGeneralOptions() +{} + +void ProfileGeneralOptions::dialogChanged() +{ +// std::cout << "ProfileGeneralOptions::dialogChanged()" << std::endl; + dialogModified=true; +} + + + + + + + + diff --git a/src/profilegeneraloptions.h b/src/profilegeneraloptions.h new file mode 100644 index 0000000..d830998 --- /dev/null +++ b/src/profilegeneraloptions.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef PROFILEGENERALOPTIONS_H +#define PROFILEGENERALOPTIONS_H + +#include "profilegeneraloptionsbase.h" +#include +#include "kvpncconfig.h" + +/** +@author Christoph Thielecke +*/ +class ProfileGeneralOptions : public ProfileGeneralOptionsBase +{ +Q_OBJECT +public: + ProfileGeneralOptions(QWidget *parent, KVpncConfig *GlobalConfig); + ~ProfileGeneralOptions(); + bool dialogModified; + +// public slots: +// void useReconnectAfterDisconnectToggled(bool); +// void useReconnectDelayToggled(bool); +// void UseDnsUpdateToggled(bool); + +protected: + KVpncConfig *GlobalConfig; + +private slots: + void dialogChanged(); + +signals: + void changed(); +}; + +#endif diff --git a/src/profilegeneraloptionsbase.ui b/src/profilegeneraloptionsbase.ui new file mode 100644 index 0000000..713e82c --- /dev/null +++ b/src/profilegeneraloptionsbase.ui @@ -0,0 +1,217 @@ + +ProfileGeneralOptionsBase + + + ProfileGeneralOptionsBase + + + + 0 + 0 + 456 + 240 + + + + General + + + + unnamed + + + + layout49 + + + + unnamed + + + + layout48 + + + + unnamed + + + + LabelGateway_2 + + + Description: + + + + + LabelGateway + + + VPN gateway: + + + + + LabelCommectionType + + + Connection type: + + + + + gatewayLineEdit + + + Hostname or IP address of the VPN gateway + + + + + DescriptionLineEdit + + + Profile description + + + + + ConnectionTypeComboBox + + + Connection type + + + This is the connection type of the profile (e.g. Cisco). + + + + + + + spacer59 + + + Vertical + + + Expanding + + + + 20 + 70 + + + + + + layout11 + + + + unnamed + + + + spacer58 + + + Horizontal + + + Expanding + + + + 92 + 20 + + + + + + RenameSessionPushButton + + + Rena&me + + + Alt+M + + + Rename the current profile + + + + + SaveSessionPushButton + + + Sa&ve + + + Alt+V + + + Save the current profile + + + + + DeleteSessionPushButton + + + Dele&te + + + Alt+T + + + Delete the current profile + + + + + NewSessionPushButton + + + Ne&w + + + Alt+W + + + Create a new profile + + + + + + + + + + DescriptionLineEdit + ConnectionTypeComboBox + gatewayLineEdit + RenameSessionPushButton + SaveSessionPushButton + DeleteSessionPushButton + NewSessionPushButton + + + advancedSettingsClicked() + + + + klineedit.h + klineedit.h + kcombobox.h + kpushbutton.h + kpushbutton.h + kpushbutton.h + kpushbutton.h + + diff --git a/src/profileipsecoptions.cpp b/src/profileipsecoptions.cpp new file mode 100644 index 0000000..8eb3c82 --- /dev/null +++ b/src/profileipsecoptions.cpp @@ -0,0 +1,132 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "profileipsecoptions.h" +#include "profileipsecoptions.h" + +#include +#include +#include +#include +#include +#include +#include +#include "widgetnotifyhelper.h" +#include + +ProfileIpsecOptions::ProfileIpsecOptions(QWidget *parent) : ProfileIpsecOptionsBase(parent) +{ +} + + +ProfileIpsecOptions::~ProfileIpsecOptions() +{ +} +void ProfileIpsecOptions::useRightNextHopToggled(bool) +{ + if (UseRightNextHopCheckBox->isChecked()) + RightNextHopLineEdit->setEnabled(true); + else + RightNextHopLineEdit->setEnabled(false); +} + + +void ProfileIpsecOptions::useLeftNextHopToggled(bool) +{ + if (UseLeftNextHopCheckBox->isChecked()) + LeftNextHopLineEdit->setEnabled(true); + else + LeftNextHopLineEdit->setEnabled(false); +} + + +void ProfileIpsecOptions::dialogChanged() +{ +// std::cout << "ProfileIpsecOptions::dialogChanged()" << std::endl; + dialogModified=true; +} + +void ProfileIpsecOptions::useIkeToggled(bool) +{ + if (UseCustomIkeCheckBox->isChecked()) + IkeGroupBox->setEnabled(true); + else + IkeGroupBox->setEnabled(false); +} + + +void ProfileIpsecOptions::useEspToogled(bool) +{ + if (UseCustomEspCheckBox->isChecked()) + EspGroupBox->setEnabled(true); + else + EspGroupBox->setEnabled(false); +} + +void ProfileIpsecOptions::localIDTypeToggled(const QString& text) +{ + if (text == "asn1dn" || text == i18n("Certificate ID")) + { + LocalIDLineEdit->setDisabled(true); + LocalIDLabel->setDisabled(true); + } + else + { + LocalIDLineEdit->setDisabled(false); + LocalIDLabel->setDisabled(false); + } +} + +void ProfileIpsecOptions::remoteIDTypeToggled(const QString& text) +{ + if (text == "asn1dn" || text == "none") + { + RemoteIDLineEdit->setDisabled(true); + RemoteIDLabel->setDisabled(true); + } + else + { + RemoteIDLineEdit->setDisabled(false); + RemoteIDLabel->setDisabled(false); + } +} + + + +void ProfileIpsecOptions::ikeHelpClicked(int,int) +{ + QWhatsThis::display ( i18n("

IPSec IKE algorithms

You have to specify the IKE values in the following format:\n<encryption algorithm>-<authentication algorithm>\nor\n<encryption algorithm>-<authentication algorithm>-<diffie helman group>

"), QCursor::pos ( ), (QWidget *)IkeHelpActiveLabel); +} + + + +void ProfileIpsecOptions::espHelpClicked(int,int) +{ + QWhatsThis::display ( i18n("

IPSec ESP algorithms

You have to specify the ESP values in the following format:\n<encryption algorithm>-<authentication algorithm>\nor\n<encryption algorithm>-<authentication algorithm>

"), QCursor::pos ( ), (QWidget *)EspHelpActiveLabel); +} + + + +void ProfileIpsecOptions::usePfsToogled(bool) +{ + if (PerfectForwardSecurityCheckbox->isChecked()) + PerfectForwardSecrecyCombobox->setEnabled(true); + else + PerfectForwardSecrecyCombobox->setEnabled(false); +} diff --git a/src/profileipsecoptions.h b/src/profileipsecoptions.h new file mode 100644 index 0000000..fc8e9ef --- /dev/null +++ b/src/profileipsecoptions.h @@ -0,0 +1,61 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef PROFILEIPSECOPTIONS_H +#define PROFILEIPSECOPTIONS_H + + +/** + @author Christoph Thielecke +*/ + +#include "profileipsecoptionsbase.h" +#include "kvpncconfig.h" +#include + + + +class ProfileIpsecOptions : public ProfileIpsecOptionsBase { + Q_OBJECT +public: + ProfileIpsecOptions(QWidget *parent); + ~ProfileIpsecOptions(); + bool dialogModified; + +public slots: + void useRightNextHopToggled(bool); + void useLeftNextHopToggled(bool); + void useEspToogled(bool); + void useIkeToggled(bool); + void localIDTypeToggled(const QString& text); + void remoteIDTypeToggled(const QString&); + void ikeHelpClicked(int,int); + void espHelpClicked(int,int); + void usePfsToogled(bool); + +private slots: + void dialogChanged(); + + +signals: + void changed(); + +}; + +#endif diff --git a/src/profileipsecoptionsbase.ui b/src/profileipsecoptionsbase.ui new file mode 100644 index 0000000..118153a --- /dev/null +++ b/src/profileipsecoptionsbase.ui @@ -0,0 +1,1179 @@ + +ProfileIpsecOptionsBase + + + ProfileIpsecOptionsBase + + + + 0 + 0 + 455 + 305 + + + + FreeSWAN (OpenSWAN) + + + + unnamed + + + + tabWidget2 + + + + GeneralTab + + + General + + + + unnamed + + + + layout33 + + + + unnamed + + + + layout136 + + + + unnamed + + + + HashAlgoTextLabel_2 + + + Exchange mode: + + + + + spacer72 + + + Horizontal + + + Expanding + + + + 199 + 21 + + + + + + + + ExchangeModeComboBox + + + Internet Key Exchange mode + + + + + + + layout137 + + + + unnamed + + + + layout150 + + + + unnamed + + + + IPsecVpnModeTextLabel + + + IPsec VPN mode: + + + + + spacer72_2_3 + + + Horizontal + + + Expanding + + + + 28 + 20 + + + + + + + + IpsecVpnModeCombobox + + + false + + + This is the type of the local ID (default: asn1dn)<br> +<ul> +<li>asn1dn - the type is an ASN.1 distinguished name. Use 'use email address as identifier' in certificate settings if it should be the mail address. If this option is not checked, the DN from the Subject field in the certificate will be used.</li> +<li>address - the type is the IP address.</li> +<li>fqdn - the type is a FQDN (fully-qualified domain name).</li> +<li>keyid - the type is a KEY_ID (file)</li> +<li>user_fqdn - the type is a USER_FQDN (user fully-qualified domain name).</li> +</ul> + Automatic keying has a property called perfect forward secrecy. This is the Diffie Helman group for PFS. + + + This is the type of the local ID (default: asn1dn)<br> +<ul> +<li>asn1dn - the type is an ASN.1 distinguished name. Use 'use email address as identifier' in certificate settings if it should be the mail address. If this option is not checked, the DN from the Subject field in the certificate will be used.</li> +<li>address - the type is the IP address.</li> +<li>fqdn - the type is a FQDN (fully-qualified domain name).</li> +<li>keyid - the type is a KEY_ID (file)</li> +<li>user_fqdn - the type is a USER_FQDN (user fully-qualified domain name).</li> +</ul> + + + + + + + layout43 + + + + unnamed + + + + PerfectForwardSecurityCheckbox + + + Use PFS + + + + + + Use perfect forward secrety (PFS) + + + + + spacer8 + + + Horizontal + + + Expanding + + + + 160 + 21 + + + + + + PerfectForwardSecrecyCombobox + + + false + + + Diffie Helman group for Perfect Forward Secrecy + Automatic keying has a property called perfect forward secrecy. This is the Diffie Helman group for PFS. + + + This is the Diffie Helman group for PFS. +The following assignment will is used: +server = DH group is recieved from server (cisco only) +nopfs = no pfs is used +dh1 = modp768 +dh2 = modp1024 +dh5 = modp1536 +d14 = modp2048 (racoon only) +dh15= modp3072 (racoon only) +dh16 = modp4096 (racoon only) +dh17 = modp6144 (racoon only) +dh18 = modp8192 (racoon only) + + + + + + + layout20 + + + + unnamed + + + + UseModeConfigCheckBox + + + Use &Mode Configuration + + + Alt+M + + + + + spacer113 + + + Horizontal + + + Expanding + + + + 16 + 20 + + + + + + + + layout22 + + + + unnamed + + + + RightNextHopLineEdit + + + false + + + + + UseLeftNextHopCheckBox + + + Use &left next hop: + + + Alt+L + + + + + UseRightNextHopCheckBox + + + &Use right next hop: + + + Alt+U + + + + + LeftNextHopLineEdit + + + false + + + + + + + + + + layout90 + + + + unnamed + + + + DisableOpportunisticEncryptionCheckBox + + + Disable opportunistic encr&yption + + + Alt+Y + + + + + spacer6_2 + + + Horizontal + + + Expanding + + + + 100 + 20 + + + + + + + + layout90_2 + + + + unnamed + + + + UseXauthCheckBox + + + Authenticate &with username and password (XAUTH) + + + Alt+W + + + enable this if you want enable the XAUTh extension + + + + + spacer6_2_2 + + + Horizontal + + + Expanding + + + + 100 + 20 + + + + + + + + spacer3 + + + Vertical + + + Expanding + + + + 20 + 82 + + + + + + + + IkeespTab + + + IKE/ESP + + + + unnamed + + + + layout25 + + + + unnamed + + + + layout49 + + + + unnamed + + + + layout48 + + + + unnamed + + + + layout37 + + + + unnamed + + + + UseCustomIkeCheckBox + + + Specify IKE + + + + + spacer11 + + + Horizontal + + + Expanding + + + + 16 + 20 + + + + + + IkeHelpActiveLabel + + + 13 + + + <a href="">Help needed?</a> + + + + + + + IkeGroupBox + + + false + + + IKE + + + + unnamed + + + + IkeAes256Sha1CheckBox + + + aes&256-sha1 + + + Alt+2 + + + + + IkeAes128Sha1CheckBox + + + aes&128-sha1 + + + Alt+1 + + + + + IkeDesSha1Modp2048CheckBox + + + 3des-sha1-modp2&048 + + + Alt+0 + + + + + IkeDesSha1CheckBox + + + 3des-sha1 + + + + + + + + IkeDesMd5CheckBox + + + &3des-md5 + + + Alt+3 + + + + + layout52 + + + + unnamed + + + + textLabel1 + + + other: + + + + + OtherIkeLineEdit + + + + + + + + + + + layout47 + + + + unnamed + + + + layout41 + + + + unnamed + + + + UseCustomEspCheckBox + + + Specify ESP + + + + + + + + spacer12 + + + Horizontal + + + Expanding + + + + 61 + 21 + + + + + + EspHelpActiveLabel + + + 13 + + + AlwaysOff + + + RichText + + + <a href="">Help needed?</a> + + + + + + + layout46 + + + + unnamed + + + + EspGroupBox + + + false + + + ESP + + + + unnamed + + + + EspAes128Sha1CheckBox + + + aes12&8-sha1 + + + Alt+8 + + + + + EspDesSha1CheckBox + + + 3des-sha1 + + + + + + + + Esp3desMd5CheckBox + + + 3des-md5 + + + + + layout53 + + + + unnamed + + + + textLabel2 + + + other: + + + + + OtherEspLineEdit + + + + + + + EspAes256Sha1CheckBox + + + aes2&56-sha1 + + + Alt+5 + + + + + + + spacer28 + + + Vertical + + + Expanding + + + + 20 + 21 + + + + + + + + + + + + spacer16 + + + Vertical + + + Expanding + + + + 20 + 71 + + + + + + + + + + IdTab + + + Local/Remote ID + + + + unnamed + + + + layout26 + + + + unnamed + + + + LocalIdentifierGroupBox + + + Local identifier + + + + unnamed + + + + layout97 + + + + unnamed + + + + LocalIDLabel + + + ID value + + + + + spacer72_2_2 + + + Horizontal + + + Expanding + + + + 170 + 20 + + + + + + + + LocalIDLineEdit + + + false + + + Normal + + + Value for the local ID, hint: if type address, you can enter a hostname here which will be resolved at connect + + + + + layout29 + + + + unnamed + + + + HashAlgoTextLabel_2_2 + + + ID type + + + + + spacer72_2 + + + Horizontal + + + Expanding + + + + 137 + 20 + + + + + + + + LocalIdTypeCombobox + + + false + + + This is the type of the local ID (default: asn1dn)<br> +<ul> +<li>asn1dn - the type is an ASN.1 distinguished name. Use 'use email address as identifier' in certificate settings if it should be the mail address. If this option is not checked, the DN from the Subject field in the certificate will be used.</li> +<li>address - the type is the IP address.</li> +<li>fqdn - the type is a FQDN (fully-qualified domain name).</li> +<li>keyid - the type is a KEY_ID (file)</li> +<li>user_fqdn - the type is a USER_FQDN (user fully-qualified domain name).</li> +</ul> + Automatic keying has a property called perfect forward secrecy. This is the Diffie Helman group for PFS. + + + This is the type of the local ID (default: asn1dn)<br> +<ul> +<li>asn1dn - the type is an ASN.1 distinguished name. Use 'use email address as identifier' in certificate settings if it should be the mail address. If this option is not checked, the DN from the Subject field in the certificate will be used.</li> +<li>address - the type is the IP address.</li> +<li>fqdn - the type is a FQDN (fully-qualified domain name).</li> +<li>keyid - the type is a KEY_ID (file)</li> +<li>user_fqdn - the type is a USER_FQDN (user fully-qualified domain name).</li> +</ul> + + + + + + + RemoteIdentifierGroupBox + + + Remote identifier + + + + unnamed + + + + layout74_2 + + + + unnamed + + + + layout73_2 + + + + unnamed + + + + HashAlgoTextLabel_2_2_2 + + + ID type + + + + + spacer72_2_3_2 + + + Horizontal + + + Expanding + + + + 51 + 20 + + + + + + + + RemoteIDLineEdit + + + false + + + Normal + + + Value for the remote ID, hint: if type address, you can enter a hostname here which will be resolved at connect + + + + + layout72_2 + + + + unnamed + + + + RemoteIDLabel + + + ID value + + + + + spacer72_2_2_2 + + + Horizontal + + + Expanding + + + + 51 + 20 + + + + + + + + RemoteIdTypeCombobox + + + false + + + This is the type of the local ID (default: asn1dn)<br> +<ul> +<li>asn1dn - the type is an ASN.1 distinguished name. Use 'use email address as identifier' in certificate settings if it should be the mail address. If this option is not checked, the DN from the Subject field in the certificate will be used.</li> +<li>address - the type is the IP address.</li> +<li>fqdn - the type is a FQDN (fully-qualified domain name).</li> +<li>keyid - the type is a KEY_ID (file)</li> +<li>user_fqdn - the type is a USER_FQDN (user fully-qualified domain name).</li> +</ul> + Automatic keying has a property called perfect forward secrecy. This is the Diffie Helman group for PFS. + + + This is the type of the local ID (default: asn1dn)<br> +<ul> +<li>asn1dn - the type is an ASN.1 distinguished name. Use 'use email address as identifier' in certificate settings if it should be the mail address. If this option is not checked, the DN from the Subject field in the certificate will be used.</li> +<li>address - the type is the IP address.</li> +<li>fqdn - the type is a FQDN (fully-qualified domain name).</li> +<li>keyid - the type is a KEY_ID (file)</li> +<li>user_fqdn - the type is a USER_FQDN (user fully-qualified domain name).</li> +</ul> + + + + + + + + + spacer17 + + + Vertical + + + Expanding + + + + 20 + 31 + + + + + + + + + + + + + UseCustomEspCheckBox + toggled(bool) + ProfileIpsecOptionsBase + useEspToogled(bool) + + + UseCustomIkeCheckBox + toggled(bool) + ProfileIpsecOptionsBase + useIkeToggled(bool) + + + UseLeftNextHopCheckBox + toggled(bool) + ProfileIpsecOptionsBase + useLeftNextHopToggled(bool) + + + UseRightNextHopCheckBox + toggled(bool) + ProfileIpsecOptionsBase + useRightNextHopToggled(bool) + + + LocalIdTypeCombobox + activated(const QString&) + ProfileIpsecOptionsBase + localIDTypeToggled(const QString&) + + + IkeHelpActiveLabel + clicked(int,int) + ProfileIpsecOptionsBase + ikeHelpClicked(int,int) + + + EspHelpActiveLabel + clicked(int,int) + ProfileIpsecOptionsBase + espHelpClicked(int,int) + + + RemoteIdTypeCombobox + activated(const QString&) + ProfileIpsecOptionsBase + remoteIDTypeToggled(const QString&) + + + PerfectForwardSecurityCheckbox + toggled(bool) + ProfileIpsecOptionsBase + usePfsToogled(bool) + + + + useLeftNextHopToggled(bool) + useRightNextHopToggled(bool) + localIDTypeToggled(const QString&) + useIkeToggled(bool) + useEspToogled(bool) + useLeftSourceIpToggeled(bool) + useRightSourceIpToggeled(bool) + ikeHelpClicked(int,int) + espHelpClicked(int,int) + remoteIDTypeToggled(const QString&) + usePfsToogled(bool) + + + + kcombobox.h + kcombobox.h + klineedit.h + klineedit.h + kactivelabel.h + klineedit.h + kactivelabel.h + klineedit.h + klineedit.h + kcombobox.h + klineedit.h + kcombobox.h + + diff --git a/src/profilemanagerbase.cpp b/src/profilemanagerbase.cpp new file mode 100644 index 0000000..bb769c1 --- /dev/null +++ b/src/profilemanagerbase.cpp @@ -0,0 +1,53 @@ +#include +#include +/**************************************************************************** +** Form implementation generated from reading ui file './profilemanagerbase.ui' +** +** Created: Mon Aug 28 16:23:54 2006 +** by: The User Interface Compiler ($Id: qt/main.cpp 3.3.6 edited Aug 31 2005 $) +** +** WARNING! All changes made in this file will be lost! +****************************************************************************/ + +#include "profilemanagerbase.h" + +#include +#include +#include +#include + +/* + * Constructs a ProfileManagerDialogBase as a child of 'parent', with the + * name 'name' and widget flags set to 'f'. + */ +ProfileManagerDialogBase::ProfileManagerDialogBase( QWidget* parent, const char* name, WFlags fl ) + : QWidget( parent, name, fl ) +{ + if ( !name ) + setName( "ProfileManagerDialogBase" ); + setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)3, 0, 0, sizePolicy().hasHeightForWidth() ) ); + setMinimumSize( QSize( 550, 450 ) ); + ProfileManagerDialogBaseLayout = new QGridLayout( this, 1, 1, 11, 6, "ProfileManagerDialogBaseLayout"); + languageChange(); + resize( QSize(622, 622).expandedTo(minimumSizeHint()) ); + clearWState( WState_Polished ); +} + +/* + * Destroys the object and frees any allocated resources + */ +ProfileManagerDialogBase::~ProfileManagerDialogBase() +{ + // no need to delete child widgets, Qt does it all for us +} + +/* + * Sets the strings of the subwidgets using the current + * language. + */ +void ProfileManagerDialogBase::languageChange() +{ + setCaption( tr2i18n( "Profile Manager" ) ); +} + +#include "profilemanagerbase.moc" diff --git a/src/profilenetworkgeneraloptions.cpp b/src/profilenetworkgeneraloptions.cpp new file mode 100644 index 0000000..e875021 --- /dev/null +++ b/src/profilenetworkgeneraloptions.cpp @@ -0,0 +1,130 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "profilenetworkgeneraloptions.h" + +#include +#include +#include +#include +#include +#include + +#include "widgetnotifyhelper.h" +#include + +ProfileNetworkGeneralOptions::ProfileNetworkGeneralOptions(QWidget *parent) : ProfileNetworkGeneralOptionsBase(parent) +{ + useConnectionStatusCheckToggled(UseConnectionStatusCheckCheckBox->isChecked()); + WidgetNotifyHelper h; + h.setupChangedAction(this); + dialogModified=false; +} + +ProfileNetworkGeneralOptions::~ProfileNetworkGeneralOptions() +{} + +void ProfileNetworkGeneralOptions::mtuToggled(bool) +{ + if (MtuCheckbox->isChecked()) + MtuSpinbox->setEnabled(true); + else + MtuSpinbox->setEnabled(false); +} + +void ProfileNetworkGeneralOptions::mruToggled(bool) +{ + if (MruCheckbox->isChecked()) + MruSpinbox->setEnabled(true); + else + MruSpinbox->setEnabled(false); +} + + +void ProfileNetworkGeneralOptions::useConnectionStatusCheckToggled(bool) +{ + if (UseConnectionStatusCheckCheckBox->isChecked()) + { + ConnectionStatusCheckIntervalNumInput->setEnabled(true); + ConnectionStatusSuccessCountNumInput->setEnabled(true); + PingIntervalLabel->setEnabled(true); + PingSuccessCountLabel->setEnabled(true); + } + else + { + ConnectionStatusCheckIntervalNumInput->setEnabled(false); + ConnectionStatusSuccessCountNumInput->setEnabled(false); + PingIntervalLabel->setEnabled(false); + PingSuccessCountLabel->setEnabled(false); + } +} + +void ProfileNetworkGeneralOptions::pingIpAfterConnectToggled(bool) +{ + if (PingCheckBox->isChecked()) + PingIPLineEdit->setEnabled(true); + else + PingIPLineEdit->setEnabled(false); +} + +void ProfileNetworkGeneralOptions::useReconnectDelayToggled(bool) +{ + if (UseReconnectDelayCheckBox->isChecked()) + ReconnectDelayNumInput->setEnabled(true); + else + ReconnectDelayNumInput->setEnabled(false); +} + +void ProfileNetworkGeneralOptions::useReconnectAfterDisconnectToggled(bool) +{ + if (DoReconnectAfterConnectionLostCheckBox->isChecked()) + { + if (UseReconnectDelayCheckBox->isChecked()) + ReconnectDelayNumInput->setEnabled(true); + else + ReconnectDelayNumInput->setEnabled(false); + + UseReconnectDelayCheckBox->setEnabled(true); + } + else + { + ReconnectDelayNumInput->setEnabled(false); + UseReconnectDelayCheckBox->setEnabled(false); + } +} + +void ProfileNetworkGeneralOptions::UseDnsUpdateToggled(bool) +{ + // UseDnsUpdate->setEnabled(UseDnsUpdateCheckBox->isChecked()); +} + +void ProfileNetworkGeneralOptions::dialogChanged() +{ +// std::cout << "ProfileNetworkGeneralOptions::dialogChanged()" << std::endl; + dialogModified=true; +} + + +void ProfileNetworkGeneralOptions::useNetworkToggled(bool) +{ + if (UseRemoteNetworkCheckBox->isChecked()) + UseRemoteNetworkGroupBox->setEnabled(true); + else + UseRemoteNetworkGroupBox->setEnabled(false); +} diff --git a/src/profilenetworkgeneraloptions.h b/src/profilenetworkgeneraloptions.h new file mode 100644 index 0000000..e6e2ceb --- /dev/null +++ b/src/profilenetworkgeneraloptions.h @@ -0,0 +1,55 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Nat Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Nat Public License for more details. * + * * + * You should have received a copy of the GNU Nat Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef PROFILENETWORKGENERALOPTIONS_H +#define PROFILENETWORKGENERALOPTIONS_H + +#include "profilenetworkgeneraloptionsbase.h" +#include + +/** +@author Christoph Thielecke +*/ +class ProfileNetworkGeneralOptions : public ProfileNetworkGeneralOptionsBase +{ +Q_OBJECT +public: + ProfileNetworkGeneralOptions(QWidget *parent); + ~ProfileNetworkGeneralOptions(); + bool dialogModified; + +public slots: + void mtuToggled(bool); + void mruToggled(bool); + void useReconnectDelayToggled(bool); + void useReconnectAfterDisconnectToggled(bool); + void pingIpAfterConnectToggled(bool); + void useConnectionStatusCheckToggled(bool); + void UseDnsUpdateToggled(bool); + void useNetworkToggled(bool); + +private slots: + void dialogChanged(); + +signals: + void changed(); + +}; + +#endif diff --git a/src/profilenetworkgeneraloptionsbase.ui b/src/profilenetworkgeneraloptionsbase.ui new file mode 100644 index 0000000..c965f65 --- /dev/null +++ b/src/profilenetworkgeneraloptionsbase.ui @@ -0,0 +1,1031 @@ + +ProfileNetworkGeneralOptionsBase + + + ProfileNetworkGeneralOptionsBase + + + + 0 + 0 + 459 + 354 + + + + General network options + + + + unnamed + + + + layout60 + + + + unnamed + + + + layout58 + + + + unnamed + + + + MtuCheckbox + + + User defined &MTU: + + + Alt+M + + + Check this to set a custom MTU size + + + If you enable this you can set a own MTU size. + + + + + MtuSpinbox + + + false + + + 1500 + + + 1200 + + + 1492 + + + The MTU size for the ppp connection + + + Here you can specify the MTU size for use with pppd. + + + + + spacer54 + + + Horizontal + + + Expanding + + + + 71 + 20 + + + + + + MruCheckbox + + + Userdefined M&RU: + + + Alt+R + + + Check this to set a custom MRU size + + + If you enable this you can set a own MRU size. + + + + + MruSpinbox + + + false + + + 1500 + + + 1200 + + + 1492 + + + The MRU size for the ppp connection + + + Here you can specify the MRU size for use with pppd. + + + + + + + layout59 + + + + unnamed + + + + layout56 + + + + unnamed + + + + UseRemoteNetworkCheckBox + + + &Use remote network + + + Alt+U + + + + + spacer28 + + + Horizontal + + + Expanding + + + + 41 + 21 + + + + + + + + layout58 + + + + unnamed + + + + LabelNetworkDevice + + + true + + + Network device + + + + + layout44 + + + + unnamed + + + + spacer169 + + + Horizontal + + + Expanding + + + + 227 + 20 + + + + + + NetworkDeviceComboBox + + + true + + + Network device for use with tunnel + + + This is the network device which should be used for the tunnel. Its only active if needed. If no selection made, "default" is set for using the device where the defaultroute points to. + + + + + + + + + spacer24 + + + Horizontal + + + Expanding + + + + 208 + 20 + + + + + + FixPathMtuDiscoveryProblemCheckBox + + + Fix path mtu discovery problem + + + + + + Fixes the path mtu discovery problem by inserting a special firwall rule. + + + Problem: TCP connections using the PPTP Client host as a hop in the route (such as via normal routing, NAT or IP masquerading) freeze once they attempt to transfer large amounts of data. +Diagnosis: path MTU discovery may not be working, due to hosts on the route refusing to forward ICMP fragmentation needed responses. + + + + + layout55 + + + + unnamed + + + + UseDnsUpdateCheckBox + + + true + + + Update DNS configuration + + + + + + true + + + Modify the nameserver configuration and set DNS_UPDATE var. + + + If this is checked, the nameserver configuration will be updated. The DNS_UPDATE environment variable will be set to YES, otherwise NO. + + + + + spacer27 + + + Horizontal + + + Expanding + + + + 71 + 21 + + + + + + + + layout57 + + + + unnamed + + + + TunnelDeviceTypeLabel + + + false + + + Tunnel device type: + + + + + layout22 + + + + unnamed + + + + spacer15 + + + Horizontal + + + Expanding + + + + 181 + 21 + + + + + + TunnelDeviceTypeComboBox + + + false + + + + + + + + + + + layout58 + + + + unnamed + + + + UseRemoteNetworkGroupBox + + + false + + + Remote network + + + + unnamed + + + + LabelRemoteNetwork + + + false + + + Remote network: + + + + + layout77 + + + + unnamed + + + + RemoteNetAddrLineEdit + + + Remote network address + + + This is the remote network where the connection should going to. Use this at a PPTP connection for set another network than the retrieved IP is located. + + + + + RemoteNetDividetextLabel + + + / + + + + + + 8 + + + + + 9 + + + + + 10 + + + + + 11 + + + + + 12 + + + + + 13 + + + + + 14 + + + + + 15 + + + + + 16 + + + + + 17 + + + + + 18 + + + + + 19 + + + + + 20 + + + + + 21 + + + + + 22 + + + + + 23 + + + + + 24 + + + + + 25 + + + + + 26 + + + + + 27 + + + + + 28 + + + + + 29 + + + + + 30 + + + + + 31 + + + + + 32 + + + + RemoteNetMaskComboBox + + + 16 + + + + + + + + + ConnectionStatusGroupBox + + + Connection Status Check + + + Options for connection status check + + + Here you can set various options for the connection status check. + + + + unnamed + + + + layout57 + + + + unnamed + + + + UseConnectionStatusCheckCheckBox + + + true + + + &Check connection status + + + Alt+C + + + true + + + Test if the connection is allive by pinging the gateway + + + If checked, the connection status check will be enabled. The parameters below control how often the gateway will be pinged and it must be minimal success in a count.<br>Example: interval 1, success count 4: this means that 4 pings will be done and minimal one must be success for keep the connection alive. The delay between the pings are 1 sec. + + + + + spacer8_2 + + + Horizontal + + + Expanding + + + + 201 + 20 + + + + + + + + DoReconnectAfterConnectionLostCheckBox + + + true + + + Reconnect after connection &lost + + + Alt+L + + + false + + + Reconnect automatically after the connection is lost + + + + + + + + layout118 + + + + unnamed + + + + layout119 + + + + unnamed + + + + PingIntervalLabel + + + false + + + Interval: + + + + + spacer8 + + + Horizontal + + + Expanding + + + + 181 + 20 + + + + + + + + ConnectionStatusCheckIntervalNumInput + + + 1 + + + 120 + + + + + + + layout117 + + + + unnamed + + + + layout120 + + + + unnamed + + + + PingSuccessCountLabel + + + false + + + Success count: + + + + + spacer9 + + + Horizontal + + + Expanding + + + + 181 + 20 + + + + + + + + ConnectionStatusSuccessCountNumInput + + + 4 + + + 1 + + + 10 + + + + + + + layout4 + + + + unnamed + + + + PingCheckBox + + + WidgetOrigin + + + Ping hostname/IP address: + + + + + + Use specified hostname/IP address instead the gateway address to test the connection status + + + + + PingIPLineEdit + + + false + + + Normal + + + Hostname/IP address for ping test + + + This is the hostname/IP address which should be tested. + + + + + + + spacer29 + + + Horizontal + + + Expanding + + + + 181 + 21 + + + + + + layout121 + + + + unnamed + + + + layout121 + + + + unnamed + + + + UseReconnectDelayCheckBox + + + false + + + Reconnect dela&y: + + + Alt+Y + + + false + + + Delay in seconds before reconnect after the connection lost + + + + + + + + spacer68 + + + Horizontal + + + Expanding + + + + 64 + 21 + + + + + + + + ReconnectDelayNumInput + + + false + + + 5 + + + 1 + + + 120 + + + Reconnect delay in seconds + + + + + + + + + + + spacer112 + + + Vertical + + + Expanding + + + + 20 + 16 + + + + + + + + + + MtuCheckbox + toggled(bool) + ProfileNetworkGeneralOptionsBase + mtuToggled(bool) + + + MruCheckbox + toggled(bool) + ProfileNetworkGeneralOptionsBase + mruToggled(bool) + + + UseConnectionStatusCheckCheckBox + toggled(bool) + ProfileNetworkGeneralOptionsBase + useConnectionStatusCheckToggled(bool) + + + DoReconnectAfterConnectionLostCheckBox + toggled(bool) + ProfileNetworkGeneralOptionsBase + useReconnectAfterDisconnectToggled(bool) + + + UseReconnectDelayCheckBox + toggled(bool) + ProfileNetworkGeneralOptionsBase + useReconnectDelayToggled(bool) + + + PingCheckBox + toggled(bool) + ProfileNetworkGeneralOptionsBase + pingIpAfterConnectToggled(bool) + + + UseRemoteNetworkCheckBox + toggled(bool) + ProfileNetworkGeneralOptionsBase + useNetworkToggled(bool) + + + + mtuToggled(bool) + mruToggled(bool) + useConnectionStatusCheckToggled(bool) + pingIpAfterConnectToggled(bool) + useReconnectAfterDisconnectToggled(bool) + useReconnectDelayToggled(bool) + UseDnsUpdateToggled(bool) + useNetworkToggled(bool) + + + + kcombobox.h + klineedit.h + kcombobox.h + klineedit.h + kcombobox.h + knuminput.h + knuminput.h + knuminput.h + knuminput.h + klineedit.h + knuminput.h + knuminput.h + + diff --git a/src/profilenetworkhttpproxyoptions.cpp b/src/profilenetworkhttpproxyoptions.cpp new file mode 100644 index 0000000..ec8c331 --- /dev/null +++ b/src/profilenetworkhttpproxyoptions.cpp @@ -0,0 +1,110 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "profilenetworkhttpproxyoptions.h" +#include +#include +#include +#include +#include +#include +#include + +#include "widgetnotifyhelper.h" +#include + +ProfileNetworkHttpProxyOptions::ProfileNetworkHttpProxyOptions(QWidget *parent) + : ProfileNetworkHttpProxyOptionsBase(parent) +{ + WidgetNotifyHelper h; + h.setupChangedAction(this); + dialogModified=false; +} + + +ProfileNetworkHttpProxyOptions::~ProfileNetworkHttpProxyOptions() +{} + + +void ProfileNetworkHttpProxyOptions::useHttpProxyToggeled(bool) +{ + if ( UseHttpProxyCheckBox->isChecked()) + { + HttpProxyGroupBox->setEnabled(true); + UseHttpProxyAuthCheckBox->setEnabled(true); + HttpProxyLineEdit->setEnabled(true); + HttpProxyPortIntNumInput->setEnabled(true); + HttpProxyTimeoutIntSpinBox->setEnabled(true); + TimeoutTextLabel->setEnabled(true); + HostTextLabel->setEnabled(true); + PortTextextLabel->setEnabled(true); + + } + else + { + HttpProxyGroupBox->setEnabled(false); + UseHttpProxyAuthCheckBox->setEnabled(false); + HttpProxyLineEdit->setEnabled(false); + HttpProxyPortIntNumInput->setEnabled(false); + HttpProxyTimeoutIntSpinBox->setEnabled(false); + TimeoutTextLabel->setEnabled(false); + HostTextLabel->setEnabled(false); + PortTextextLabel->setEnabled(false); + } +} + +void ProfileNetworkHttpProxyOptions::useHttpProxyAuthToggeled(bool) +{ + if (UseHttpProxyAuthCheckBox->isChecked()) + { + HttpProxyAuthTextLabel->setEnabled(true); + HttpProxyAuthTypeComboBox->setEnabled(true); + HttpProxyUserTextLabel->setEnabled(true); + HttpProxyUserLineEdit->setEnabled(true); + HttpProxyPassTextLabel->setEnabled(true); + HttpProxyAuthPasswordEdit->setEnabled(true); + } + else + { + HttpProxyAuthTextLabel->setEnabled(false); + HttpProxyAuthTypeComboBox->setEnabled(false); + HttpProxyUserTextLabel->setEnabled(false); + HttpProxyUserLineEdit->setEnabled(false); + HttpProxyPassTextLabel->setEnabled(false); + HttpProxyAuthPasswordEdit->setEnabled(false); + } +} + +void ProfileNetworkHttpProxyOptions::dialogChanged() +{ +// std::cout << "ProfileNetworkHttpProxyOptions::dialogChanged()" << std::endl; + dialogModified=true; +} + + + + + + + + + + + + diff --git a/src/profilenetworkhttpproxyoptions.h b/src/profilenetworkhttpproxyoptions.h new file mode 100644 index 0000000..d7e8cf6 --- /dev/null +++ b/src/profilenetworkhttpproxyoptions.h @@ -0,0 +1,49 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef PROFILENETWORKHTTPPROXYOPTIONS_H +#define PROFILENETWORKHTTPPROXYOPTIONS_H + +#include "profilenetworkhttpproxyoptionsbase.h" +#include + +/** +@author Christoph Thielecke +*/ +class ProfileNetworkHttpProxyOptions : public ProfileNetworkHttpProxyOptionsBase +{ +Q_OBJECT +public: + ProfileNetworkHttpProxyOptions(QWidget *parent); + ~ProfileNetworkHttpProxyOptions(); + bool dialogModified; + +public slots: + void useHttpProxyToggeled(bool); + void useHttpProxyAuthToggeled(bool); + +private slots: + void dialogChanged(); + +signals: + void changed(); + +}; + +#endif diff --git a/src/profilenetworkhttpproxyoptionsbase.ui b/src/profilenetworkhttpproxyoptionsbase.ui new file mode 100644 index 0000000..a4892be --- /dev/null +++ b/src/profilenetworkhttpproxyoptionsbase.ui @@ -0,0 +1,438 @@ + +ProfileNetworkHttpProxyOptionsBase + + + ProfileNetworkHttpProxyOptionsBase + + + + 0 + 0 + 451 + 337 + + + + HTTP proxy + + + + unnamed + + + + layout65 + + + + unnamed + + + + layout64 + + + + unnamed + + + + UseHttpProxyCheckBox + + + Use HTTP prox&y + + + Alt+Y + + + Connect via HTTP proxy + + + + + layout8 + + + + unnamed + + + + HttpProxyGroupBox + + + HTTP proxy + + + HTTP proxy settings + + + + unnamed + + + + PortTextextLabel + + + false + + + Port + + + Proxy server port number + + + + + HostTextLabel + + + false + + + Host + + + Name or IP address of the proxy server + + + + + HttpProxyPassTextLabel + + + false + + + Password + + + Name or IP address of the proxy server + + + + + HttpProxyAuthTextLabel + + + false + + + Type + + + Name or IP address of the proxy server + + + + + TimeoutTextLabel + + + false + + + Timeout + + + Timeout in seconds + + + + + spacer18 + + + Horizontal + + + Expanding + + + + 41 + 21 + + + + + + layout14 + + + + unnamed + + + + spacer19 + + + Horizontal + + + Expanding + + + + 91 + 21 + + + + + + HttpProxyAuthTypeComboBox + + + false + + + + + + + spacer14 + + + Horizontal + + + Expanding + + + + 150 + 20 + + + + + + layout13 + + + + unnamed + + + + spacer13 + + + Horizontal + + + Expanding + + + + 103 + 21 + + + + + + HttpProxyTimeoutIntSpinBox + + + false + + + 5 + + + Timeout in seconds + + + + + + + HttpProxyUserTextLabel + + + false + + + Username + + + Name or IP address of the proxy server + + + + + HttpProxyUserLineEdit + + + false + + + Name or IP address of the proxy server + + + + + layout9 + + + + unnamed + + + + spacer12 + + + Horizontal + + + Expanding + + + + 119 + 21 + + + + + + HttpProxyPortIntNumInput + + + false + + + 65535 + + + 1 + + + 8080 + + + Proxy server port number + + + + + + + UseHttpProxyAuthCheckBox + + + false + + + Use HTTP prox&y authentication + + + Alt+Y + + + Connect via HTTP proxy + + + + + HttpProxyLineEdit + + + false + + + Name or IP address of the proxy server + + + + + HttpProxyAuthPasswordEdit + + + false + + + Password + + + + + + + spacer5_2 + + + Vertical + + + Expanding + + + + 41 + 110 + + + + + + + + + + spacer20 + + + Horizontal + + + Expanding + + + + 16 + 20 + + + + + + + + + + UseHttpProxyAuthCheckBox + toggled(bool) + ProfileNetworkHttpProxyOptionsBase + useHttpProxyAuthToggeled(bool) + + + UseHttpProxyCheckBox + toggled(bool) + ProfileNetworkHttpProxyOptionsBase + useHttpProxyToggeled(bool) + + + + HttpProxyLineEdit + HttpProxyPortIntNumInput + HttpProxyTimeoutIntSpinBox + + + useHttpProxyToggeled(bool) + useHttpProxyAuthToggeled(bool) + + + + kcombobox.h + knuminput.h + knuminput.h + + diff --git a/src/profilenetworknatoptions.cpp b/src/profilenetworknatoptions.cpp new file mode 100644 index 0000000..53f4687 --- /dev/null +++ b/src/profilenetworknatoptions.cpp @@ -0,0 +1,70 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "profilenetworknatoptions.h" + +#include +#include +#include "widgetnotifyhelper.h" +#include + +ProfileNetworkNatOptions::ProfileNetworkNatOptions(QWidget *parent) + : ProfileNetworkNatOptionsBase(parent) +{ + WidgetNotifyHelper h; + h.setupChangedAction(this); + dialogModified=false; +} + + +ProfileNetworkNatOptions::~ProfileNetworkNatOptions() +{} + +void ProfileNetworkNatOptions::useNatToggled(bool) +{ + if (UseNatCheckbox->isChecked()) + { + UdpPortCheckbox->setEnabled(TRUE); + } + else + { + UdpPortCheckbox->setEnabled(FALSE); + } +} + + +void ProfileNetworkNatOptions::udpPortToggled(bool) +{ + if (UdpPortCheckbox->isChecked()) + { + UdpPortSpinbox->setEnabled(TRUE); + } + else + { + UdpPortSpinbox->setEnabled(FALSE); + } +} + + +void ProfileNetworkNatOptions::dialogChanged() +{ +// std::cout << "ProfileNetworkNatOptions::dialogChanged()" << std::endl; + dialogModified=true; +} + diff --git a/src/profilenetworknatoptions.h b/src/profilenetworknatoptions.h new file mode 100644 index 0000000..95d86c4 --- /dev/null +++ b/src/profilenetworknatoptions.h @@ -0,0 +1,49 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef PROFILENETWORKNATOPTIONS_H +#define PROFILENETWORKNATOPTIONS_H + +#include "profilenetworknatoptionsbase.h" +#include + +/** +@author Christoph Thielecke +*/ +class ProfileNetworkNatOptions : public ProfileNetworkNatOptionsBase +{ +Q_OBJECT +public: + ProfileNetworkNatOptions(QWidget *parent); + ~ProfileNetworkNatOptions(); + bool dialogModified; + +public slots: + void useNatToggled(bool); + void udpPortToggled(bool); + +private slots: + void dialogChanged(); + +signals: + void changed(); + +}; + +#endif diff --git a/src/profilenetworknatoptionsbase.ui b/src/profilenetworknatoptionsbase.ui new file mode 100644 index 0000000..f2122a7 --- /dev/null +++ b/src/profilenetworknatoptionsbase.ui @@ -0,0 +1,225 @@ + +ProfileNetworkNatOptionsBase + + + ProfileNetworkNatOptionsBase + + + + 0 + 0 + 393 + 127 + + + + NAT + + + + unnamed + + + + layout71 + + + + unnamed + + + + layout70 + + + + unnamed + + + + layout69 + + + + unnamed + + + + layout67 + + + + unnamed + + + + UseUdpCheckbox + + + &Use UDP + + + Alt+U + + + For IPSec use UDP encapsulation. For openvpn <br>use UDP instead of TCP protocol. + + + For openvpn this causes using UDP instead of TCP protocol <br>(peer have to use the same protocol). + + + + + spacer39 + + + Horizontal + + + Expanding + + + + 40 + 20 + + + + + + + + UseNatCheckbox + + + Use NAT + + + Enable NAT support + + + You should enable this if you behind a firewall + + + + + spacer7_2 + + + Horizontal + + + Expanding + + + + 116 + 21 + + + + + + UdpPortCheckbox + + + false + + + UDP port for NAT-&T: + + + Alt+T + + + Use specified port number for IPSec NAT-T + + + + + UdpPortSpinbox + + + false + + + 65535 + + + 1 + + + 10000 + + + UDP port for NAT-T + + + + + + + spacer4 + + + Vertical + + + Expanding + + + + 21 + 46 + + + + + + + + spacer52 + + + Horizontal + + + Expanding + + + + 31 + 20 + + + + + + + + + + UseNatCheckbox + toggled(bool) + ProfileNetworkNatOptionsBase + useNatToggled(bool) + + + UdpPortCheckbox + toggled(bool) + ProfileNetworkNatOptionsBase + udpPortToggled(bool) + + + + UseUdpCheckbox + UdpPortCheckbox + UdpPortSpinbox + + + useNatToggled(bool) + useUdpToggled(bool) + udpPortToggled(bool) + + + diff --git a/src/profilenetworkrouteoptions.cpp b/src/profilenetworkrouteoptions.cpp new file mode 100644 index 0000000..ad47bd2 --- /dev/null +++ b/src/profilenetworkrouteoptions.cpp @@ -0,0 +1,227 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "profilenetworkrouteoptions.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "addnetworkroutedialog.h" +#include "widgetnotifyhelper.h" + +ProfileNetworkRouteOptions::ProfileNetworkRouteOptions(QWidget *parent): ProfileNetworkRouteOptionsBase(parent) +{ + WidgetNotifyHelper h; + h.setupChangedAction(this); + dialogModified=false; + + checkList(); +} + + +ProfileNetworkRouteOptions::~ProfileNetworkRouteOptions() +{ +} + +void ProfileNetworkRouteOptions::additionalNetworkRoutesToggled(bool) +{ + if (UseExtraNetworkRoutesCheckbox->isChecked()) + { + NetworkListView->setEnabled(TRUE); + AddRoutePushButton->setEnabled(TRUE); + checkList(); + } + else + { + NetworkListView->setEnabled(FALSE); + DeleteNetworkRoutePushButton->setEnabled(FALSE); + AddRoutePushButton->setEnabled(FALSE); + } +} + +void ProfileNetworkRouteOptions::delNetworkRouteClicked() +{ + if ( NetworkListView->childCount() > 0 && NetworkListView->currentItem()!= 0 ) + { + QListViewItem *item = NetworkListView->currentItem(); + QString Network = item->text(0); + QString Netmask = item->text(1); + int result = KMessageBox::questionYesNo ( this, i18n( "Do you really want to delete the network \"%1/%2\"?" ).arg( Network ).arg(Netmask), i18n( "Delete?" ) ); + //LogOutput->append( "Result: "+ QString().setNum(result) ) ; + if ( result == 3) // Yes + { + NetworkListView->removeItem(item); + } + checkList(); + } +} + +void ProfileNetworkRouteOptions::addNetworkRouteClicked() +{ + AddNetworkRouteDialog dlg(this, i18n("Add Network Route...")); + + + dlg.main->InterfaceComboBox->insertItem("default"); // interface where default route points + + //FIXME + dlg.main->InterfaceComboBox->insertItem("eth0"); + dlg.main->InterfaceComboBox->insertItem("eth1"); + dlg.main->InterfaceComboBox->insertItem("eth2"); + dlg.main->InterfaceComboBox->insertItem("ipsec0"); + dlg.main->InterfaceComboBox->insertItem("tun0"); + dlg.main->InterfaceComboBox->insertItem("ppp0"); + + if (dlg.exec()) + { + QString gateway = dlg.getGateway(); + QString interface = dlg.getInterface(); + if (!dlg.getUseGateway()) + gateway="-"; + if (!dlg.getUseInterface()) + interface="-"; + NetworkListView->insertItem( new QListViewItem(NetworkListView, dlg.getNetwork(),dlg.getNetmask(), gateway,interface)); + if (dlg.dialogModified == true) + dialogModified=true; + } + checkList(); +} + +void ProfileNetworkRouteOptions::editNetworkRouteClicked() +{ + + if ( NetworkListView->childCount() > 0 && NetworkListView->currentItem()!= 0 ) + { + AddNetworkRouteDialog dlg(this, i18n("Edit Network Route...")); + QString Network=NetworkListView->currentItem()->text(0); + QString Netmask=NetworkListView->currentItem()->text(1); + QString Gateway=NetworkListView->currentItem()->text(2); + QString Interface=NetworkListView->currentItem()->text(3); + + + dlg.main->InterfaceComboBox->insertItem("default"); // interface where default route points + + //FIXME + dlg.main->InterfaceComboBox->insertItem("eth0"); + dlg.main->InterfaceComboBox->insertItem("eth1"); + dlg.main->InterfaceComboBox->insertItem("eth2"); + dlg.main->InterfaceComboBox->insertItem("ipsec0"); + dlg.main->InterfaceComboBox->insertItem("tun0"); + dlg.main->InterfaceComboBox->insertItem("tun1"); + dlg.main->InterfaceComboBox->insertItem("tun2"); + dlg.main->InterfaceComboBox->insertItem("tap0"); + dlg.main->InterfaceComboBox->insertItem("tap1"); + dlg.main->InterfaceComboBox->insertItem("tap2"); + dlg.main->InterfaceComboBox->insertItem("ppp0"); + + dlg.main->RemoteNetAddrLineEdit->setText(Network); + dlg.main->RemoteNetMaskComboBox->setCurrentItem(Netmask); + + if (!Gateway.isEmpty() && Gateway != "-") + { + dlg.main->RemoteGatewayAddrLineEdit->setText(Gateway); + dlg.main->UseGatewayCheckBox->setChecked(true); + } + else + dlg.main->UseGatewayCheckBox->setChecked(false); + + if (!Interface.isEmpty() && Interface!="-") + { + dlg.main->InterfaceComboBox->setCurrentText(Interface); + dlg.main->UseInterfaceCheckBox->setChecked(true); + } + else + dlg.main->UseInterfaceCheckBox->setChecked(false); + + if (dlg.exec()) + { + QString gateway = dlg.getGateway(); + QString interface = dlg.getInterface(); + if (!dlg.getUseGateway()) + gateway="-"; + if (!dlg.getUseInterface()) + interface="-"; + + NetworkListView->takeItem(NetworkListView->currentItem()); + NetworkListView->insertItem( new QListViewItem(NetworkListView, dlg.getNetwork(),dlg.getNetmask(), gateway,interface)); + +// NetworkListView->currentItem()->text(0) = dlg.getNetwork(); +// NetworkListView->currentItem()->text(1) = dlg.getNetmask(); +// NetworkListView->currentItem()->text(2) = gateway; +// NetworkListView->currentItem()->text(3) = interface; + } + checkList(); + } +} + +void ProfileNetworkRouteOptions::checkList() +{ + if (NetworkListView->childCount() > 0 && NetworkListView->currentItem()!= 0 ) + { + EditRoutePushButton->setEnabled(true); + DeleteNetworkRoutePushButton->setEnabled(true); + } + else + { + EditRoutePushButton->setEnabled(false); + DeleteNetworkRoutePushButton->setEnabled(false); + } +} + +void ProfileNetworkRouteOptions::contextMenuRequested ( QListViewItem * item, const QPoint &pos, int ) +{ + ContextMenu = new QPopupMenu ( 0 ); + if (item != 0) + { + ContextMenu->insertItem(i18n("&Edit...")); + ContextMenu->insertItem(i18n("&Delete...")); + } + ContextMenu->insertItem(i18n("&Add...")); + connect ( ContextMenu, SIGNAL ( activated ( int ) ), this, SLOT ( doContextMenuAction ( int ) ) ); + ContextMenu->show(); + ContextMenu->setGeometry(pos.x(),pos.y(), ContextMenu->width(),ContextMenu->height()); +} + +void ProfileNetworkRouteOptions::doContextMenuAction ( int action) +{ + QString itemtext = ContextMenu->text ( action ); +// std::cout << "action: " << itemtext << std::endl; + if (itemtext == i18n("&Edit...")) + editNetworkRouteClicked(); + if (itemtext == i18n("&Delete...")) + delNetworkRouteClicked(); + if (itemtext == i18n("&Add...")) + addNetworkRouteClicked(); +} + +void ProfileNetworkRouteOptions::dialogChanged() +{ +// std::cout << "ProfileNetworkRouteOptions::dialogChanged()" << std::endl; + dialogModified=true; +} + + diff --git a/src/profilenetworkrouteoptions.h b/src/profilenetworkrouteoptions.h new file mode 100644 index 0000000..8df59ff --- /dev/null +++ b/src/profilenetworkrouteoptions.h @@ -0,0 +1,60 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef PROFILENETWORKROUTEOPTIONS_H +#define PROFILENETWORKROUTEOPTIONS_H + +#include "profilenetworkrouteoptionsbase.h" +#include +#include + +/** +@author Christoph Thielecke +*/ +class ProfileNetworkRouteOptions : public ProfileNetworkRouteOptionsBase +{ + Q_OBJECT +public: + ProfileNetworkRouteOptions(QWidget *parent); + ~ProfileNetworkRouteOptions(); + bool dialogModified; + + +public slots: + void delNetworkRouteClicked(); + void addNetworkRouteClicked(); + void editNetworkRouteClicked(); + void additionalNetworkRoutesToggled(bool); + void checkList(); + void contextMenuRequested ( QListViewItem *, const QPoint &, int ); + void doContextMenuAction ( int ); + +private: + QPopupMenu *ContextMenu; + +private slots: + void dialogChanged(); + +signals: + void changed(); + + +}; + +#endif diff --git a/src/profilenetworkrouteoptionsbase.ui b/src/profilenetworkrouteoptionsbase.ui new file mode 100644 index 0000000..64f4a19 --- /dev/null +++ b/src/profilenetworkrouteoptionsbase.ui @@ -0,0 +1,290 @@ + +ProfileNetworkRouteOptionsBase + + + ProfileNetworkRouteOptionsBase + + + + 0 + 0 + 402 + 403 + + + + + 3 + 3 + 0 + 0 + + + + Network Route Options + + + + unnamed + + + + layout5 + + + + unnamed + + + + layout14 + + + + unnamed + + + + + Keep default route + + + + + Replace default route + + + + DefaultRouteComboBox + + + + + spacer12 + + + Horizontal + + + Expanding + + + + 278 + 21 + + + + + + + + UseExtraNetworkRoutesCheckbox + + + true + + + &Use additional network routes + + + Alt+U + + + + + + Network + + + true + + + true + + + + + Netmask + + + true + + + true + + + + + Gateway + + + true + + + true + + + + + Device + + + true + + + true + + + + NetworkListView + + + false + + + + 0 + 150 + + + + List of additional network routes + + + + + layout4 + + + + unnamed + + + + spacer31_2 + + + Horizontal + + + Expanding + + + + 70 + 20 + + + + + + EditRoutePushButton + + + false + + + Edit &route... + + + Alt+R + + + Add new route + + + + + AddRoutePushButton + + + false + + + Add &route... + + + Alt+R + + + Add new route + + + + + DeleteNetworkRoutePushButton + + + false + + + De&lete + + + Alt+L + + + Delete route + + + + + + + + + + + AddRoutePushButton + clicked() + ProfileNetworkRouteOptionsBase + addNetworkRouteClicked() + + + DeleteNetworkRoutePushButton + clicked() + ProfileNetworkRouteOptionsBase + delNetworkRouteClicked() + + + UseExtraNetworkRoutesCheckbox + toggled(bool) + ProfileNetworkRouteOptionsBase + additionalNetworkRoutesToggled(bool) + + + EditRoutePushButton + clicked() + ProfileNetworkRouteOptionsBase + editNetworkRouteClicked() + + + NetworkListView + contextMenuRequested(QListViewItem*,const QPoint&,int) + ProfileNetworkRouteOptionsBase + contextMenuRequested(QListViewItem*,const QPoint&,int) + + + + UseExtraNetworkRoutesCheckbox + NetworkListView + AddRoutePushButton + DeleteNetworkRoutePushButton + + + additionalNetworkRoutesToggled(bool) + addNetworkRouteClicked() + delNetworkRouteClicked() + editNetworkRouteClicked() + contextMenuRequested(QListViewItem*,const QPoint&,int) + + + + kcombobox.h + klistview.h + kpushbutton.h + kpushbutton.h + kpushbutton.h + + diff --git a/src/profilenetworkvirtualipoptions.cpp b/src/profilenetworkvirtualipoptions.cpp new file mode 100644 index 0000000..3ffc81e --- /dev/null +++ b/src/profilenetworkvirtualipoptions.cpp @@ -0,0 +1,86 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "profilenetworkvirtualipoptions.h" + +#include +#include +#include +#include "widgetnotifyhelper.h" +#include + +ProfileNetworkVirtualIpOptions::ProfileNetworkVirtualIpOptions(QWidget *parent) + : ProfileNetworkVirtualIpOptionsBase(parent) +{ + WidgetNotifyHelper h; + h.setupChangedAction(this); + dialogModified=false; +} + + +ProfileNetworkVirtualIpOptions::~ProfileNetworkVirtualIpOptions() +{} + +void ProfileNetworkVirtualIpOptions::useVirtualIpAddressToggled(bool) +{ + if (UseVirtualIPCheckBox->isChecked()){ + LocalVirtualIpEdit->setEnabled( TRUE ); + LabelLocalVirtualIp->setEnabled( TRUE ); + RemoteVirtualIpLineEdit->setEnabled( TRUE ); + LabelRemoteVirtualIp->setEnabled( TRUE ); + } + else { + LocalVirtualIpEdit->setEnabled( FALSE ); + LabelLocalVirtualIp->setEnabled( FALSE ); + RemoteVirtualIpLineEdit->setEnabled( FALSE ); + LabelRemoteVirtualIp->setEnabled( FALSE ); + } +} + +void ProfileNetworkVirtualIpOptions::dialogChanged() +{ +// std::cout << "ProfileNetworkVirtualIpOptions::dialogChanged()" << std::endl; + dialogModified=true; +} + +void ProfileNetworkVirtualIpOptions::useLeftSourceIpToggeled(bool) +{ + if (UseLeftSourceIpCheckBox->isChecked()) + LeftSourceIpLineEdit->setEnabled(true); + else + LeftSourceIpLineEdit->setEnabled(false); +} + +void ProfileNetworkVirtualIpOptions::useRightSourceIpToggeled(bool) +{ + if (UseRightSourceIpCheckBox->isChecked()) + RightSourceIpLineEdit->setEnabled(true); + else + RightSourceIpLineEdit->setEnabled(false); +} + +void ProfileNetworkVirtualIpOptions::useVirtualSubnetsToggled(bool) +{ + if (UseVirtualSubnetsCheckBox->isChecked()) + VirtualSubnetsLineEdit->setEnabled(true); + else + VirtualSubnetsLineEdit->setEnabled(false); +} + + diff --git a/src/profilenetworkvirtualipoptions.h b/src/profilenetworkvirtualipoptions.h new file mode 100644 index 0000000..ffbb2b9 --- /dev/null +++ b/src/profilenetworkvirtualipoptions.h @@ -0,0 +1,50 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef PROFILENETWORKVIRTUALIPOPTIONS_H +#define PROFILENETWORKVIRTUALIPOPTIONS_H + +#include "profilenetworkvirtualipoptionsbase.h" +#include +/** +@author Christoph Thielecke +*/ +class ProfileNetworkVirtualIpOptions : public ProfileNetworkVirtualIpOptionsBase +{ +Q_OBJECT +public: + ProfileNetworkVirtualIpOptions(QWidget *parent); + ~ProfileNetworkVirtualIpOptions(); + bool dialogModified; + +public slots: + void useVirtualIpAddressToggled(bool); + void useVirtualSubnetsToggled(bool); + void useLeftSourceIpToggeled(bool); + void useRightSourceIpToggeled(bool); + +private slots: + void dialogChanged(); + +signals: + void changed(); + +}; + +#endif diff --git a/src/profilenetworkvirtualipoptionsbase.ui b/src/profilenetworkvirtualipoptionsbase.ui new file mode 100644 index 0000000..5ff00cf --- /dev/null +++ b/src/profilenetworkvirtualipoptionsbase.ui @@ -0,0 +1,302 @@ + +ProfileNetworkVirtualIpOptionsBase + + + ProfileNetworkVirtualIpOptionsBase + + + + 0 + 0 + 428 + 388 + + + + Network Virtual IP Options + + + + unnamed + + + + layout66 + + + + unnamed + + + + VirtualIpGroupBox + + + Virtual IP + + + + unnamed + + + + layout183 + + + + unnamed + + + + LabelRemoteVirtualIp + + + false + + + Remote IP (virtual): + + + + + layout77 + + + + unnamed + + + + + + RemoteVirtualIpLineEdit + + + false + + + Remote IP address (for tunnel) + + + + + UseVirtualIPCheckBox + + + Use vir&tual IP addresses + + + Alt+T + + + Use virtual IP addresses + + + + + LocalVirtualIpEdit + + + false + + + Local IP address (for tunnel) + + + + + + + + LabelLocalVirtualIp + + + false + + + Local IP (virtual): + + + + + + + + + SourceIpgroupBox + + + IPsec + + + + unnamed + + + + layout65 + + + + unnamed + + + + layout49 + + + + unnamed + + + + RightSourceIpLineEdit + + + false + + + + + UseLeftSourceIpCheckBox + + + Use &local source IP: + + + Alt+L + + + + + UseRightSourceIpCheckBox + + + &Use remote source IP: + + + Alt+U + + + + + LeftSourceIpLineEdit + + + false + + + + + + + + + + layout64 + + + + unnamed + + + + UseVirtualSubnetsCheckBox + + + &Use virtual subnets: + + + Alt+U + + + + + VirtualSubnetsLineEdit + + + false + + + + 200 + 0 + + + + for example: %v4:10.0.0.0/8,%v4:172.16.0.0/12,%v4:192.168.0.0/16,%v4:!192.168.2.0/24,%v4:!192.168.15.128/25 + + + + + + + + + + + spacer2 + + + Vertical + + + Expanding + + + + 41 + 159 + + + + + + + + + + UseVirtualIPCheckBox + toggled(bool) + ProfileNetworkVirtualIpOptionsBase + useVirtualIpAddressToggled(bool) + + + UseLeftSourceIpCheckBox + toggled(bool) + ProfileNetworkVirtualIpOptionsBase + useLeftSourceIpToggeled(bool) + + + UseRightSourceIpCheckBox + toggled(bool) + ProfileNetworkVirtualIpOptionsBase + useRightSourceIpToggeled(bool) + + + UseVirtualSubnetsCheckBox + toggled(bool) + ProfileNetworkVirtualIpOptionsBase + useVirtualSubnetsToggled(bool) + + + + UseVirtualIPCheckBox + LocalVirtualIpEdit + RemoteVirtualIpLineEdit + + + useVirtualIpAddressToggled(bool) + useLeftSourceIpToggeled(bool) + useRightSourceIpToggeled(bool) + useVirtualSubnetsToggled(bool) + + + + klineedit.h + klineedit.h + klineedit.h + klineedit.h + klineedit.h + + diff --git a/src/profileopenvpnoptions.cpp b/src/profileopenvpnoptions.cpp new file mode 100644 index 0000000..31128be --- /dev/null +++ b/src/profileopenvpnoptions.cpp @@ -0,0 +1,177 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "profileopenvpnoptions.h" +#include +#include +#include +#include +#include +#include +#include +#include "widgetnotifyhelper.h" +#include + +ProfileOpenvpnOptions::ProfileOpenvpnOptions(QWidget *parent) + : ProfileOpenvpnOptionsBase(parent) +{ + NsCertTypeComboBox->insertItem("client"); + NsCertTypeComboBox->insertItem("server"); + + if (UseTlsAuthCheckBox ->isChecked()) + { + TlsAuthURLRequester->setEnabled(true); + UseTlsRemoteHostCheckBox->setEnabled(true); + } + else + { + TlsAuthURLRequester->setEnabled(false); + UseTlsRemoteHostCheckBox->setEnabled(false); + } + WidgetNotifyHelper h; + h.setupChangedAction(this); + dialogModified=false; + +} + + +ProfileOpenvpnOptions::~ProfileOpenvpnOptions() +{} + +void ProfileOpenvpnOptions::userdefinedPortToggled(bool) +{ + if (UseUserdefinedPortCheckBox->isChecked()) + UserdefinedPortSpinBox->setEnabled(true); + else + UserdefinedPortSpinBox->setEnabled(false); +} + +void ProfileOpenvpnOptions::useNsCertTypeToggled(bool) +{ + if (UseNsCertTypeCheckBox->isChecked()) + NsCertTypeComboBox->setEnabled(true); + else + NsCertTypeComboBox->setEnabled(false); +} + +void ProfileOpenvpnOptions::useUserdefiniedCipherToggled(bool) +{ + if (UseUserdefiniedCipherCheckBox->isChecked()) + UserdefiniedCipherComboBox->setEnabled(true); + else + UserdefiniedCipherComboBox->setEnabled(false); +} + +void ProfileOpenvpnOptions::useTlsAuthToggled(bool) +{ + if (UseTlsAuthCheckBox ->isChecked()) + { + TlsAuthURLRequester->setEnabled(true); + UseTlsRemoteHostCheckBox->setEnabled(true); + } + else + { + TlsAuthURLRequester->setEnabled(false); + UseTlsRemoteHostCheckBox->setEnabled(false); + } +} + + +void ProfileOpenvpnOptions::useTlsRemoteHostToggled(bool) +{ + if (UseTlsRemoteHostCheckBox->isChecked()) + TlsRemoteHostLineEdit->setEnabled(true); + else + TlsRemoteHostLineEdit->setEnabled(false); +} + +void ProfileOpenvpnOptions::userdefinedRemotePortToggled(bool) +{ + if (UseUserdefinedRemotePortCheckBox->isChecked()) + UserdefinedRemotePortSpinBox->setEnabled(true); + else + UserdefinedRemotePortSpinBox->setEnabled(false); +} + +void ProfileOpenvpnOptions::userdefiniedPacketSizeToggled(bool) +{ + if (UseUserdefinedPacketSizeCheckBox->isChecked()) + UserdefinedPacketSizeSpinBox->setEnabled(true); + else + UserdefinedPacketSizeSpinBox->setEnabled(false); +} + +void ProfileOpenvpnOptions::userdefiniedFragmentationSizeToggled(bool) +{ + if(UseUserdefinedFragmentationSizeCheckBox->isChecked()) + UserdefinedFragmentSizeSpinBox->setEnabled(true); + else + UserdefinedFragmentSizeSpinBox->setEnabled(false); +} + +void ProfileOpenvpnOptions::authenticateWithUsernameAndPasswordToggled(bool) +{ + if (AuthWithUsernameAndPasswordCheckBox->isChecked()) + UseOnlyCaCertAndUserAuthCheckBox->setEnabled(true); + else + UseOnlyCaCertAndUserAuthCheckBox->setEnabled(false); +} + +void ProfileOpenvpnOptions::useAuthenticationAlgorithmToggled(bool) +{ + if (UseAuthenticationAlgorithmCheckBox->isChecked()) + UserdefiniedDigestComboBox->setEnabled(true); + else + UserdefiniedDigestComboBox->setEnabled(false); +} + +void ProfileOpenvpnOptions::tunnelPingToggeled(bool) +{ + if (TunnelPingCheckBox->isChecked()) + TunnelPingSpinBox->setEnabled(true); + else + TunnelPingSpinBox->setEnabled(false); +} + + +void ProfileOpenvpnOptions::tunnelPingRestartToggeled(bool) +{ + if (TunnelPingRestartCheckBox->isChecked()) + TunnelPingRestartSpinBox->setEnabled(true); + else + TunnelPingRestartSpinBox->setEnabled(false); +} + + +void ProfileOpenvpnOptions::renegSecToggled(bool) +{ + if (RenegSecCheckBox->isChecked()) + RenegSecSpinBox->setEnabled(true); + else + RenegSecSpinBox->setEnabled(false); +} + + +void ProfileOpenvpnOptions::dialogChanged() +{ +// std::cout << "ProfileOpenvpnOptions::dialogChanged()" << std::endl; + dialogModified=true; +} + + diff --git a/src/profileopenvpnoptions.h b/src/profileopenvpnoptions.h new file mode 100644 index 0000000..69f2c5d --- /dev/null +++ b/src/profileopenvpnoptions.h @@ -0,0 +1,61 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef PROFILEOPENVPNOPTIONS_H +#define PROFILEOPENVPNOPTIONS_H + +#include "profileopenvpnoptionsbase.h" +#include + +/** +@author Christoph Thielecke +*/ +class ProfileOpenvpnOptions : public ProfileOpenvpnOptionsBase +{ +Q_OBJECT +public: + ProfileOpenvpnOptions(QWidget *parent); + ~ProfileOpenvpnOptions(); + bool dialogModified; + +public slots: + void userdefinedPortToggled(bool); + void useNsCertTypeToggled(bool); + void useUserdefiniedCipherToggled(bool); + void useTlsAuthToggled(bool); + void useTlsRemoteHostToggled(bool); + void userdefinedRemotePortToggled(bool); + void userdefiniedPacketSizeToggled(bool); + void userdefiniedFragmentationSizeToggled(bool); + void authenticateWithUsernameAndPasswordToggled(bool); + void useAuthenticationAlgorithmToggled(bool); + void tunnelPingRestartToggeled(bool); + void tunnelPingToggeled(bool); + void renegSecToggled(bool); + + +private slots: + void dialogChanged(); + +signals: + void changed(); + +}; + +#endif diff --git a/src/profileopenvpnoptionsbase.ui b/src/profileopenvpnoptionsbase.ui new file mode 100644 index 0000000..9d48239 --- /dev/null +++ b/src/profileopenvpnoptionsbase.ui @@ -0,0 +1,920 @@ + +ProfileOpenvpnOptionsBase + + + ProfileOpenvpnOptionsBase + + + + 0 + 0 + 435 + 272 + + + + OpenVPN + + + + unnamed + + + + tabWidget4 + + + + GeneralTab + + + General + + + + unnamed + + + + layout72 + + + + unnamed + + + + layout71 + + + + unnamed + + + + UserdefinedPortSpinBox + + + false + + + 65535 + + + 1 + + + 1194 + + + Port number + + + + + UseUserdefinedPortCheckBox + + + Use specified &local port: + + + Alt+L + + + Specify local (source) port to use + + + + + UseUserdefinedRemotePortCheckBox + + + &Use specified remote port: + + + Use non standard TCP/UDP port + + + + + DisableLzoCompressionCheckBox + + + Disable L&ZO compression + + + Alt+Z + + + + + UserdefinedRemotePortSpinBox + + + false + + + 65535 + + + 1 + + + 1194 + + + Port number + + + + + DisableSocketBindCheckBox + + + Disable socket bind + + + + + + + + AllowIpAddressChangeOfPeerCheckBox + + + Allow IP address change of peer (for DHCP) + + + + + + + + + + + + + spacer63 + + + Vertical + + + Expanding + + + + 20 + 31 + + + + + + + + + + NetworkTab + + + Network + + + + unnamed + + + + layout74 + + + + unnamed + + + + layout73 + + + + unnamed + + + + RenegSecSpinBox + + + false + + + 65535 + + + 1 + + + 3600 + + + + + + + + TunnelPingRestartCheckBox + + + Use tunnel ping restart: + + + + + + Specify local (source) port to use + + + + + RenegSecCheckBox + + + Use reneg-sec: + + + + + + + + + + + UseUserdefiniedCipherCheckBox + + + Use specified cipher: + + + Use non standard cipher algorithm + + + + + TunnelPingRestartSpinBox + + + false + + + 65535 + + + 1 + + + 120 + + + + + + + + UseUserdefinedFragmentationSizeCheckBox + + + Frag&ment packets bigger than: + + + Alt+M + + + + + + + + UserdefinedPacketSizeSpinBox + + + false + + + 1500 + + + 1000 + + + 1300 + + + Packet size + + + This is the max packet size after encapsulation + + + + + spacer6_5 + + + Horizontal + + + Expanding + + + + 74 + 20 + + + + + + spacer6_3_3 + + + Horizontal + + + Expanding + + + + 74 + 20 + + + + + + UserdefinedFragmentSizeSpinBox + + + false + + + 1500 + + + 1000 + + + 1300 + + + Max packet size + + + + + TunnelPingCheckBox + + + Use tunnel ping: + + + + + + + + + + + spacer6_6 + + + Horizontal + + + Expanding + + + + 74 + 20 + + + + + + UseUserdefinedPacketSizeCheckBox + + + Use specified packet size: + + + Use specified max packet size after encapsulation + + + + + TunnelPingSpinBox + + + false + + + 65535 + + + 1 + + + 10 + + + + + + + + spacer6_3_2 + + + Horizontal + + + Expanding + + + + 74 + 20 + + + + + + UserdefiniedCipherComboBox + + + false + + + Cipher algorithm + + + + + spacer6_4 + + + Horizontal + + + Expanding + + + + 74 + 20 + + + + + + spacer7_3 + + + Horizontal + + + Expanding + + + + 74 + 20 + + + + + + + + spacer64 + + + Vertical + + + Expanding + + + + 20 + 21 + + + + + + + + + + AuthenticationTab + + + Authentication + + + + unnamed + + + + layout76 + + + + unnamed + + + + layout75 + + + + unnamed + + + + spacer7_3_2 + + + Horizontal + + + Expanding + + + + 74 + 20 + + + + + + UseAuthenticationAlgorithmCheckBox + + + Use authentication method: + + + Use non standard authentication algorithm + + + + + AuthenticationDirectionComboBox + + + true + + + Digest algorithm + + + + + UseNsCertTypeCheckBox + + + Re&quire peer ns cert type: + + + Alt+Q + + + Require that peer certificate was signed with an explicit nsCertType destination of "client" or "server" + + + + + UseOnlyCaCertAndUserAuthCheckBox + + + false + + + Use only CA cert and authenticate with username and password + + + + + + Authenticate with server using username and password + + + + + UseTlsRemoteHostCheckBox + + + Accept onl&y peer with common name: + + + Alt+Y + + + Accept connections only from a host with X509 name <br>or common name equal to specified name + + + + + UserdefiniedDigestComboBox + + + false + + + Digest algorithm + + + + + TlsRemoteHostLineEdit + + + false + + + Common name, X509 name or common name prefix + + + + + textLabel1_2 + + + Authentication direction: + + + + + NsCertTypeComboBox + + + false + + + The NS cert type: + + + + + layout26 + + + + unnamed + + + + AuthWithUsernameAndPasswordCheckBox + + + Authenticate &with username and password + + + Alt+W + + + + + + + + spacer7_2_2 + + + Horizontal + + + Expanding + + + + 16 + 20 + + + + + + + + UseTlsAuthCheckBox + + + Use &TLS auth + + + Alt+T + + + Add an additional TLS authentication + + + + + spacer7 + + + Horizontal + + + Expanding + + + + 74 + 20 + + + + + + TlsAuthURLRequester + + + false + + + File name of static key or passphrase file. + + + + + spacer7_3_2_2 + + + Horizontal + + + Expanding + + + + 74 + 20 + + + + + + + + spacer65 + + + Vertical + + + Expanding + + + + 20 + 21 + + + + + + + + + + + + + UseUserdefinedPortCheckBox + toggled(bool) + ProfileOpenvpnOptionsBase + userdefinedPortToggled(bool) + + + UseNsCertTypeCheckBox + toggled(bool) + ProfileOpenvpnOptionsBase + useNsCertTypeToggled(bool) + + + UseUserdefiniedCipherCheckBox + toggled(bool) + ProfileOpenvpnOptionsBase + useUserdefiniedCipherToggled(bool) + + + UseTlsAuthCheckBox + toggled(bool) + ProfileOpenvpnOptionsBase + useTlsAuthToggled(bool) + + + UseTlsRemoteHostCheckBox + toggled(bool) + ProfileOpenvpnOptionsBase + useTlsRemoteHostToggled(bool) + + + UseUserdefinedRemotePortCheckBox + toggled(bool) + ProfileOpenvpnOptionsBase + userdefinedRemotePortToggled(bool) + + + UseUserdefinedFragmentationSizeCheckBox + toggled(bool) + ProfileOpenvpnOptionsBase + userdefiniedFragmentationSizeToggled(bool) + + + AuthWithUsernameAndPasswordCheckBox + toggled(bool) + ProfileOpenvpnOptionsBase + authenticateWithUsernameAndPasswordToggled(bool) + + + UseUserdefinedPacketSizeCheckBox + toggled(bool) + ProfileOpenvpnOptionsBase + userdefiniedPacketSizeToggled(bool) + + + UseAuthenticationAlgorithmCheckBox + toggled(bool) + ProfileOpenvpnOptionsBase + useAuthenticationAlgorithmToggled(bool) + + + RenegSecCheckBox + toggled(bool) + ProfileOpenvpnOptionsBase + renegSecToggled(bool) + + + TunnelPingCheckBox + toggled(bool) + ProfileOpenvpnOptionsBase + tunnelPingToggeled(bool) + + + TunnelPingRestartCheckBox + toggled(bool) + ProfileOpenvpnOptionsBase + tunnelPingRestartToggeled(bool) + + + + UseUserdefinedPortCheckBox + UserdefinedPortSpinBox + UseUserdefinedRemotePortCheckBox + UserdefinedRemotePortSpinBox + UseNsCertTypeCheckBox + NsCertTypeComboBox + UseUserdefiniedCipherCheckBox + UserdefiniedCipherComboBox + UseTlsAuthCheckBox + TlsAuthURLRequester + UseTlsRemoteHostCheckBox + TlsRemoteHostLineEdit + DisableLzoCompressionCheckBox + AuthWithUsernameAndPasswordCheckBox + + + authenticateWithUsernameAndPasswordToggled(bool) + userdefiniedPacketSizeToggled(bool) + userdefiniedFragmentationSizeToggled(bool) + userdefinedRemotePortToggled(bool) + useTlsRemoteHostToggled(bool) + useTlsAuthToggled(bool) + useUserdefiniedCipherToggled(bool) + useNsCertTypeToggled(bool) + userdefinedPortToggled(bool) + useAuthenticationAlgorithmToggled(bool) + renegSecToggled(bool) + tunnelPingToggeled(bool) + tunnelPingRestartToggeled(bool) + + + + kcombobox.h + kcombobox.h + kcombobox.h + kcombobox.h + kurlrequester.h + klineedit.h + kpushbutton.h + + diff --git a/src/profilepptpoptions.cpp b/src/profilepptpoptions.cpp new file mode 100644 index 0000000..24ad5e7 --- /dev/null +++ b/src/profilepptpoptions.cpp @@ -0,0 +1,73 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "profilepptpoptions.h" + +#include +#include +#include +#include "widgetnotifyhelper.h" +#include + +ProfilePptpOptions::ProfilePptpOptions(QWidget *parent) + : ProfilePptpOptionsBase(parent) +{ + WidgetNotifyHelper h; + h.setupChangedAction(this); + dialogModified=false; +} + + +ProfilePptpOptions::~ProfilePptpOptions() +{} + +void ProfilePptpOptions::useDnsServerToggled(bool) +{ + if ( DnsServerCheckbox->isChecked() ) + DnsServerLineedit->setEnabled( true ); + else + DnsServerLineedit->setEnabled( false ); +} + + +void ProfilePptpOptions::useSearchDomainInResolvConfToggled(bool) +{ + if ( UseSearchDomainInResolvConfCheckbox ->isChecked() ) + SearchDomainInResolvConfLineedit->setEnabled( true ); + else + SearchDomainInResolvConfLineedit->setEnabled( false ); +} + +void ProfilePptpOptions::useDomainInResolvConfToggled(bool) +{ + if ( UseDomainInResolvConfCheckbox ->isChecked() ) + DomainInResolvConfLineedit->setEnabled( true ); + else + DomainInResolvConfLineedit->setEnabled( false ); +} + +void ProfilePptpOptions::dialogChanged() +{ +// std::cout << "ProfilePptpOptions::dialogChanged()" << std::endl; + dialogModified=true; +} + + + + diff --git a/src/profilepptpoptions.h b/src/profilepptpoptions.h new file mode 100644 index 0000000..9846351 --- /dev/null +++ b/src/profilepptpoptions.h @@ -0,0 +1,51 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef PROFILEPPTPOPTIONS_H +#define PROFILEPPTPOPTIONS_H + +#include "profilepptpoptionsbase.h" +#include + +/** +@author Christoph Thielecke +*/ +class ProfilePptpOptions : public ProfilePptpOptionsBase +{ +Q_OBJECT +public: + ProfilePptpOptions(QWidget *parent); + ~ProfilePptpOptions(); + bool dialogModified; + +public slots: + void useDnsServerToggled(bool); + void useSearchDomainInResolvConfToggled(bool); + void useDomainInResolvConfToggled(bool); + + +private slots: + void dialogChanged(); + +signals: + void changed(); + +}; + +#endif diff --git a/src/profilepptpoptionsbase.ui b/src/profilepptpoptionsbase.ui new file mode 100644 index 0000000..1871e0d --- /dev/null +++ b/src/profilepptpoptionsbase.ui @@ -0,0 +1,697 @@ + +ProfilePptpOptionsBase + + + ProfilePptpOptionsBase + + + + 0 + 0 + 513 + 206 + + + + PPTP/L2TP + + + + unnamed + + + + tabWidget5 + + + + MppeTab + + + MPPE + + + + unnamed + + + + layout85 + + + + unnamed + + + + layout84 + + + + unnamed + + + + spacer69 + + + Horizontal + + + Expanding + + + + 196 + 20 + + + + + + RequireMppeCheckbox + + + Re&quire MPPE + + + Alt+Q + + + Require Microsoft Point-To-Point Encrpytion (enabled by default) + + + + + AllowStatefulModeCheckbox + + + A&llow MPPE stateful mode + + + Alt+L + + + Check this for allow stateful mode of MPPE + + + + + Refuse40BitEncryptionCheckbox + + + Refuse 4&0 bit encryption + + + Alt+0 + + + Refuse 40 bit length encryption of MPPE + + + + + Refuse128BitEncryptionCheckbox + + + Refuse &128 bit encryption + + + Alt+1 + + + Refuse 128 bit length encryption of MPPE + + + + + UseNoMPPECompressionCheckbox + + + Do not use &MPPC compression + + + Alt+M + + + Do not use the Microsoft Poit-To-Point Compression protocol. <br>I.e. for compatibility with watchguard firebox (disabled by default) + + + Check this for disable Microsoft Point-to-Point Compression (MPPC) (i.e. for compatibility with watchguard firebox). + + + + + + + spacer70 + + + Vertical + + + Expanding + + + + 21 + 31 + + + + + + + + + + PppTab + + + PPP + + + + unnamed + + + + layout92 + + + + unnamed + + + + layout91 + + + + unnamed + + + + UseNoDeflateCheckbox + + + Do not use deflate met&hod + + + Alt+H + + + Do not use deflate decompression method (disabled by default) + + + + + DisableCcpCheckbox + + + Disable CCP negotiation + + + + + + Disable Compression Control Protocol negotiation + + + Check to disabe CCP (Compression Control Protocol) negotiation. This option should only be required if the peer is buggy and gets confused by requests from pppd for CCP negotiation. + + + + + spacer73 + + + Horizontal + + + Expanding + + + + 181 + 21 + + + + + + DisableIpxCheckbox + + + Disable IPX + + + + + + Disables the IPXCP and IPX protocols + + + Disables the IPXCP and IPX protocols. This option should only be required if the peer is buggy and gets confused by requests from pppd for IPXCP negotiation. + + + + + UseNoIpDefaultCheckbox + + + Use no IP b&y default + + + Alt+Y + + + + + UseNoBsdCompCheckbox + + + Do not use BSD compression + + + + + + Do not use BSD compression (disabled by default) + + + + + DisableHeaderCompressionCheckbox + + + Disable TCP/IP header compression + + + + + + Disables the Van Jacobson style TCP/IP header compression + + + Disables the Van Jacobson style TCP/IP header compression in both the transmit and the receive direction. + + + + + DisableAdressControlCompressionCheckbox + + + Disable adress control compression + + + + + + Disable Address/Control compression in both directions + + + Disable Address/Control compression in both directions (send and receive). + + + + + DisableMagicNumberNegotiationCheckbox + + + Disable magic number negotiation + + + + + + Disables the magic number negotiation + + + Disable magic number negotiation. With this option, pppd cannot detect a looped-back line. This option should only be needed if the peer is buggy. + + + + + DisableProtocolFieldCompressionCheckbox + + + Disable protocol field compression + + + + + + Disable protocol field compression negotiation + + + Disable protocol field compression negotiation in both the receive and the transmit direction + + + + + + + spacer3 + + + Vertical + + + Expanding + + + + 20 + 138 + + + + + + + + + + AuthenticationTab + + + Authentication + + + + unnamed + + + + layout89 + + + + unnamed + + + + layout88 + + + + unnamed + + + + layout7 + + + + unnamed + + + + textLabel1 + + + Authorization method: + + + + + AuthMethodComboBox + + + + + + + RequireEapCheckbox + + + Re&quire EAP + + + Alt+Q + + + Require EAP (disabled by default), should be disabled + + + + + layout7 + + + + unnamed + + + + layout6 + + + + unnamed + + + + L2tpdDaemonLabel + + + L2TP daemon + + + + + spacer4 + + + Horizontal + + + Expanding + + + + 111 + 21 + + + + + + + + + l2tpd/xl2tpd + + + + + openl2tp + + + + L2tpDaemonComboBox + + + + + + + + + spacer72 + + + Vertical + + + Expanding + + + + 20 + 51 + + + + + + + + + + DnsTab + + + DNS + + + + unnamed + + + + layout87 + + + + unnamed + + + + layout86 + + + + unnamed + + + + DnsServerLineedit + + + false + + + + + + IP address of the DNS server (no hostname) + + + + + DnsServerCheckbox + + + Use specified DNS server: + + + Use specified DNS server instead of retrieved from peer + + + + + SearchDomainInResolvConfLineedit + + + false + + + + + + IP address of the DNS server (no hostname) + + + + + UseDomainInResolvConfCheckbox + + + Use specified DNS domain: + + + Use specified DNS server instead of retrieved from peer + + + + + UseSearchDomainInResolvConfCheckbox + + + Use specified DNS search domain: + + + Use specified DNS server instead of retrieved from peer + + + + + DomainInResolvConfLineedit + + + false + + + + + + IP address of the DNS server (no hostname) + + + + + + + spacer71 + + + Vertical + + + Expanding + + + + 20 + 71 + + + + + + + + + + + + + DnsServerCheckbox + toggled(bool) + ProfilePptpOptionsBase + useDnsServerToggled(bool) + + + UseDomainInResolvConfCheckbox + toggled(bool) + ProfilePptpOptionsBase + useDomainInResolvConfToggled(bool) + + + UseSearchDomainInResolvConfCheckbox + toggled(bool) + ProfilePptpOptionsBase + useSearchDomainInResolvConfToggled(bool) + + + + DnsServerCheckbox + DnsServerLineedit + Refuse40BitEncryptionCheckbox + Refuse128BitEncryptionCheckbox + RequireMppeCheckbox + AllowStatefulModeCheckbox + UseNoBsdCompCheckbox + UseNoDeflateCheckbox + UseNoIpDefaultCheckbox + UseNoMPPECompressionCheckbox + + + mtuToggled(bool) + useDnsServerToggled(bool) + keepDefaultRouteToggled(bool) + useNtDomainNameToggled(bool) + useSearchDomainInResolvConfToggled(bool) + useDomainInResolvConfToggled(bool) + + + + kcombobox.h + kcombobox.h + klineedit.h + klineedit.h + klineedit.h + + diff --git a/src/profilepskoptions.cpp b/src/profilepskoptions.cpp new file mode 100644 index 0000000..2926d4d --- /dev/null +++ b/src/profilepskoptions.cpp @@ -0,0 +1,68 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "profilepskoptions.h" + +#include +#include +#include +#include +#include +#include +#include +#include "widgetnotifyhelper.h" +#include + +ProfilePskOptions::ProfilePskOptions(QWidget *parent) + : ProfilePskOptionsBase(parent) +{ + WidgetNotifyHelper h; + h.setupChangedAction(this); + dialogModified=false; +} + + +ProfilePskOptions::~ProfilePskOptions() +{} + +void ProfilePskOptions::pskIsInFileToggled(bool) +{ + if (PskInFileCheckBox->isChecked()) + { + LabelPskFile->setEnabled(TRUE); + PSKFileURLRequester->setEnabled(TRUE); + LabelPsk->setEnabled(FALSE); + PSKLineEdit->setEnabled(FALSE); + } + else + { + LabelPskFile->setEnabled(FALSE); + PSKFileURLRequester->setEnabled(FALSE); + LabelPsk->setEnabled(TRUE); + PSKLineEdit->setEnabled(TRUE); + + } +} + +void ProfilePskOptions::dialogChanged() +{ +// std::cout << "ProfilePskOptions::dialogChanged()" << std::endl; + dialogModified=true; +} + diff --git a/src/profilepskoptions.h b/src/profilepskoptions.h new file mode 100644 index 0000000..0898edb --- /dev/null +++ b/src/profilepskoptions.h @@ -0,0 +1,49 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef PROFILEPSKOPTIONS_H +#define PROFILEPSKOPTIONS_H + +#include "profilepskoptionsbase.h" +#include + +/** +@author Christoph Thielecke +*/ +class ProfilePskOptions : public ProfilePskOptionsBase +{ +Q_OBJECT +public: + ProfilePskOptions(QWidget *parent); + ~ProfilePskOptions(); + bool dialogModified; + +public slots: + void pskIsInFileToggled(bool); + + +private slots: + void dialogChanged(); + +signals: + void changed(); + +}; + +#endif diff --git a/src/profilepskoptionsbase.ui b/src/profilepskoptionsbase.ui new file mode 100644 index 0000000..6a8b86a --- /dev/null +++ b/src/profilepskoptionsbase.ui @@ -0,0 +1,300 @@ + +ProfilePskOptionsBase + + + ProfilePskOptionsBase + + + + 0 + 0 + 484 + 214 + + + + PSK + + + + unnamed + + + + spacer38_3 + + + Horizontal + + + Expanding + + + + 16 + 51 + + + + + + layout21 + + + + unnamed + + + + layout117 + + + + unnamed + + + + LabelAuthType + + + Authentication type: + + + + + spacer23 + + + Horizontal + + + Expanding + + + + 50 + 20 + + + + + + AuthTypeComboBox + + + Authentication type + + + + + + + PskGroupBox + + + Pre Shared Key (Cisco: Group Password) + + + PSK options + + + + unnamed + + + + PSKLineEdit + + + true + + + Password + + + Pre-shared key for authentication (shared secret) + + + + + PSKFileURLRequester + + + + 250 + 0 + + + + File which contains Pre-shared key (shared secret) + + + + + LabelPsk + + + true + + + Pre shared key: + + + + + spacer18 + + + Horizontal + + + Expanding + + + + 118 + 20 + + + + + + PskInFileCheckBox + + + &Load PSK from file + + + Alt+L + + + Pre-shared key (shared secret) is stored in a file (e.g. on a usbstick) + + + + + spacer38 + + + Horizontal + + + Expanding + + + + 80 + 20 + + + + + + LabelPskFile + + + false + + + Pre shared key file: + + + + + spacer37 + + + Horizontal + + + Expanding + + + + 94 + 20 + + + + + + CheckSavePsk + + + Sa&ve PSK + + + Alt+V + + + Save Pre-shared key in config file (or in KWallet if available) + + + + + spacer30 + + + Horizontal + + + Expanding + + + + 152 + 20 + + + + + + + + spacer14 + + + Vertical + + + Expanding + + + + 21 + 20 + + + + + + + + + + PskInFileCheckBox + toggled(bool) + ProfilePskOptionsBase + pskIsInFileToggled(bool) + + + + AuthTypeComboBox + PskInFileCheckBox + CheckSavePsk + PSKFileURLRequester + PSKLineEdit + + + pskIsInFileToggled(bool) + useSpecialRemoteIDToggled(bool) + + + + kcombobox.h + klineedit.h + kurlrequester.h + klineedit.h + kpushbutton.h + + diff --git a/src/profileracoonoptions.cpp b/src/profileracoonoptions.cpp new file mode 100644 index 0000000..c2368f7 --- /dev/null +++ b/src/profileracoonoptions.cpp @@ -0,0 +1,98 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "profileracoonoptions.h" + +#include +#include +#include +#include +#include +#include +#include "widgetnotifyhelper.h" +#include + +ProfileRacoonOptions::ProfileRacoonOptions(QWidget *parent) + : ProfileRacoonOptionsBase(parent) +{ + WidgetNotifyHelper h; + h.setupChangedAction(this); + dialogModified=false; + + QToolTip::add( RemoteIdTypeCombobox, i18n("Remote ID type
" + "" + "" + "" + "" + "" + "" + "
none:No ID
address:The type is the IP address. This is the default type if you do not specify an identifier to use
user_fqdn:The type is a USER_FQDN (user fully-qualified domain name)
fqdn:The type is a FQDN (fully-qualified domain name)
keyid (file):The type is a KEY_ID, read from the file
keyid:The type is a KEY_ID, specified in field
asn1dn:The type is an ASN.1 distinguished name. If empty, DN from the Subject field in the certificate will be used" + "")); + + QToolTip::add( LocalIdTypeCombobox, i18n("Local ID type
" + "" + "" + "" + "" + "" + "" + "
none:No ID
address:The type is the IP address. This is the default type if you do not specify an identifier to use
user_fqdn:The type is a USER_FQDN (user fully-qualified domain name)
fqdn:The type is a FQDN (fully-qualified domain name)
keyid (file):The type is a KEY_ID, read from the file
keyid:The type is a KEY_ID, specified in field
asn1dn:The type is an ASN.1 distinguished name. If empty, DN from the Subject field in the certificate will be used" + "")); + + +} + + +ProfileRacoonOptions::~ProfileRacoonOptions() +{} + +void ProfileRacoonOptions::localIDTypeToggled(const QString& text) +{ + if (text == "none") + { + LocalIDLineEdit->setDisabled(true); + LocalIDLabel->setDisabled(true); + } + else + { + LocalIDLineEdit->setDisabled(false); + LocalIDLabel->setDisabled(false); + } +} + +void ProfileRacoonOptions::dialogChanged() +{ +// std::cout << "ProfileRacoonOptions::dialogChanged()" << std::endl; + dialogModified=true; +} + + +void ProfileRacoonOptions::remoteIDTypeToggled(const QString& text) +{ + if (text == "none") + { + RemoteIDLineEdit->setDisabled(true); + RemoteIDLabel->setDisabled(true); + } + else + { + RemoteIDLineEdit->setDisabled(false); + RemoteIDLabel->setDisabled(false); + } +} diff --git a/src/profileracoonoptions.h b/src/profileracoonoptions.h new file mode 100644 index 0000000..01f73ac --- /dev/null +++ b/src/profileracoonoptions.h @@ -0,0 +1,50 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef PROFILERACOONOPTIONS_H +#define PROFILERACOONOPTIONS_H + +#include "profileracoonoptionsbase.h" +#include + +/** +@author Christoph Thielecke +*/ +class ProfileRacoonOptions : public ProfileRacoonOptionsBase +{ +Q_OBJECT +public: + ProfileRacoonOptions(QWidget *parent); + ~ProfileRacoonOptions(); + bool dialogModified; + +public slots: + void localIDTypeToggled(const QString&); + void remoteIDTypeToggled(const QString&); + + +private slots: + void dialogChanged(); + +signals: + void changed(); + +}; + +#endif diff --git a/src/profileracoonoptionsbase.ui b/src/profileracoonoptionsbase.ui new file mode 100644 index 0000000..88449c7 --- /dev/null +++ b/src/profileracoonoptionsbase.ui @@ -0,0 +1,884 @@ + +ProfileRacoonOptionsBase + + + ProfileRacoonOptionsBase + + + + 0 + 0 + 382 + 332 + + + + Racoon + + + + unnamed + + + + layout63 + + + + unnamed + + + + textLabel1 + + + racoon + ipsec tools specific settings (Linux &2.6 native or BSD + + + + + tabWidget3 + + + + GeneralTab + + + General + + + + unnamed + + + + layout62 + + + + unnamed + + + + layout61 + + + + unnamed + + + + layout75 + + + + unnamed + + + + UseModeConfigCheckBox + + + &Use Mode Configuration + + + Alt+U + + + + + + + layout42 + + + + unnamed + + + + ExchangeModeComboBox + + + Internet Key Exchange mode + + + + + layout72 + + + + unnamed + + + + HashAlgoTextLabel_2 + + + Exchange mode: + + + + + spacer72 + + + Horizontal + + + Expanding + + + + 91 + 21 + + + + + + + + EncryptionAlgorithm2ComboBox + + + + + + + + layout69 + + + + unnamed + + + + HashAlgoTextLabel + + + Authentication algorithm phase 1: + + + Use specified hash algorithm for IKE phase 1 + + + + + spacer69 + + + Horizontal + + + Expanding + + + + 101 + 21 + + + + + + + + EncryptionAlgorithmComboBox + + + + + + + + layout39 + + + + unnamed + + + + PerfectForwardSecurityCheckbox + + + Perfect forward secrec&y (PFS): + + + Alt+Y + + + Use perfect forward secrety (PFS) + + + + + spacer34_2 + + + Horizontal + + + Expanding + + + + 31 + 20 + + + + + + + + layout71 + + + + unnamed + + + + EncryptionAlgorithm2TextLabel + + + Encryption algorithm phase 1: + + + + + spacer71 + + + Horizontal + + + Expanding + + + + 101 + 21 + + + + + + + + layout37 + + + + unnamed + + + + IkeGroupCheckbox + + + &IKE DH group: + + + Alt+I + + + Use special Diffie Hellman group + + + + + spacer33_2 + + + Horizontal + + + Expanding + + + + 61 + 21 + + + + + + + + PerfectForwardSecrecyCombobox + + + false + + + Diffie Helman group for Perfect Forward Secrecy + Automatic keying has a property called perfect forward secrecy. This is the Diffie Helman group for PFS. + + + This is the Diffie Helman group for PFS. +The following assignment will is used: +server = DH group is recieved from server (cisco only) +nopfs = no pfs is used +dh1 = modp768 +dh2 = modp1024 +dh5 = modp1536 +d14 = modp2048 (racoon only) +dh15= modp3072 (racoon only) +dh16 = modp4096 (racoon only) +dh17 = modp6144 (racoon only) +dh18 = modp8192 (racoon only) + + + + + DHGroupComboBox + + + false + + + Diffie Hellman group + + + This define the group used for the Diffie-Hellman exponentiations. The following assignment is used: +dh1 = modp768 +dh2 = modp1024 +dh5 = modp1536 +d14 = modp2048 (only racoon) +dh15 = modp3072 (only racoon) +dh16 = modp4096 (only racoon) +dh17 = modp6144 (only racoon) +dh18 = modp8192 (only racoon) + + + + + HashAlgoComboBox + + + Use specified hash algorithm for IKE phase 1 + + + + + AuthenticationAlgorithm2ComboBox + + + + + + + + layout71_2 + + + + unnamed + + + + EncryptionAlgorithm2TextLabel_2 + + + Encryption algorithm phase 2: + + + + + spacer71_2 + + + Horizontal + + + Expanding + + + + 101 + 21 + + + + + + + + layout70_2 + + + + unnamed + + + + AuthenticationAlgorithm2TextLabel_2 + + + Authentication algorithm phase 2: + + + + + spacer70_2 + + + Horizontal + + + Expanding + + + + 81 + 21 + + + + + + + + + + + + spacer44 + + + Vertical + + + Expanding + + + + 20 + 21 + + + + + + + + + + IdTab + + + Local/Remote ID + + + + unnamed + + + + layout51 + + + + unnamed + + + + RemoteIdentifierGroupBox + + + Remote identifier + + + + unnamed + + + + layout74_2 + + + + unnamed + + + + layout73_2 + + + + unnamed + + + + HashAlgoTextLabel_2_2_2 + + + ID type + + + + + spacer72_2_3 + + + Horizontal + + + Expanding + + + + 51 + 20 + + + + + + + + RemoteIDLineEdit + + + false + + + Normal + + + Value for the local ID + + + + + layout72_2_2 + + + + unnamed + + + + RemoteIDLabel + + + ID value + + + + + spacer72_2_2_2 + + + Horizontal + + + Expanding + + + + 51 + 20 + + + + + + + + RemoteIdTypeCombobox + + + false + + + This is the type of the local ID (default: asn1dn)<br> +<ul> +<li>asn1dn - the type is an ASN.1 distinguished name. Use 'use email address as identifier' in certificate settings if it should be the mail address. If this option is not checked, the DN from the Subject field in the certificate will be used.</li> +<li>address - the type is the IP address.</li> +<li>fqdn - the type is a FQDN (fully-qualified domain name).</li> +<li>keyid - the type is a KEY_ID (file)</li> +<li>user_fqdn - the type is a USER_FQDN (user fully-qualified domain name).</li> +</ul> + Automatic keying has a property called perfect forward secrecy. This is the Diffie Helman group for PFS. + + + This is the type of the local ID (default: asn1dn)<br> +<ul> +<li>asn1dn - the type is an ASN.1 distinguished name. Use 'use email address as identifier' in certificate settings if it should be the mail address. If this option is not checked, the DN from the Subject field in the certificate will be used.</li> +<li>address - the type is the IP address.</li> +<li>fqdn - the type is a FQDN (fully-qualified domain name).</li> +<li>keyid - the type is a KEY_ID (file)</li> +<li>user_fqdn - the type is a USER_FQDN (user fully-qualified domain name).</li> +</ul> + + + + + + + + + LocalIdentifierGroupBox + + + Local identifier + + + + unnamed + + + + layout74 + + + + unnamed + + + + layout73 + + + + unnamed + + + + HashAlgoTextLabel_2_2 + + + ID type + + + + + spacer72_2 + + + Horizontal + + + Expanding + + + + 51 + 20 + + + + + + + + LocalIDLineEdit + + + false + + + Normal + + + Value for the local ID + + + + + layout72_2 + + + + unnamed + + + + LocalIDLabel + + + ID value + + + + + spacer72_2_2 + + + Horizontal + + + Expanding + + + + 51 + 20 + + + + + + + + LocalIdTypeCombobox + + + false + + + This is the type of the local ID (default: asn1dn)<br> +<ul> +<li>asn1dn - the type is an ASN.1 distinguished name. Use 'use email address as identifier' in certificate settings if it should be the mail address. If this option is not checked, the DN from the Subject field in the certificate will be used.</li> +<li>address - the type is the IP address.</li> +<li>fqdn - the type is a FQDN (fully-qualified domain name).</li> +<li>keyid - the type is a KEY_ID (file)</li> +<li>user_fqdn - the type is a USER_FQDN (user fully-qualified domain name).</li> +</ul> + Automatic keying has a property called perfect forward secrecy. This is the Diffie Helman group for PFS. + + + This is the type of the local ID (default: asn1dn)<br> +<ul> +<li>asn1dn - the type is an ASN.1 distinguished name. Use 'use email address as identifier' in certificate settings if it should be the mail address. If this option is not checked, the DN from the Subject field in the certificate will be used.</li> +<li>address - the type is the IP address.</li> +<li>fqdn - the type is a FQDN (fully-qualified domain name).</li> +<li>keyid - the type is a KEY_ID (file)</li> +<li>user_fqdn - the type is a USER_FQDN (user fully-qualified domain name).</li> +</ul> + + + + + + + + + spacer36 + + + Vertical + + + Expanding + + + + 20 + 51 + + + + + + + + + + AuthenticationTab + + + Authentication + + + + unnamed + + + + layout60 + + + + unnamed + + + + layout90_2 + + + + unnamed + + + + UseXauthCheckBox + + + Authenticate &with username and password (XAUTH) + + + Alt+W + + + enable this if you want enable the XAUTh extension + + + + + spacer6_2_2 + + + Horizontal + + + Expanding + + + + 100 + 20 + + + + + + + + spacer43 + + + Vertical + + + Expanding + + + + 21 + 191 + + + + + + + + + + + + + + useLeftNextHopToggled(bool) + useRightNextHopToggled(bool) + localIDTypeToggled(const QString&) + remoteIDTypeToggled(const QString&) + + + + kcombobox.h + kcombobox.h + klineedit.h + kcombobox.h + klineedit.h + kcombobox.h + + diff --git a/src/profilesmartcardoptions.cpp b/src/profilesmartcardoptions.cpp new file mode 100644 index 0000000..1e220ea --- /dev/null +++ b/src/profilesmartcardoptions.cpp @@ -0,0 +1,81 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "profilesmartcardoptions.h" + +#include +#include +#include +#include +#include +#include +#include +#include "widgetnotifyhelper.h" +#include + +ProfileSmartcardOptions::ProfileSmartcardOptions(QWidget *parent) + : ProfileSmartcardOptionsBase(parent) +{ + WidgetNotifyHelper h; + h.setupChangedAction(this); + dialogModified=false; +} + + +ProfileSmartcardOptions::~ProfileSmartcardOptions() +{} + +void ProfileSmartcardOptions::usePkcs11ProvidersToggled(bool) +{ + if (UsePkcs11ProvidersCheckBox->isChecked()) + Pkcs11ProvidersURLRequester->setEnabled(true); + else + Pkcs11ProvidersURLRequester->setEnabled(false); +} + +void ProfileSmartcardOptions::useSmartcardToggled(bool) +{ + if(UseSmartcardCheckBox->isChecked()) + SmartcardGroupBox->setEnabled(true); + else + SmartcardGroupBox->setEnabled(false); +} + +void ProfileSmartcardOptions::idTypeToggled() +{ +// if (Pkcs11IdTypeComboBox->currentItem() == 0) +// IdLabel->setText(i18n("ID")); +// else if (Pkcs11IdTypeComboBox->currentItem() == 1) +// IdLabel->setText(i18n("Label")); +// else +// IdLabel->setText(i18n("Description")); +} + +void ProfileSmartcardOptions::dialogChanged() +{ +// std::cout << "ProfileSmartcardOptions::dialogChanged()" << std::endl; + dialogModified=true; +} + + + + + + + diff --git a/src/profilesmartcardoptions.h b/src/profilesmartcardoptions.h new file mode 100644 index 0000000..bca0949 --- /dev/null +++ b/src/profilesmartcardoptions.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef PROFILESMARTCARDOPTIONS_H +#define PROFILESMARTCARDOPTIONS_H + +#include "profilesmartcardoptionsbase.h" +#include + + + +/** +@author Christoph Thielecke +*/ +class ProfileSmartcardOptions : public ProfileSmartcardOptionsBase +{ +Q_OBJECT +public: + ProfileSmartcardOptions(QWidget *parent); + ~ProfileSmartcardOptions(); + bool dialogModified; + +public slots: + void useSmartcardToggled(bool); + void usePkcs11ProvidersToggled(bool); + virtual void idTypeToggled(); + + +private slots: + void dialogChanged(); + +signals: + void changed(); + +}; + +#endif diff --git a/src/profilesmartcardoptionsbase.ui b/src/profilesmartcardoptionsbase.ui new file mode 100644 index 0000000..6160343 --- /dev/null +++ b/src/profilesmartcardoptionsbase.ui @@ -0,0 +1,476 @@ + +ProfileSmartcardOptionsBase + + + ProfileSmartcardOptionsBase + + + + 0 + 0 + 396 + 269 + + + + + 1 + 1 + 0 + 0 + + + + Smartcard + + + + unnamed + + + + layout157 + + + + unnamed + + + + layout156 + + + + unnamed + + + + layout155 + + + + unnamed + + + + layout154 + + + + unnamed + + + + UseSmartcardCheckBox + + + Enable PKCS&11 smartcard support + + + Alt+1 + + + + + + + + spacer48 + + + Horizontal + + + Expanding + + + + 210 + 20 + + + + + + + + layout41 + + + + unnamed + + + + + + SmartcardGroupBox + + + false + + + PKCS11 smartcard + + + + unnamed + + + + layout56 + + + + unnamed + + + + layout24 + + + + unnamed + + + + layout23 + + + + unnamed + + + + Pkcs11SlotTypeLabel + + + Slot type + + + + + + auto + + + + + sign + + + + + recover + + + + + any + + + + Pkcs11SignModeComboBox + + + + + + ID + + + + + Name + + + + + Label + + + + Pkcs11SlotTypeComboBox + + + + 3 + 0 + 0 + 0 + + + + + + textLabel5 + + + Sign mode + + + + + + + layout22 + + + + unnamed + + + + spacer20 + + + Horizontal + + + Expanding + + + + 241 + 21 + + + + + + + ID + + + + + Label + + + + + Subject + + + + Pkcs11IdTypeComboBox + + + + + textLabel2 + + + ID type + + + + + + + + + layout55 + + + + unnamed + + + + DetectPkcs11IdPushButton + + + Detect + + + + + textLabel3 + + + Slot + + + + + IdLabel + + + ID + + + + + Pkcs11SlotComboBox + + + + 3 + 0 + 0 + 0 + + + + 5 + + + 15 + + + false + + + + + DetectPkcs11SlotsPushButton + + + Detect + + + + + Pkcs11IdComboBox + + + + 3 + 0 + 0 + 0 + + + + true + + + 50 + + + false + + + + + + + layout31 + + + + unnamed + + + + UsePkcs11ProvidersCheckBox + + + Use token provider &library: + + + Alt+L + + + + + Pkcs11ProvidersURLRequester + + + false + + + + + + + + + + + + + spacer14 + + + Vertical + + + Expanding + + + + 21 + 40 + + + + + + + + spacer38_3 + + + Horizontal + + + Expanding + + + + 16 + 51 + + + + + + + + + + UsePkcs11ProvidersCheckBox + toggled(bool) + ProfileSmartcardOptionsBase + usePkcs11ProvidersToggled(bool) + + + UseSmartcardCheckBox + toggled(bool) + ProfileSmartcardOptionsBase + useSmartcardToggled(bool) + + + + UseSmartcardCheckBox + Pkcs11SlotTypeComboBox + Pkcs11IdTypeComboBox + Pkcs11SignModeComboBox + Pkcs11SlotComboBox + DetectPkcs11SlotsPushButton + Pkcs11IdComboBox + DetectPkcs11IdPushButton + UsePkcs11ProvidersCheckBox + Pkcs11ProvidersURLRequester + + + usePkcs11ProvidersToggled(bool) + useSmartcardToggled(bool) + idTypeToggled() + + + + kcombobox.h + kcombobox.h + kcombobox.h + kpushbutton.h + kcombobox.h + kpushbutton.h + kcombobox.h + kurlrequester.h + klineedit.h + kpushbutton.h + + diff --git a/src/profilesshoptions.cpp b/src/profilesshoptions.cpp new file mode 100644 index 0000000..c6d1546 --- /dev/null +++ b/src/profilesshoptions.cpp @@ -0,0 +1,98 @@ +/*************************************************************************** + * Copyright (C) 2007 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "profilesshoptions.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "widgetnotifyhelper.h" +#include + +ProfileSshOptions::ProfileSshOptions(QWidget *parent) + : ProfileSshOptionsBase(parent) +{ + WidgetNotifyHelper h; + h.setupChangedAction(this); + dialogModified=false; +} + + +ProfileSshOptions::~ProfileSshOptions() +{} + +void ProfileSshOptions::usePortToggled(bool) +{ + if (UseUserdefinedRemotePortCheckBox->isChecked()) + UserdefinedRemotePortSpinBox->setEnabled(true); + else + UserdefinedRemotePortSpinBox->setEnabled(false); +} + +void ProfileSshOptions::dialogChanged() +{ +// std::cout << "ProfileSshOptions::dialogChanged()" << std::endl; + dialogModified=true; +} + +void ProfileSshOptions::sshKeyToggled(bool) +{ + if (AutoKeyRadioButton->isChecked()) + { + SshKeyComboBox->setEnabled(true); + CostumkeyURLRequester->setEnabled(false); + } + else + { + SshKeyComboBox->setEnabled(false); + CostumkeyURLRequester->setEnabled(true); + } +} + +void ProfileSshOptions::sshAuthToggled(bool) +{ + if (AuthKeyRadioButton->isChecked() && !AuthPassRadioButton->isChecked()) + { +// KMessageBox::information ( this, "auth key is set", "a" ); + SshkeyButtonGroup->setEnabled(true); + } + if (!AuthKeyRadioButton->isChecked() && AuthPassRadioButton->isChecked()) + { +// KMessageBox::information ( this, "auth pass is set", "a" ); + SshkeyButtonGroup->setEnabled(false); + } + sshKeyToggled(true); +} + + + +void ProfileSshOptions::useSshConfigRemoteScriptToggled(bool) +{ + if (UseSshConfigRemoteScriptCheckBox->isChecked()) + SshConfigRemoteScriptLineEdit->setEnabled(true); + else + SshConfigRemoteScriptLineEdit->setEnabled(false); +} diff --git a/src/profilesshoptions.h b/src/profilesshoptions.h new file mode 100644 index 0000000..68a92db --- /dev/null +++ b/src/profilesshoptions.h @@ -0,0 +1,51 @@ +/*************************************************************************** + * Copyright (C) 2007 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef PROFILESSHOPTIONS_H +#define PROFILESSHOPTIONS_H + +#include "profilesshoptionsbase.h" +#include + +/** +@author Christoph Thielecke +*/ +class ProfileSshOptions : public ProfileSshOptionsBase +{ +Q_OBJECT +public: + ProfileSshOptions(QWidget *parent); + ~ProfileSshOptions(); + bool dialogModified; + +public slots: + void usePortToggled(bool); + void sshKeyToggled(bool); + void sshAuthToggled(bool); + void useSshConfigRemoteScriptToggled(bool); + +private slots: + void dialogChanged(); + +signals: + void changed(); + +}; + +#endif diff --git a/src/profilesshoptionsbase.ui b/src/profilesshoptionsbase.ui new file mode 100644 index 0000000..17d833f --- /dev/null +++ b/src/profilesshoptionsbase.ui @@ -0,0 +1,372 @@ + +ProfileSshOptionsBase + + + ProfileSshOptionsBase + + + + 0 + 0 + 490 + 421 + + + + SSH + + + + unnamed + + + + layout7 + + + + unnamed + + + + layout209 + + + + unnamed + + + + UseUserdefinedRemotePortCheckBox + + + &Use specified remote port: + + + Alt+U + + + Use non standard TCP/UDP port + + + + + spacer6_3 + + + Horizontal + + + Expanding + + + + 82 + 20 + + + + + + UserdefinedRemotePortSpinBox + + + false + + + 65535 + + + 1 + + + 22 + + + Port number + + + + + + + layout6 + + + + unnamed + + + + UseSshConfigRemoteScriptCheckBox + + + &Use network config script on server: + + + Alt+U + + + Use non standard TCP/UDP port + + + + + SshConfigRemoteScriptLineEdit + + + false + + + full path to script on server + + + Parameter 0: script name e.g. /root/ssh_vpn_up.sh +Parameter 1: device type e.g. tun +Parameter 2: ip address e.g. 1.2.3.4 (tun) +Parameter 3: remote ip address 1.2.3.5 (tun) + + + + + + + layout9 + + + + unnamed + + + + buttonGroup1 + + + Authentication + + + + unnamed + + + + AuthKeyRadioButton + + + &Key + + + Alt+K + + + + + AuthPassRadioButton + + + Pass&word + + + Alt+W + + + true + + + + + + + spacer132 + + + Horizontal + + + Expanding + + + + 194 + 41 + + + + + + + + SshkeyButtonGroup + + + false + + + SSH key + + + + unnamed + + + + SshKeyComboBox + + + + 200 + 0 + + + + + + layout7 + + + + unnamed + + + + CostumKeyRadioButton + + + Costum key: + + + + + spacer6 + + + Horizontal + + + Expanding + + + + 51 + 20 + + + + + + + + CostumkeyURLRequester + + + + + layout10 + + + + unnamed + + + + AutoKeyRadioButton + + + autodetected ke&y: + + + Alt+Y + + + true + + + + + spacer7 + + + Horizontal + + + Expanding + + + + 41 + 21 + + + + + + + + + + spacer130 + + + Vertical + + + Expanding + + + + 20 + 140 + + + + + + + + + + UseUserdefinedRemotePortCheckBox + toggled(bool) + ProfileSshOptionsBase + usePortToggled(bool) + + + AuthKeyRadioButton + toggled(bool) + ProfileSshOptionsBase + sshKeyToggled(bool) + + + CostumKeyRadioButton + toggled(bool) + ProfileSshOptionsBase + sshKeyToggled(bool) + + + AuthPassRadioButton + toggled(bool) + ProfileSshOptionsBase + sshAuthToggled(bool) + + + UseSshConfigRemoteScriptCheckBox + toggled(bool) + ProfileSshOptionsBase + useSshConfigRemoteScriptToggled(bool) + + + + usePortToggled(bool) + sshKeyToggled(bool) + sshAuthToggled(bool) + useSshConfigRemoteScriptToggled(bool) + + + + klineedit.h + kcombobox.h + kurlrequester.h + klineedit.h + kpushbutton.h + + diff --git a/src/profileuseroptions.cpp b/src/profileuseroptions.cpp new file mode 100644 index 0000000..70336c9 --- /dev/null +++ b/src/profileuseroptions.cpp @@ -0,0 +1,54 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "profileuseroptions.h" + +#include +#include + +#include "widgetnotifyhelper.h" +#include + +ProfileUserOptions::ProfileUserOptions(QWidget *parent) + : ProfileUserOptionsBase(parent) +{ + WidgetNotifyHelper h; + h.setupChangedAction(this); + dialogModified=false; +} + + +ProfileUserOptions::~ProfileUserOptions() +{} + +void ProfileUserOptions::domainNameToggled(bool) +{ + if ( NtDomainNameCheckbox->isChecked() ) + NtDomainNameLineedit->setEnabled( true ); + else + NtDomainNameLineedit->setEnabled( false ); +} + +void ProfileUserOptions::dialogChanged() +{ +// std::cout << "ProfileUserOptions::dialogChanged()" << std::endl; + dialogModified=true; +} + + diff --git a/src/profileuseroptions.h b/src/profileuseroptions.h new file mode 100644 index 0000000..98f4e91 --- /dev/null +++ b/src/profileuseroptions.h @@ -0,0 +1,49 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef PROFILEUSEROPTIONS_H +#define PROFILEUSEROPTIONS_H + +#include "profileuseroptionsbase.h" +#include + +/** +@author Christoph Thielecke +*/ +class ProfileUserOptions : public ProfileUserOptionsBase +{ + Q_OBJECT +public: + ProfileUserOptions(QWidget *parent); + ~ProfileUserOptions(); + bool dialogModified; + +public slots: + void domainNameToggled(bool); + + +private slots: + void dialogChanged(); + +signals: + void changed(); + +}; + +#endif diff --git a/src/profileuseroptionsbase.ui b/src/profileuseroptionsbase.ui new file mode 100644 index 0000000..1c3d6a9 --- /dev/null +++ b/src/profileuseroptionsbase.ui @@ -0,0 +1,315 @@ + +ProfileUserOptionsBase + + + ProfileUserOptionsBase + + + + 0 + 0 + 360 + 235 + + + + User Data + + + + unnamed + + + + layout7 + + + + unnamed + + + + layout17 + + + + unnamed + + + + PasswordEdit + + + Password + + + Password for authentication + + + + + layout31 + + + + unnamed + + + + NtDomainNameCheckbox + + + false + + + N&T domain name: + + + Alt+T + + + Use NT domain for authentication + + + + + spacer14 + + + Horizontal + + + Expanding + + + + 121 + 21 + + + + + + + + NtDomainNameLineedit + + + false + + + NT domain name for authentication + + + + + spacer13 + + + Horizontal + + + Expanding + + + + 133 + 20 + + + + + + UsernameLineEdit + + + Username for authentication + + + + + DontSaveUsernameCheckBox + + + Dont save username + + + + + + Do not save the username in config nor KWallet + + + + + spacer12 + + + Horizontal + + + Expanding + + + + 133 + 20 + + + + + + layout55 + + + + unnamed + + + + LabelPassword + + + Password: + + + + + spacer62 + + + Horizontal + + + Expanding + + + + 211 + 21 + + + + + + + + layout54 + + + + unnamed + + + + LabelUsername + + + Username: + + + + + spacer61 + + + Horizontal + + + Expanding + + + + 211 + 21 + + + + + + + + CheckUserPass + + + Save &user password + + + Alt+U + + + Save user password in config file (or in KWallet if available) + + + + + + + HideGroupPasswordInAccountDataDialogCheckBox + + + Hide group pass&word field in account data dialog + + + Alt+W + + + Do not show group password field in dialog for request username/password. + + + + + AskUserPasswordOnEachConnectCheckBox + + + false + + + Ask user password on each connect + + + + + + If this option is enabled, on each connect the user password will be asked. + + + + + spacer2 + + + Vertical + + + Expanding + + + + 20 + 43 + + + + + + + + + UsernameLineEdit + PasswordEdit + NtDomainNameCheckbox + NtDomainNameLineedit + CheckUserPass + DontSaveUsernameCheckBox + HideGroupPasswordInAccountDataDialogCheckBox + + + domainNameToggled(bool) + + + + klineedit.h + klineedit.h + + diff --git a/src/profilevtunoptions.cpp b/src/profilevtunoptions.cpp new file mode 100644 index 0000000..baa732e --- /dev/null +++ b/src/profilevtunoptions.cpp @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (C) 2007 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "profilevtunoptions.h" + +#include +#include +#include +#include +#include "widgetnotifyhelper.h" +#include + +ProfileVtunOptions::ProfileVtunOptions(QWidget *parent) + : ProfileVtunOptionsBase(parent) +{ + WidgetNotifyHelper h; + h.setupChangedAction(this); + dialogModified=false; +} + + +ProfileVtunOptions::~ProfileVtunOptions() +{} + +void ProfileVtunOptions::usePortToggled(bool) +{ + if (PortCheckbox->isChecked()) + PortSpinbox->setEnabled(true); + else + PortSpinbox->setEnabled(false); +} + +void ProfileVtunOptions::dialogChanged() +{ +// std::cout << "ProfileVtunOptions::dialogChanged()" << std::endl; + dialogModified=true; +} diff --git a/src/profilevtunoptions.h b/src/profilevtunoptions.h new file mode 100644 index 0000000..915c84a --- /dev/null +++ b/src/profilevtunoptions.h @@ -0,0 +1,48 @@ +/*************************************************************************** + * Copyright (C) 2007 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef PROFILEVTUNOPTIONS_H +#define PROFILEVTUNOPTIONS_H + +#include "profilevtunoptionsbase.h" +#include + +/** +@author Christoph Thielecke +*/ +class ProfileVtunOptions : public ProfileVtunOptionsBase +{ +Q_OBJECT +public: + ProfileVtunOptions(QWidget *parent); + ~ProfileVtunOptions(); + bool dialogModified; + +public slots: + void usePortToggled(bool); + +private slots: + void dialogChanged(); + +signals: + void changed(); + +}; + +#endif diff --git a/src/profilevtunoptionsbase.ui b/src/profilevtunoptionsbase.ui new file mode 100644 index 0000000..bc28153 --- /dev/null +++ b/src/profilevtunoptionsbase.ui @@ -0,0 +1,214 @@ + +ProfileVtunOptionsBase + + + ProfileVtunOptionsBase + + + + 0 + 0 + 678 + 297 + + + + Vtun + + + + unnamed + + + + layout118 + + + + unnamed + + + + layout9 + + + + unnamed + + + + + + spacer59 + + + Horizontal + + + Expanding + + + + 439 + 21 + + + + + + + + layout28 + + + + unnamed + + + + layout27 + + + + unnamed + + + + layout22 + + + + unnamed + + + + LabelID + + + VTun profile: + + + + + spacer15 + + + Horizontal + + + Expanding + + + + 50 + 20 + + + + + + VtunProfileLineEdit + + + IPSec ID of the remote side + + + + + + + layout16 + + + + unnamed + + + + PortCheckbox + + + Use userdefined port: + + + + + + + + spacer18 + + + Horizontal + + + Expanding + + + + 81 + 21 + + + + + + PortSpinbox + + + false + + + 65535 + + + 5000 + + + Local port number + + + + + + + + + spacer4 + + + Vertical + + + Expanding + + + + 20 + 22 + + + + + + + + + + PortCheckbox + toggled(bool) + ProfileVtunOptionsBase + usePortToggled(bool) + + + + VtunProfileLineEdit + + + usePortToggled(bool) + + + + klineedit.h + + diff --git a/src/toolinfo.cpp b/src/toolinfo.cpp new file mode 100644 index 0000000..754467a --- /dev/null +++ b/src/toolinfo.cpp @@ -0,0 +1,641 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "toolinfo.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +ToolInfo::ToolInfo( const QString &Name) +{ + this->Name = Name; + this->programsInPath = programsInPath; + this->found = false; + TryPath_first=""; + /* + if (!PathToExec.isEmpty()) + SearchPathList.append(PathToExec);*/ +// if (config->KvpncDebugLevel > 2) +// std::cout << "Checking for: " << Name.ascii() << std::endl; + + Version=i18n("No info"); + + env = new QStringList(); + *env << "LC_ALL=C" << "LANG=C" << "PATH=/bin:/usr/bin:/usr/sbin:/sbin"; + + collectRunning=false; + collectOpenvpnCapabilitiesRunning=false; + collectToolInfo(); +} + +bool ToolInfo::collectToolInfo() +{ + if(programsInPath) + { + addSearchPath("/usr/local/sbin"); + addSearchPath("/usr/sbin"); + addSearchPath("/sbin"); + addSearchPath("/usr/local/bin"); + addSearchPath("/usr/bin"); + addSearchPath("/bin"); + + addSearchPath(QString (QString(getenv("HOME"))+"/bin")); + } + + bool success = false; + found = false; + + if ( TryPath_first.isEmpty() ) + TryPath_first=Name; + + QStringList::Iterator it; + if (QFile (TryPath_first).exists() && QFileInfo(TryPath_first).isFile() ) + { +// if (GlobalConfig->KvpncDebugLevel > 2) +// std::cout << Name.ascii() << "found at: " << TryPath_first.ascii() << ", was first try" << std::endl; + found = true; + PathToExec=TryPath_first; + } + else + { +// if (GlobalConfig->KvpncDebugLevel > 2) +// { +// std::cout << QString(i18n("Trying first %1 at %2 has been failed, trying other paths").arg(Name).arg(TryPath_first)).ascii() << std::endl; +// std::cout << "searchpath list: " << SearchPathList.join(" ").ascii() << std::endl; +// } +// std::cout << "searchpath list: " << SearchPathList.join(" ").ascii() << std::endl; + for (QStringList::Iterator it = SearchPathList.begin();it != SearchPathList.end();it++) + { + QString TryPath=QString(*it)+"/"+Name; +// if (GlobalConfig->KvpncDebugLevel > 2) +// std::cout << QString (i18n("Trying %1 at: %2").arg(Name).arg(TryPath)).ascii() << std::endl; + + if (!TryPath.isEmpty() && QFile (TryPath).exists() && QFileInfo(TryPath).isFile() ) + { +// if (GlobalConfig->KvpncDebugLevel > 2) +// std::cout << QString(i18n("%1 found at: %2").arg(Name).arg(TryPath)).ascii() << std::endl; + found=true; + PathToExec=TryPath; + break; + } + } + } + + if ( found) + { + + CollectToolInfoProcess = new QProcess(this); + CollectToolInfoProcess->clearArguments(); + connect( CollectToolInfoProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutCollectToolInfo() ) ); + connect( CollectToolInfoProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrCollectToolInfo() ) ); + //connect( CollectToolInfoProcess, SIGNAL( processExited () ), this, SLOT(processFinished() ) ); + bool run=true; + + //FIXME how it could be better? + CollectToolInfoProcess->addArgument(PathToExec); + if (Name == "vpnc") + CollectToolInfoProcess->addArgument("--version"); + else if (Name == "vpnclient") { } + else if (Name == "ipsec") + CollectToolInfoProcess->addArgument("--version"); + else if (Name == "racoon" ) + { + // we need to do some stupid hack... + // /usr/sbin/racoon -> /usr/sbin/setkey + CollectToolInfoProcess->clearArguments(); + CollectToolInfoProcess->addArgument(QString(PathToExec.left(PathToExec.length()-6)+"setkey")); + CollectToolInfoProcess->addArgument("-V"); + } + else if (Name == "setkey") + CollectToolInfoProcess->addArgument("-V"); + else if (Name == "openvpn") + CollectToolInfoProcess->addArgument("--version"); + else if (Name == "openssl") + CollectToolInfoProcess->addArgument("version"); + else if (Name == "pppd") + CollectToolInfoProcess->addArgument("--version"); + else if (Name == "iptables") + CollectToolInfoProcess->addArgument("-V"); + else if (Name == "kill") + { + // run=false; + // success=true; + CollectToolInfoProcess->addArgument("-V"); + } + else if (Name == "killall") + CollectToolInfoProcess->addArgument("-V"); + else if (Name == "ping") + CollectToolInfoProcess->addArgument("-V"); + else if (Name == "ip") + CollectToolInfoProcess->addArgument("-V"); + else if (Name == "ifconfig") + CollectToolInfoProcess->addArgument("-V"); + else if (Name == "route") + CollectToolInfoProcess->addArgument("-V"); + else if (Name == "pptp") + ; + else if (Name == "l2tpd") + CollectToolInfoProcess->addArgument("-D"); + else if (Name == "xl2tpd") + CollectToolInfoProcess->addArgument("-v"); + else if (Name == "openl2tpd") + { + CollectToolInfoProcess->addArgument("-c"); + CollectToolInfoProcess->addArgument("-"); + CollectToolInfoProcess->addArgument("-f"); + } + else if (Name =="pkcs11-tool") + CollectToolInfoProcess->addArgument("-I"); + else if (Name =="vtund") + CollectToolInfoProcess->addArgument("-h"); + else if (Name == "cisco_cert_mgr"); + else if (Name =="tail") + CollectToolInfoProcess->addArgument("--version"); + else if (Name =="ssh") + CollectToolInfoProcess->addArgument("-V"); + else if (Name =="ksshaskpass") + CollectToolInfoProcess->addArgument("--version"); +// else if (Name =="gnome-ssh-askpass") +// CollectToolInfoProcess->addArgument("--version"); + else if (Name =="netstat") + CollectToolInfoProcess->addArgument("--version"); + else + { +// if (GlobalConfig->KvpncDebugLevel > 2) +// std::cout << "Invalid tool (" << Name.ascii() <<")!" << std::endl; + run=false; + success=false; + } + + collectRunning=false; + + if (run ) + { + + if ( !PathToExec.isEmpty() && !CollectToolInfoProcess->start(env) ) + { + std::cerr << (i18n("Unable to start collectToolInfo process (%1)!").arg(Name)).ascii() << std::endl; + //delete CollectToolInfoProcess; + collectRunning=false; + success=false; + } + else + { + collectRunning=true; + + while(CollectToolInfoProcess->isRunning() && collectRunning) + { + if (Name == "l2tpd" || Name == "pkcs11-tool" || Name == "cisco_cert_mgr" || Name == "vpnclient") + { + usleep(500); + CollectToolInfoProcess->kill(); + } + } + + //KMessageBox::information(0,QString("Name: "+Name+", Path: "+PathToExec+", Version: "+Version),"aaa"); + // disconnect( CollectToolInfoProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutCollectToolInfo() ) ); + // disconnect( CollectToolInfoProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrCollectToolInfo() ) ); + // delete CollectToolInfoProcess; + success=true; + } + } + + disconnect( CollectToolInfoProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutCollectToolInfo() ) ); + disconnect( CollectToolInfoProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrCollectToolInfo() ) ); + + delete CollectToolInfoProcess; + CollectToolInfoProcess=0L; + + //std::cout << "Name: " << Name << ", Path: " << PathToExec << ", Version: " << Version << std::endl; + + if (Name=="openvpn") + getOpenvpnCapabilities(); + } + else + { +// if (GlobalConfig->KvpncDebugLevel > 2) +// std::cout << QString(i18n("%1 not found.").arg(Name)).ascii() << std::endl; + } + return success; +} + +void ToolInfo::getOpenvpnCapabilities() +{ + + if (Name=="openvpn" && !PathToExec.isEmpty()) + { + + CollectOpenvpnCapabilitiesProcess = new QProcess(this); + CollectOpenvpnCapabilitiesProcess->clearArguments(); + connect( CollectOpenvpnCapabilitiesProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutCollectOpenvpnCapabilies() ) ); + connect( CollectOpenvpnCapabilitiesProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrCollectOpenvpnCapabilies() ) ); + connect( CollectOpenvpnCapabilitiesProcess, SIGNAL( processExited () ), this, SLOT(processFinished() ) ); + + //FIXME how it could be better? + CollectOpenvpnCapabilitiesProcess->addArgument(PathToExec); + if (Name == "vpnc") + CollectOpenvpnCapabilitiesProcess->addArgument("--help"); + + collectOpenvpnCapabilitiesRunning=false; + + if ( !PathToExec.isEmpty() && !CollectOpenvpnCapabilitiesProcess->start(env) ) + { + std::cerr << i18n("Unable to start collectToolInfo process (%1)!").arg(Name).ascii() << std::endl; + + //delete CollectToolInfoProcess; + collectOpenvpnCapabilitiesRunning=false; + } + else + { + collectOpenvpnCapabilitiesRunning=true; + while(CollectOpenvpnCapabilitiesProcess->isRunning() && collectOpenvpnCapabilitiesRunning) + { + // wait... + } + + //KMessageBox::information(0,QString("Name: "+Name+", Path: "+PathToExec+", Version: "+Version),"aaa"); + // disconnect( CollectOpenvpnCapabilitiesProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutCollectOpenvpnCapabilies() ) ); + // disconnect( CollectOpenvpnCapabilitiesProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrCollectOpenvpnCapabilies() ) ); + // delete CollectOpenvpnCapabilitiesProcess; + } + + disconnect( CollectOpenvpnCapabilitiesProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutCollectOpenvpnCapabilies() ) ); + disconnect( CollectOpenvpnCapabilitiesProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrCollectOpenvpnCapabilies() ) ); + + + //std::cout << "Name: " << Name << ", Path: " << PathToExec << ", Version: " << Version << std::endl; + } +} + +void ToolInfo::addSearchPath(const QString& path ) +{ + + // std::cout << "Path added: " << path << std::endl; + if (!path.isEmpty()) + SearchPathList.insert(SearchPathList.end(), QString(path)); + else + + return; +} + +void ToolInfo::removeSearchPath(const QString& path ) +{ + + // std::cout << "Path removed: " << path << std::endl; + if (!path.isEmpty()) + SearchPathList.remove(QString(path)); + else + + return; +} + + +/* == slots == */ +/** + * + */ +void ToolInfo::readStdOutCollectToolInfo () +{ + while (CollectToolInfoProcess->canReadLineStdout()) + { + QString msg = QString( CollectToolInfoProcess->readLineStdout() ); + // QString msg = QString( CollectToolInfoProcess->readStdout() ); + // std::cout << "Checking for: " << Name.ascii() << std::endl; + // std::cout << "stdout collectToolInfo: " << msg.ascii() < -1 ) + { +// std::cout << "stdout collectToolInfo: " << msg.ascii() << std::endl; +// std::cout << "stdout collectToolInfo: 2,2 " << msg.simplifyWhiteSpace().section(' ',2,2).ascii() << std::endl; + Version = msg.simplifyWhiteSpace().section(' ',2,2); + } + if ( msg.find( "Built without openssl (certificate) support.", 0, FALSE ) > -1 ) + { +// Capabilities+=i18n("no openssl support")+";"; + } + else if ( msg.find( "Built with openssl (certificate) support.", 0, FALSE ) > -1 ) + { + Capabilities=i18n("openssl (certificate) support")+";"; + } + } + else if (Name == "vpnclient" || Name =="cisco_cert_mgr") + { + if ( msg.find( "Cisco Systems VPN Client", 0, FALSE ) > -1 ) + Version = msg.section(' ',5,6); // "Cisco Systems VPN Client Version 4.8.00 (0490)" + } + else if (Name == "ipsec") + { + if ( msg.find( "wan", 0, FALSE ) > -1 ) + { + // std::cout << "stdout collectToolInfo: " << msg << std::endl; +// if ( msg.find( "openswan", 0, FALSE ) > -1 ) +// Version = msg.section(' ',2,2); +// else + Version = msg.section(' ',1,2); // "Openswan Ux.x.x/kx.x.x" + if (msg.section(' ',1,2).contains('/')) + Version = msg.section(' ',1,2).section('/',0,0); // "Openswan Ux.x.x" + else + Version = msg.section(' ',1,2); + } + } + else if (Name == "racoon" || Name == "racoonctl") + { + + // we need to do some stupid hack... + // /usr/sbin/racoon -> /usr/sbin/setkey + CollectToolInfoProcess->addArgument(QString(PathToExec.left(PathToExec.length()-6)+"setkey")); + if ( msg.find( "ipsec-tools", 0, FALSE ) > -1 ) + { + //std::cout << "stdout collectToolInfo: " << msg << std::endl; + Version = msg.section(' ',3,3); + } + } + else if (Name == "setkey") + { + if ( msg.find( "ipsec-tools", 0, FALSE ) > -1 ) + { + //std::cout << "stdout collectToolInfo: " << msg << std::endl; + Version = msg.section(' ',3,3); + } + } + else if (Name == "openvpn") + { + if ( msg.find( "built", 0, FALSE ) > -1 ) + { + //std::cout << "stdout collectToolInfo: " << msg << std::endl; + Version = msg.section(' ',1,1); + } + } + else if (Name == "openssl") + { + if ( msg.find( "OpenSSL", 0, FALSE ) > -1 ) + { + //std::cout << "stdout collectToolInfo: " << msg << std::endl; + Version = msg.section(' ',1,1); + } + } + else if (Name == "pppd") + { + if ( msg.find( "version", 0, FALSE ) > -1 ) + { + //std::cout << "stdout collectToolInfo: " << msg << std::endl; + Version = msg.section(' ',2,2); + } + } + else if (Name == "iptables") + { + if ( msg.find( "iptables", 0, FALSE ) > -1 ) + { + //std::cout << "stdout collectToolInfo: " << msg << std::endl; + Version = msg.section(' ',1,1); + } + } + else if (Name == "ping") + { + if ( msg.find( "ping", 0, FALSE ) > -1 ) + { + //std::cout << "stdout collectToolInfo: " << msg << std::endl; + Version = msg.section(' ',2,2); + } + } + else if (Name == "ip") + { + if ( msg.find( "ip", 0, FALSE ) > -1 ) + { + //std::cout << "stdout collectToolInfo: " << msg << std::endl; + Version = msg.section(' ',2,2); + } + } + else if (Name == "kill") + { + if ( msg.find( "kill", 0, FALSE ) > -1 ) + { + //std::cout << "stdout collectToolInfo: " << msg << std::endl; + Version = msg.section(' ',3,3).section(')',0,0); + } + } + else if (Name == "pkcs11-tool") + { + if ( msg.find( "version", 0, FALSE ) > -1 ) + { + //std::cout << "stdout collectToolInfo: " << msg << std::endl; + Version = msg.section(' ',2,2); + } + else if ( msg.find( "Error: can't open /var/run/openct/status", 0, FALSE ) > -1 ) + { + std::cerr << "stdout collectToolInfo (pkcs11): " << msg.ascii() << std::endl; + CollectToolInfoProcess->kill(); + } + } + else if (Name == "xl2tpd") + { + if ( msg.find( "version:", 0, FALSE ) > -1 ) + { +// std::cout << "stdout collectToolInfo: " << msg << std::endl; + Version = msg.section(' ',3,3).stripWhiteSpace(); + } + } + else if (Name == "openl2tpd") + { + if ( msg.find( "OpenL2TP V", 0, FALSE ) > -1 ) + { + //std::cout << "stdout collectToolInfo: " << msg << std::endl; + Version = msg.section(' ',1,1).remove(',').remove('V'); + std::cerr << "stdout collectToolInfo (openl2tpd): " << msg.ascii() << std::endl; + CollectToolInfoProcess->kill(); + } + } + else if (Name == "vtund") + { + if ( msg.find( "VTun ver", 0, FALSE ) > -1 ) + { +// std::cout << "stdout collectToolInfo: " << msg << std::endl; + Version = msg.section(' ',2,3).stripWhiteSpace(); + } + } + else if (Name == "tail") + { + if ( msg.find( "tail ", 0, FALSE ) > -1 ) + { +// std::cout << "stdout collectToolInfo: " << msg << std::endl; + Version = msg.section(' ',3,3).stripWhiteSpace(); + } + } + else if (Name == "ksshaskpass") + { + if ( msg.find( "Ksshaskpass:", 0, FALSE ) > -1 ) + { +// std::cout << "stdout collectToolInfo: " << msg << std::endl; + Version = msg.section(' ',1,1).stripWhiteSpace(); + } + } + else if (Name == "gnome-ssh-askpass") + { +// if ( msg.find( "askpass", 0, FALSE ) > -1 ) + { +// std::cout << "stdout collectToolInfo: " << msg << std::endl; +// Version = msg.section(' ',3,3).stripWhiteSpace(); + Version=i18n("unknown"); + } + } + else if (Name == "netstat") + { + if ( msg.find( "netstat ", 0, FALSE ) > -1 ) + { +// std::cout << "stdout collectToolInfo: " << msg << std::endl; + Version = msg.section(' ',1,1).stripWhiteSpace(); + } + } + else + { +// KMessageBox::information(0,QString("Name: "+Name+", Path: "+PathToExec+", Version: "+Version+", err: "+msg),"aaa"); + } + } + collectRunning=false; +} + +void ToolInfo::readStdErrCollectToolInfo() +{ + while (CollectToolInfoProcess->canReadLineStderr()) + { + QString msg = QString( CollectToolInfoProcess->readLineStderr() ); +// if (GlobalConfig->KvpncDebugLevel > 2) +// { +// std::cout << "Checking for: " << Name.ascii() << std::endl; +// std::cout << "stderr collectToolInfo: " << msg.ascii() < -1 ) + { + //std::cout << "stdout collectToolInfo: " << msg << std::endl; + Version = msg.section(' ',2,2); + } + } + else if (Name == "killall") + { + if ( msg.find( "killall", 0, FALSE ) > -1 ) + { + //std::cout << "stdout collectToolInfo: " << msg << std::endl; + Version = msg.section(' ',2,2); + } + } + else if (Name == "ifconfig") + { + //KMessageBox::information(0,QString("Name: "+Name+", Path: "+PathToExec+", Version: "+Version),"aaa"); + if ( msg.find( "ifconfig", 0, FALSE ) > -1 ) + { + //std::cout << "stdout collectToolInfo: " << msg << std::endl; + Version = msg.section(' ',1,1); + } + } + else if (Name == "route") + { + if ( msg.find( "route", 0, FALSE ) > -1 ) + { + //std::cout << "stdout collectToolInfo: " << msg << std::endl; + Version = msg.section(' ',1,1); + } + } + else if (Name == "pptp") + { + if ( msg.find( "pptp version", 0, FALSE ) > -1 ) + { + // std::cout << "stdout collectToolInfo: " << msg.ascii() << std::endl; + Version = msg.section(' ',2,2).section(')',0,0); + } + } + else if (Name == "l2tpd") + { + if ( msg.find( "l2tpd", 0, FALSE ) > -1 ) + { + //std::cout << "stdout collectToolInfo: " << msg << std::endl; + Version = msg.section(' ',2,2).section(')',0,0); + } + } + else if (Name == "pkcs11-tool") + { + if ( msg.find( "version", 0, FALSE ) > -1 ) + { +// std::cout << "stdout collectToolInfo (pkcs11): " << msg.ascii() << std::endl; + Version = msg.section(' ',2,2); + } + else if ( msg.find( "Error: can't open /var/run/openct/status", 0, FALSE ) > -1 ) + { +// std::cout << "stdout collectToolInfo (pkcs11): " << msg.ascii() << std::endl; + CollectToolInfoProcess->kill(); + } + } + else if (Name == "ssh") + { + if ( msg.find( "OpenSSH", 0, FALSE ) > -1 ) + { +// std::cout << "stdout collectToolInfo: " << msg << std::endl; + Version = msg.section(' ',0,0).section('_',1,1).stripWhiteSpace(); + } + } + else + { +// KMessageBox::information(0,QString("Name: "+Name+", Path: "+PathToExec+", Version: "+Version+", err: "+msg),"aaa"); + } + } +} + +void ToolInfo::readStdOutCollectOpenvpnCapabilies() +{ + while (CollectOpenvpnCapabilitiesProcess->canReadLineStdout()) + { + QString msg = QString( CollectOpenvpnCapabilitiesProcess->readLineStdout() ); + // QString msg = QString( CollectOpenvpnCapabilitiesProcess->readStdout() ); + // std::cout << "stdout collectOpenvpnCapabilities: " << msg.ascii() < -1 ) + Capabilities+=i18n("pkcs11 support")+";"; + + } + collectOpenvpnCapabilitiesRunning=false; +} + +void ToolInfo::readStdErrCollectOpenvpnCapabilies() +{ + while (CollectOpenvpnCapabilitiesProcess->canReadLineStderr()) + { + QString msg = QString( CollectOpenvpnCapabilitiesProcess->readLineStderr() ); + // std::cout << "stderr collectOpenvpnCapabilities: " << msg.ascii() < +#include +#include +#include + +class ToolInfo : public QObject +{ + Q_OBJECT +public: + /** + * Information about a helper program + * @param GlobalConfig Pointer to global config + * @param Name Name of the tool + * @return None + */ + ToolInfo(const QString &Name); + +private: + QProcess *CollectToolInfoProcess; + QProcess *CollectOpenvpnCapabilitiesProcess; + QStringList SearchPathList; + bool collectRunning; + bool collectOpenvpnCapabilitiesRunning; + QStringList *env; + +public: + QString Name; //< Name of the tool + QString Version; //< Version number of the tool + QString PathToExec; //< Path to executable + QString Capabilities; + QString TryPath_first; //< try that path first before list + bool collectToolInfo(); //< Collects information of the tool + bool programsInPath; + bool found; + void addSearchPath(const QString &path); //< Adds a path for searching + void removeSearchPath(const QString &path); //< Removes a path for searching + void getOpenvpnCapabilities(); + + +private slots: + void readStdOutCollectToolInfo(); + void readStdErrCollectToolInfo(); + void readStdOutCollectOpenvpnCapabilies(); + void readStdErrCollectOpenvpnCapabilies(); + void processFinished(); + +}; + + +#endif diff --git a/src/toolsinfodialog.cpp b/src/toolsinfodialog.cpp new file mode 100644 index 0000000..26e8041 --- /dev/null +++ b/src/toolsinfodialog.cpp @@ -0,0 +1,527 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +//BEGIN INCLUDES +#include "toolsinfodialog.h" +#include "listviewtooltip.h" +#include +//#include +#include +#include +#include +#include +#include +#include +#include + +#include "utils.h" +//END INCLUDES + +ToolsInfoDialog::ToolsInfoDialog(KVpncConfig *GlobalConfig, QWidget *parent, const char *) + :KDialogBase( parent, "Tool_information", true, "", + KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, true ) +{ + main = new ToolsInfoWidgetBase(this); + setMainWidget(main); + main->InfoListView->setMinimumSize(main->InfoListView->sizeHint()); + + QPixmap ok_icon = KGlobal::iconLoader()->loadIcon( "button_ok", KIcon::NoGroup, 16 ); + QPixmap wrong_icon = KGlobal::iconLoader()->loadIcon( "button_cancel", KIcon::NoGroup, 16 ); + ToolInfo *tool=0; + main->InfoListView->setSorting(1); + + GlobalConfig->appPointer->setOverrideCursor( QCursor(Qt::WaitCursor) ); + + for ( tool = GlobalConfig->ToolList->first(); tool; tool = GlobalConfig->ToolList->next() ) + { +// std::cout << "tool: " << tool->Name.ascii() << std::endl; + // std::cout << "Version: " << tool->Version << std::endl; + // std::cout << "Path: " << tool->PathToExec << std::endl << std::endl; + QString state=""; + QString usability=""; + QString requiredBy=""; + QString comment=""; + + tool->programsInPath = GlobalConfig->programsInPath; + +// tool->collectToolInfo(); + + if (!tool->PathToExec.isEmpty() && QFile (tool->PathToExec).exists() && QFileInfo(tool->PathToExec).isFile() ) + { +// state=i18n("Found"); + if (tool->Name == "vpnc") + { + // FIXME use major/minor/subminor version + if ( tool->Version.find("0.3.",0,-1) > -1 || tool->Version.find("0.4.",0,-1) > -1) + { + usability=i18n("good"); + comment=i18n("no certificate support"); + } + if ( tool->Version.find("0.5.",0,-1) > -1 ) + { + usability=i18n("good"); + if( tool->Capabilities.find(i18n("openssl (certificate) support"),0,-1) > -1) + comment=i18n("hybrid support"); + else + comment=i18n("no certificate support"); + } + else if ( tool->Version.find("0.3.2",0,-1) > -1) + { + usability=i18n("limited"); + comment=i18n("no split DNS support"); + } + else if ( tool->Version.find("0.2.",0,-1) > -1) + { + usability=i18n("basic"); + comment=i18n("no NAT-T, IPSec over IP, no split DNS support"); + } + + } + else if (tool->Name == "ciscovpnc") + { + usability=i18n("full"); + } + else if (tool->Name == "ipsec") + { + // version is like this: "Openswan U2.4.4/K2.6.15" or "strongSwan U2.4.4/K2.6.15" + QString realversion=tool->Version.section(' ',1,1).section('/',0,0).right(tool->Version.section(' ',1,1).section('/',0,0).length()-1); + int majorversion = realversion.section('.',0,0).toInt(); + int minorversion = realversion.section('.',1,1).toInt(); + int subminorversion = realversion.section('.',2,2).toInt(); + QString realtype=tool->Version.section(' ',0,0).lower(); + + if ( tool->Version.contains("Openswan")) + { + comment="Openswan"; + comment+=", "+i18n("kernel %1 support").arg("2.6"); + comment+=", "+i18n("smartcard support"); + } + else if ( tool->Version.contains("strongSwan")) + { + comment="strongSwan"; + comment+=", "+i18n("no aggressive mode"); + comment+=", "+i18n("kernel %1 support").arg("2.4"); + if (!(majorversion <= 2 && minorversion <= 8 && subminorversion <= 1)) + comment+=", "+i18n("kernel %1 support").arg("2.6"); + comment+=", "+i18n("smartcard support"); + } + else + { + comment+="FreeS/WAN"; + } + + if ( realversion.find("2.",0,-1) > -1) + usability=i18n("full"); + else if ( realversion.find("1.",0,-1) > -1) + { + usability=i18n("limited"); + comment=+", "+i18n("no aggressive mode"); + } + else + usability=i18n("unknown"); + + } + else if (tool->Name == "racoon") + { + //if ( tool->Version.find("2.",0,-1) > -1) + usability=i18n("full"); + //else if ( tool->Version.find("2.",0,-1) > -1) + // usability=i18n("limited"); + } + else if (tool->Name == "openvpn") + { + if ( tool->Version.find("2.",0,-1) > -1) + { + usability=i18n("full"); +// int major=tool->Version.section('.',0,0).toInt(); +// int minor=tool->Version.section('.',1,1).toInt(); +// int subminor=tool->Version.section('.',2,2).toInt(); + +// if ( major >= 2 && minor >= 1) + if (tool->Capabilities.find( i18n("pkcs11 support"), 0, FALSE ) > -1 ) + { + if (!comment.isEmpty()) + comment+=", "; + comment+=i18n("smartcard support"); + } + } + else if ( tool->Version.find("1.",0,-1) > -1) + //else + usability=i18n("limited"); + } + else if (tool->Name == "pppd") + { + //if ( tool->Version.find("2.",0,-1) > -1) + usability=i18n("full"); + //else if ( tool->Version.find("2.",0,-1) > -1) + // usability=i18n("limited"); + + Utils::PppdCapabilities pppdcap = Utils ( GlobalConfig ).checkPppdCapabilities(); + comment=""; + if (pppdcap.pppdHasMppeRequiredSupport==true) + { + if (!comment.isEmpty()) + comment+=","; + comment+= "mppe required"; + } + if (pppdcap.pppdHasRequireMppeSupport==true) + { + if (!comment.isEmpty()) + comment+=","; + comment+= "require-mppe"; + } + if (pppdcap.pppdHasReplacedefaultrouteSupport==true) + { + if (!comment.isEmpty()) + comment+=","; + comment+="replacedefaultroute"; + } + if (pppdcap.pppdHasMppeSupport==true) + { + if (!comment.isEmpty()) + comment+=","; + comment+= "mppe support"; + } + } + else if (tool->Name == "pptp") + { + //if ( tool->Version.find("2.",0,-1) > -1) + usability=i18n("full"); + //else if ( tool->Version.find("2.",0,-1) > -1) + // usability=i18n("limited"); + } + else if (tool->Name == "vtund") + { + //if ( tool->Version.find("2.",0,-1) > -1) + usability=i18n("full"); + //else if ( tool->Version.find("2.",0,-1) > -1) + // usability=i18n("limited"); + } + else if (tool->Name == "ping") + { + //if ( tool->Version.find("2.",0,-1) > -1) + usability=i18n("full"); + //else if ( tool->Version.find("2.",0,-1) > -1) + // usability=i18n("limited"); + } + else if (tool->Name == "pkcs11-tool") + { + //if ( tool->Version.find("2.",0,-1) > -1) + usability=i18n("full"); + //else if ( tool->Version.find("2.",0,-1) > -1) + // usability=i18n("limited"); + } + else if (tool->Name == "cisco_cert_mgr") + { + //if ( tool->Version.find("2.",0,-1) > -1) + usability=i18n("full"); + //else if ( tool->Version.find("2.",0,-1) > -1) + // usability=i18n("limited"); + requiredBy=i18n("Cisco (propritary)"); + } + else if (tool->Name == "kill") + { + //if ( tool->Version.find("2.",0,-1) > -1) + usability=i18n("full"); + //else if ( tool->Version.find("2.",0,-1) > -1) + // usability=i18n("limited"); + } + else if (tool->Name == "ip") + { + //if ( tool->Version.find("2.",0,-1) > -1) + usability=i18n("full"); + //else if ( tool->Version.find("2.",0,-1) > -1) + // usability=i18n("limited"); + } + else if (tool->Name == "ifconfig") + { + //if ( tool->Version.find("2.",0,-1) > -1) + usability=i18n("full"); + //else if ( tool->Version.find("2.",0,-1) > -1) + // usability=i18n("limited"); + } + else if (tool->Name == "route") + { + //if ( tool->Version.find("2.",0,-1) > -1) + usability=i18n("full"); + //else if ( tool->Version.find("2.",0,-1) > -1) + // usability=i18n("limited"); + } + else if (tool->Name == "bash") + { + //if ( tool->Version.find("2.",0,-1) > -1) + usability=i18n("full"); + //else if ( tool->Version.find("2.",0,-1) > -1) + // usability=i18n("limited"); + } + else if (tool->Name == "iptables") + { + //if ( tool->Version.find("2.",0,-1) > -1) + usability=i18n("full"); + //else if ( tool->Version.find("2.",0,-1) > -1) + // usability=i18n("limited"); + } + else if (tool->Name == "killall") + { + //if ( tool->Version.find("2.",0,-1) > -1) + usability=i18n("full"); + //else if ( tool->Version.find("2.",0,-1) > -1) + // usability=i18n("limited"); + } + else if (tool->Name == "openssl") + { + //if ( tool->Version.find("2.",0,-1) > -1) + usability=i18n("full"); + //else if ( tool->Version.find("2.",0,-1) > -1) + // usability=i18n("limited"); + } + else if (tool->Name == "setkey") + { + //if ( tool->Version.find("2.",0,-1) > -1) + usability=i18n("full"); + //else if ( tool->Version.find("2.",0,-1) > -1) + // usability=i18n("limited"); + } + else if (tool->Name == "vpnclient") + { + //if ( tool->Version.find("2.",0,-1) > -1) + usability=i18n("full"); + //else if ( tool->Version.find("2.",0,-1) > -1) + // usability=i18n("limited"); + } + else if (tool->Name == "l2tpd") + { + //if ( tool->Version.find("2.",0,-1) > -1) +// usability=i18n("full"); + //else if ( tool->Version.find("2.",0,-1) > -1) + // usability=i18n("limited"); + } + else if (tool->Name == "xl2tpd") + { + //if ( tool->Version.find("2.",0,-1) > -1) +// usability=i18n("full"); + //else if ( tool->Version.find("2.",0,-1) > -1) + // usability=i18n("limited"); + } + else if (tool->Name == "openl2tp") + { + //if ( tool->Version.find("2.",0,-1) > -1) +// usability=i18n("full"); + //else if ( tool->Version.find("2.",0,-1) > -1) + // usability=i18n("limited"); + } + else if (tool->Name == "tail") + { +// comment+=", "+i18n("kernel %1 support").arg("2.6"); + } + else if (tool->Name == "ssh") + { + int major=tool->Version.section('.',0,0).toInt(); + int minor=tool->Version.section('.',1,1).section('p',0,0).toInt(); +// std::cout << "ssh version: major: " << QString().setNum(major).ascii() << " minor: " << QString().setNum(minor).ascii() << std::endl; + if ( major > 4 || ( major == 4 && minor >= 3) ) + { + usability=i18n("full"); + } + else + { + if ( major < 4 ) + //else + usability=i18n("unuseable"); + comment=+i18n("no vpn support"); + } + } + + else + { + // other tools + usability=i18n("full"); + } + + } + else + { +// state=i18n("Not found"); + usability=i18n("none"); + } + +// state=i18n("Found"); + if (tool->Name == "vpnc") + { + requiredBy=i18n("Cisco (free)"); + } + else if (tool->Name == "ciscovpnc") + { + requiredBy=i18n("Cisco (propritary)"); + } + else if (tool->Name == "ipsec") + { + QString realversion=tool->Version.section(' ',1,1).section('/',0,0).right(tool->Version.section(' ',1,1).section('/',0,0).length()-1); + QString realtype=tool->Version.section(' ',0,0).lower(); + + if ( tool->Version.contains("Openswan")) + { + requiredBy=i18n("Openswan"); + } + else if ( tool->Version.contains("strongSwan")) + { + requiredBy=i18n("strongSwan"); + } + else + { + requiredBy=i18n("FreeS/WAN"); + } + + } + +// std::cout << "Tool: " << tool->Name.ascii() << " Path: "<< tool->PathToExec.ascii() << " Version: " << tool->Version.ascii() << " Found: " << state.ascii() << std::endl; + + else if (tool->Name == "racoon") + { + requiredBy=i18n("ipsec-tools (racoon)"); + } + else if (tool->Name == "openvpn") + { + requiredBy=i18n("OpenVPN"); + } + else if (tool->Name == "pppd") + { + requiredBy=i18n("PPTP"); + } + else if (tool->Name == "pptp") + { + requiredBy=i18n("PPTP"); + } + else if (tool->Name == "vtund") + { + requiredBy=i18n("VTun"); + } + else if (tool->Name == "ping") + { + requiredBy=i18n("KVpnc"); + } + else if (tool->Name == "pkcs11-tool") + { + requiredBy=i18n("Smartcard support"); + } + + else if (tool->Name == "cisco_cert_mgr") + { + requiredBy=i18n("Cisco (propritary)"); + } + + else if (tool->Name == "kill") + { + requiredBy=i18n("KVpnc"); + } + else if (tool->Name == "ip") + { + requiredBy=i18n("KVpnc"); + } + else if (tool->Name == "ifconfig") + { + requiredBy=i18n("KVpnc"); + } + else if (tool->Name == "route") + { + requiredBy=i18n("KVpnc"); + } + else if (tool->Name == "bash") + { + requiredBy=i18n("KVpnc"); + } + else if (tool->Name == "iptables") + { + requiredBy=i18n("KVpnc"); + } + else if (tool->Name == "killall") + { + requiredBy=i18n("KVpnc"); + } + else if (tool->Name == "openssl") + { + requiredBy=i18n("Certificate support"); + } + else if (tool->Name == "setkey") + { + requiredBy=i18n("ipsec-tools (racoon)"); + } + else if (tool->Name == "vpnclient") + { + requiredBy=i18n("Cisco (propritary)"); + } + else if (tool->Name == "l2tpd") + { + requiredBy=i18n("L2TP"); + } + else if (tool->Name == "xl2tpd") + { + requiredBy=i18n("L2TP"); + } + else if (tool->Name == "openl2tpd") + { + requiredBy=i18n("L2TP"); + } + else if (tool->Name == "tail") + { + requiredBy=i18n("ipsec (Openswan, strongSwan, racoon)"); + } + else if (tool->Name == "ssh") + { + requiredBy=i18n("SSH VPN"); + } + else if (tool->Name == "ksshaskpass") + { + requiredBy=i18n("SSH VPN"); + } + else if (tool->Name == "gnome-ssh-askpass") + { + requiredBy=i18n("SSH VPN"); + } + else if (tool->Name == "netstat") + { + requiredBy = i18n("ipsec (Openswan, strongSwan, racoon)"); + } + else + { + // other tools + } + + + + QListViewItem *item = new QListViewItem(main->InfoListView, tool->Name,state, tool->Version, usability,requiredBy , tool->PathToExec, comment); + if (tool->found) + item->setPixmap(1,ok_icon); + else + item->setPixmap(1,wrong_icon); + main->InfoListView->insertItem(item); + + } + + QToolTip::remove( main->InfoListView ); + new ListViewToolTip( main->InfoListView ); + + this->resize(800,600); + main->InfoListView->resize(main->InfoListView->sizeHint()); + main->resize(main->sizeHint()); + //this->resize(sizeHint()); + + GlobalConfig->appPointer->restoreOverrideCursor(); +} + diff --git a/src/toolsinfodialog.h b/src/toolsinfodialog.h new file mode 100644 index 0000000..29dd3d5 --- /dev/null +++ b/src/toolsinfodialog.h @@ -0,0 +1,37 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef TOOLSINFODIALOG_H +#define TOOLSINFODIALOG_H + +#include "toolsinfowidgetbase.h" +#include +#include +#include "kvpnc.h" +#include "kvpncconfig.h" + +class ToolsInfoDialog: public KDialogBase +{ +public: + ToolsInfoDialog(KVpncConfig *GlobalConfig, QWidget *parent = 0, const char *name = 0); + ToolsInfoWidgetBase *main; + +}; + +#endif diff --git a/src/toolsinfowidgetbase.ui b/src/toolsinfowidgetbase.ui new file mode 100644 index 0000000..218279c --- /dev/null +++ b/src/toolsinfowidgetbase.ui @@ -0,0 +1,141 @@ + +ToolsInfoWidgetBase + + + ToolsInfoWidgetBase + + + + 0 + 0 + 942 + 346 + + + + Tools Information + + + + unnamed + + + + textLabel1 + + + The following information about the tools has been collected: + + + + + + Tool + + + true + + + true + + + + + State + + + true + + + true + + + + + Version + + + true + + + true + + + + + Usability + + + true + + + true + + + + + required by + + + true + + + true + + + + + Path + + + true + + + true + + + + + Comment + + + true + + + true + + + + InfoListView + + + + 7 + 3 + 0 + 0 + + + + + 600 + 300 + + + + AutoOneFit + + + true + + + false + + + + + + + klistview.h + + diff --git a/src/utils.cpp b/src/utils.cpp new file mode 100644 index 0000000..144422d --- /dev/null +++ b/src/utils.cpp @@ -0,0 +1,1912 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +//BEGIN INCLUDES +#include "utils.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // name resolving +#include +#include +#include + +//END INCLUDES + +Utils::Utils( KVpncConfig* config, QObject *parent, const char *name ) + : QObject( parent, name ) +{ + env = new QStringList(); + *env << "LC_ALL=C" << "LANG=C" << "PATH=/bin:/usr/bin:/usr/sbin:/sbin"; + this->config = config; + retrieveValidNetworkdevice = false; +} + +Utils::~Utils() +{ + // if(createProcess!=0) + // delete createProcess; + // + // if (NetworkDeviceTestProcess!=0) + // delete NetworkDeviceTestProcess; +} + +bool Utils::isValidIPv4Address( QString Address ) +{ + if ( Address.contains( '.' ) != 3 ) + return false; + else + { + //std::cout << "test1 succeed.\n"; + QString addr = Address; + int part0 = addr.section( '.', 0, 0 ).toInt(); + int part1 = addr.section( '.', 1, 1 ).toInt(); + int part2 = addr.section( '.', 2, 2 ).toInt(); + int part3 = addr.section( '.', 3, 3 ).toInt(); + + //std::cout << "part0 " << part0 << ", part1 " << part1 << ", part2 " << part2 << ", part3 " << part3 << "\n"; + + if ( ( part0 > 1 && part0 < 255 ) && + ( part1 >= 0 && part1 < 255 ) && + ( part2 >= 0 && part2 < 255 ) && + ( part3 >= 0 && part3 < 255 ) ) + return true; + else + return false; + } +} + +bool Utils::isValidIPv4NetworkAddress( QString Address ) +{ + if ( isValidIPv4Address ( Address ) ) + { + if ( Address.section( '.', 3, 3 ).toInt() == 0 ) + return true; + else + return false; + } + else + return false; +} + +bool Utils::isValidIPv4BroadcastAddress( QString Address ) +{ + if ( isValidIPv4Address ( Address ) ) + { + if ( Address.section( '.', 3, 3 ).toInt() == 255 ) + return true; + else + return false; + } + else + return false; + return false; +} + +bool Utils::isValidIPv4Netmask(QString Netmask) +{ + if ( Netmask.contains( '.' ) != 3 ) + return false; + else + { + //std::cout << "test1 succeed.\n"; + QString addr = Netmask; + int part0 = addr.section( '.', 0, 0 ).toInt(); + int part1 = addr.section( '.', 1, 1 ).toInt(); + int part2 = addr.section( '.', 2, 2 ).toInt(); + int part3 = addr.section( '.', 3, 3 ).toInt(); + + //std::cout << "part0 " << part0 << ", part1 " << part1 << ", part2 " << part2 << ", part3 " << part3 << "\n"; + + if ( ( part0 > 254 && part0 <= 255 ) && + ( part1 > 254 && part1 <= 255 ) && + ( part2 >= 0 && part2 <= 255 ) && + ( part3 >= 0 && part3 <= 253 ) ) + return true; + else + return false; + } +} + +bool Utils::tunDevExists() +{ + if ( QFile ( "/dev/net/tun" ).exists() ) + return true; + else + return false; +} + +bool Utils::createTunDev() +{ + createProcess = new QProcess( this ); + connect( createProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutCreateTunDev() ) ); + connect( createProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrCreateTunDev() ) ); + + // step one: create directory + if ( !QDir ( "/dev/net" ).exists() ) + { + createProcess->addArgument("mkdir") ; + //createProcess->addArgument("-p"); + createProcess->addArgument( "/dev/net" ); + + + if ( !createProcess->start(env) ) { + disconnect( createProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutCreateTunDev() ) ); + disconnect( createProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrCreateTunDev() ) ); + delete createProcess; + createProcess=0L; + kdError() << "Unable to create tunnel device file!" << endl; + return false; + } + else + { + // while(createProcess->isRunning()) + // { }; + sleep ( 2 ); + } + } + + // step two: create device node + createProcess->clearArguments(); + createProcess->addArgument( "/bin/mknod" ); + createProcess->addArgument( "/dev/net/tun" ); + createProcess->addArgument( "c" ); + createProcess->addArgument( "10" ); + createProcess->addArgument( "200" ); + + if ( !createProcess->start(env) ) + { + disconnect( createProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutCreateTunDev() ) ); + disconnect( createProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrCreateTunDev() ) ); + delete createProcess; + createProcess = 0L; + kdError() << "Unable to create tunnel device file!" << endl; + return false; + } + else + { + while ( createProcess->isRunning() ) + { + sleep ( 1 ); + } + disconnect( createProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutCreateTunDev() ) ); + disconnect( createProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrCreateTunDev() ) ); + delete createProcess; + createProcess = 0L; + return true; + } + return false; +} + +bool Utils::loadKernelModule( QString Name, QApplication *app ) +{ + if ( !Name.isEmpty() ) + { + modprobeSuccess = true; + ModprobeProcess = new QProcess( this ); + ModprobeProcess->addArgument( "/sbin/modprobe" ); + ModprobeProcess->addArgument( Name ); + + connect( ModprobeProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutLoadKernelModule() ) ); + connect( ModprobeProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrLoadKernelModule() ) ); + if ( !ModprobeProcess->start( env ) ) { + disconnect( ModprobeProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutLoadKernelModule() ) ); + disconnect( ModprobeProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrLoadKernelModule() ) ); + delete ModprobeProcess; + ModprobeProcess = 0L; + return modprobeSuccess; + kdError() << "Unable to start kernel module loading process!" << endl; + return false; + } + else + { + while ( ModprobeProcess && ModprobeProcess->isRunning() ) + { + if (config->appPointer->hasPendingEvents()) + config->appPointer->processEvents(); + usleep(250); + } + disconnect( ModprobeProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutLoadKernelModule() ) ); + disconnect( ModprobeProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrLoadKernelModule() ) ); + delete ModprobeProcess; + ModprobeProcess = 0L; + return modprobeSuccess; + } + + } + else + return false; +} + +bool Utils::unloadKernelModule( QString Name, QApplication *app , bool force) +{ + if ( !Name.isEmpty() ) + { + modprobeSuccess = true; + ModprobeProcess = new QProcess( this ); + ModprobeProcess->addArgument( "/sbin/rmmod" ); + + if (force == true) + ModprobeProcess->addArgument( "-f" ); + + ModprobeProcess->addArgument( Name ); + + connect( ModprobeProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutLoadKernelModule() ) ); + connect( ModprobeProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrLoadKernelModule() ) ); + if ( !ModprobeProcess->start( env ) ) { + disconnect( ModprobeProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutLoadKernelModule() ) ); + disconnect( ModprobeProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrLoadKernelModule() ) ); + delete ModprobeProcess; + ModprobeProcess = 0L; + return modprobeSuccess; + kdError() << "Unable to start kernel module loading process!" << endl; + return false; + } + else + { + while ( ModprobeProcess->isRunning() ) + { + if (config->appPointer->hasPendingEvents()) + config->appPointer->processEvents(); + usleep(250); + } + disconnect( ModprobeProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutLoadKernelModule() ) ); + disconnect( ModprobeProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrLoadKernelModule() ) ); + delete ModprobeProcess; + ModprobeProcess = 0L; + return modprobeSuccess; + } + + } + else + return false; +} + +bool Utils::doChmod( QString file, QString mode ) +{ + config->appendLogEntry ( i18n( "\"%1\" begin." ).arg("chmod"),config->info ); + KProcess *chmodProcess = new KProcess; + *chmodProcess << "/bin/chmod"; + *chmodProcess << mode; + *chmodProcess << file; + + if ( !chmodProcess->start() ) + { + // KMessageBox::sorry( this, i18n( "\"%1\" start failed!" ).arg( "PppdUpScript" ) ); + config->appendLogEntry( i18n( "Chmod of %1 failed!" ).arg( file ), config->error ); + delete chmodProcess; + return false; + } + else + { + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n( "chmod of %1 (%2) started." ).arg( file ).arg( mode ) , config->debug ); + int max_count = 9; + int count=0; + while ( count < max_count && chmodProcess->isRunning() ) + { + if ( config->KvpncDebugLevel > 6 ) + config->appendLogEntry ( i18n( "chmod of %1 (%2) running." ).arg( file ).arg( mode ) , config->debug ); + usleep ( 250 ); + if ( config->appPointer->hasPendingEvents () ) + config->appPointer->processEvents(); + count++; + } + config->appendLogEntry ( i18n( "\"%1\" finished." ).arg("chmod"),config->info ); + delete chmodProcess; + return true; + } +} + +bool Utils::resolvConfAvailable() +{ + bool resolvConfAvailable=false; + if (QFile("/sbin/resolvconf").exists() && QFile("/etc/init.d/resolvconf").exists()) + resolvConfAvailable=true; + else + resolvConfAvailable=false; + return resolvConfAvailable; +} + +QPtrList* Utils::getToolList() +{ + QPtrList *ToolList = new QPtrList(); + + //TODO move to KVpncConfig + QStringList *ToolNamesList = new QStringList(); + ToolNamesList->append( "vpnc" ); + ToolNamesList->append( "vpnclient" ); + ToolNamesList->append( "racoon" ); + ToolNamesList->append( "racoonctl" ); + ToolNamesList->append( "ipsec" ); // freeswan + ToolNamesList->append( "pppd" ); + ToolNamesList->append( "pptp" ); + ToolNamesList->append( "l2tpd" ); + ToolNamesList->append( "xl2tpd" ); + ToolNamesList->append( "openl2tpd" ); + ToolNamesList->append( "setkey" ); + ToolNamesList->append( "iptables" ); + ToolNamesList->append( "openssl" ); + ToolNamesList->append( "openvpn" ); + ToolNamesList->append( "kill" ); + ToolNamesList->append( "killall" ); + ToolNamesList->append( "ping" ); + ToolNamesList->append( "ip" ); + ToolNamesList->append( "ifconfig" ); + ToolNamesList->append( "route" ); + ToolNamesList->append( "pkcs11-tool" ); + ToolNamesList->append( "bash" ); + ToolNamesList->append( "vtund" ); + ToolNamesList->append( "cisco_cert_mgr" ); + ToolNamesList->append( "tail" ); + ToolNamesList->append( "ssh" ); + ToolNamesList->append( "ksshaskpass" ); + ToolNamesList->append( "gnome-ssh-askpass" ); + ToolNamesList->append( "racoonctl" ); + ToolNamesList->append( "netstat" ); + + ToolInfo *currentTool; + for ( QStringList::Iterator it = ToolNamesList->begin(); it != ToolNamesList->end(); it++ ) { + //std::cout << "tool: " << *it << std::endl; + + currentTool = new ToolInfo( *it ); + currentTool->programsInPath =config->programsInPath; + if ( currentTool->Name == "vpnc" ) + currentTool->TryPath_first = config->pathToVpnc; + else if (currentTool->Name == "vpnclient") + currentTool->TryPath_first = config->pathToCiscoVpnc; + else if ( currentTool->Name == "ipsec" ) + currentTool->TryPath_first = config->pathToIpsec; + else if ( currentTool->Name == "racoon" ) + currentTool->TryPath_first = config->pathToRacoon; + else if ( currentTool->Name == "racoonctl" ) + currentTool->TryPath_first = config->pathToRacoonctl; + else if ( currentTool->Name == "setkey" ) + currentTool->TryPath_first = config->pathToSetkey; + else if ( currentTool->Name == "openvpn" ) + currentTool->TryPath_first = config->pathToOpenvpn; + else if ( currentTool->Name == "openssl" ) + currentTool->TryPath_first = config->pathToOpenssl; + else if ( currentTool->Name == "pppd" ) + currentTool->TryPath_first = config->pathToPppd; + else if ( currentTool->Name == "iptables" ) + currentTool->TryPath_first = config->pathToIptables; + else if ( currentTool->Name == "kill" ) + currentTool->TryPath_first = config->pathToKill; + else if ( currentTool->Name == "killall" ) + currentTool->TryPath_first = config->pathToKillall; + else if ( currentTool->Name == "ping" ) + currentTool->TryPath_first = config->pathToPing; + else if ( currentTool->Name == "ip" ) + currentTool->TryPath_first = config->pathToIp; + else if ( currentTool->Name == "ifconfig" ) + currentTool->TryPath_first = config->pathToIfconfig; + else if ( currentTool->Name == "route" ) + currentTool->TryPath_first = config->pathToRoute; + else if ( currentTool->Name == "pptp" ) + currentTool->TryPath_first = config->pathToPptp; + else if ( currentTool->Name == "l2tpd" ) + currentTool->TryPath_first = config->pathToL2tpd; + else if ( currentTool->Name == "pkcs11-tool" ) + currentTool->TryPath_first = config->pathToPkcs11Tool; + else if ( currentTool->Name == "bash" ) + currentTool->TryPath_first = config->InterpreterShell; + else if ( currentTool->Name == "vtund" ) + currentTool->TryPath_first = config->pathToVtund; + else if ( currentTool->Name == "cisco_cert_mgr" ) + currentTool->TryPath_first = config->pathToCiscoCertMgr; + else if ( currentTool->Name == "tail" ) + currentTool->TryPath_first = config->pathToTail; + else if ( currentTool->Name == "ssh" ) + currentTool->TryPath_first = config->pathToSsh; + else if ( currentTool->Name == "ksshaskpass" ) + currentTool->TryPath_first = config->pathToKsshAskpass; + else if ( currentTool->Name == "gnome-ssh-askpass" ) + currentTool->TryPath_first = config->pathToGnomeSshAskpass; + else if ( currentTool->Name == "racoonctl" ) + currentTool->TryPath_first = config->pathToRacoonctl; + else if ( currentTool->Name == "netstat" ) + currentTool->TryPath_first = config->pathToNetstat; + + currentTool->collectToolInfo(); + ToolList->append( currentTool ); + + //currentTool=0L; + // std::cout << "tool: " << currentTool->Name << std::endl; + // std::cout << "Version: " << currentTool->Version << std::endl; + // std::cout << "Path: " << currentTool->PathToExec << std::endl << std::endl; + } + ToolList->sort(); + + return ToolList; + +} + +ToolInfo* Utils::getToolInfo( QString name ) +{ + ToolInfo * Tool = 0; + for ( Tool = config->ToolList->first();Tool;Tool = config->ToolList->next() ) + { + if ( Tool->Name == name ) + break; + } + return Tool; +} + +QString Utils::resolveName( QString Name ) +{ + resolvedIP = ""; + resolveFinished = false; + + struct hostent * server_entry; + + // get ip address to server name + if ( ( server_entry = gethostbyname( Name.ascii() ) ) == NULL ) + { + std::cout << "gethostbyname failed" << std::endl; + } + else + resolvedIP = QString( inet_ntoa( *( struct in_addr* ) server_entry->h_addr_list[ 0 ] ) ); + return resolvedIP; +} + +QString Utils::removeSpecialCharsForFilename( QString filename ) +{ + filename.replace( QRegExp( "[*]+" ), "_" ); + filename.replace( QRegExp( "[+] +" ), "_" ); + filename.replace( QRegExp( "[$]+" ), "_" ); + filename.replace( QRegExp( ":+" ), "_" ); + filename.replace( QRegExp( "ï¿œ" ), "_" ); + filename.replace( QRegExp( "ï¿œ" ), "_" ); + filename.replace( QRegExp( "+" ), "_" ); + filename.replace( QRegExp( "ï¿œ" ), "_" ); + filename.replace( QRegExp( "ï¿œ" ), "_" ); + filename.replace( QRegExp( "ï¿œ" ), "_" ); + filename.replace( QRegExp( "ï¿œ" ), "_" ); + filename.replace( "\\" , "_" ); + filename.replace( "/" , "_" ); + filename.replace( QRegExp( ";+" ), "_" ); + filename.replace( QRegExp( " " ), "_" ); + filename.replace( QRegExp( "_+" ), "_" ); + filename.replace( ")" , "_" ); + filename.replace( "(" , "_" ); + filename.replace( " " , "_" ); + return filename; +} + +QStringList Utils::getOpenvpnCiphers() +{ + OpenvpnCiphers.clear(); + retrieveOpenvpnCiphers = false; + + ToolInfo *OpenvpnInfo = getToolInfo ( "openvpn" ); + QString pathToOpenvpn = OpenvpnInfo->PathToExec; + + if ( pathToOpenvpn.isEmpty() ) + return OpenvpnCiphers; + + OpenvpnCiphersProcess = new QProcess( this ); + OpenvpnCiphersProcess->addArgument( pathToOpenvpn ); + OpenvpnCiphersProcess->addArgument( "--show-ciphers" ); + + connect( OpenvpnCiphersProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutRetriveOpenvpnCiphers() ) ); + connect( OpenvpnCiphersProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrRetriveOpenvpnCiphers() ) ); + + if ( !OpenvpnCiphersProcess->start( env ) ) { + + disconnect( OpenvpnCiphersProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutRetriveOpenvpnCiphers() ) ); + disconnect( OpenvpnCiphersProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrRetriveOpenvpnCiphers() ) ); + delete OpenvpnCiphersProcess; + OpenvpnCiphersProcess=0L; + kdError() << "Unable to fetch openvpn ciphers!" << endl; + return false; + } + else + { + while ( OpenvpnCiphersProcess->isRunning() ) + { + config->appPointer->processEvents(); + sleep ( 1 ); + } + disconnect( OpenvpnCiphersProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutRetriveOpenvpnCiphers() ) ); + disconnect( OpenvpnCiphersProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrRetriveOpenvpnCiphers() ) ); + delete OpenvpnCiphersProcess; + OpenvpnCiphersProcess=0L; + } + return OpenvpnCiphers; +} + +Utils::IpsecAlgos Utils::getIpsecAlgos() +{ + + IpsecAlgos salgos; + salgos.IpsecIkeEncryptionAlgorithms.clear(); + salgos.IpsecIkeHashAlgorithms.clear(); + salgos.IpsecIkeDhGroups.clear(); + salgos.IpsecEspEncryptionAlgorithms.clear(); + salgos.IpsecEspAuthenticationAlgorithms.clear(); + salgos.IpsecCompressionAlgorithms.clear(); + IpsecAlgoCurrent=""; + retrieveIpsecAlgos = false; + + ToolInfo *IpsecInfo = getToolInfo ( "ipsec" ); + QString pathToIpsec = IpsecInfo->PathToExec; + + if ( pathToIpsec.isEmpty() ) + return salgos; + + IpsecAlgosProcess = new QProcess( this ); + IpsecAlgosProcess->addArgument( pathToIpsec); + IpsecAlgosProcess->addArgument( "auto" ); + IpsecAlgosProcess->addArgument( "--status" ); + + connect( IpsecAlgosProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutRetriveIpsecAlgos() ) ); + connect( IpsecAlgosProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrRetriveIpsecAlgos() ) ); + + if ( !IpsecAlgosProcess->start( env ) ) { + disconnect( IpsecAlgosProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutRetriveIpsecAlgos() ) ); + disconnect( IpsecAlgosProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrRetriveIpsecAlgos() ) ); + delete IpsecAlgosProcess; + IpsecAlgosProcess=0L; + kdError() << "Unable to fetch ipsec algos!" << endl; + return salgos; + } + else + { + while ( IpsecAlgosProcess->isRunning() ) + { + config->appPointer->processEvents(); + sleep ( 1 ); + } + disconnect( IpsecAlgosProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutRetriveIpsecAlgos() ) ); + disconnect( IpsecAlgosProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrRetriveIpsecAlgos() ) ); + delete IpsecAlgosProcess; + IpsecAlgosProcess=0L; + } + return salgos; +} + +Utils::PppdCapabilities Utils::checkPppdCapabilities() +{ + pppdcap.pppdHasMppeRequiredSupport=false; + pppdcap.pppdHasRequireMppeSupport=false; + pppdcap.pppdHasReplacedefaultrouteSupport=false; + pppdcap.pppdHasMppeSupport=false; + pppdcap.oldPppdStyle=false; + pppdcap.pppdOk=false; + + // test mppe support of pppd + testPppdRequireMppe=true; + testPppdReplacedefaultroute=false; + testPppdMppeRequiredSupport=false; + testOldPppdStyle=false; + testPppdRequireMppe=false; + testPppdMppeRequired=false; + + + /* get pppd info */ + int pppd_version_major = 0; + int pppd_version_minor = 0; + int pppd_version_subminor = 0; + + ToolInfo *Tool = Utils ( config ).getToolInfo ( "pppd" ); + if ( !Tool->Version.isEmpty() ) + { + pppd_version_major = ( Tool->Version.section ( '.', 0, 0 ) ).toInt(); + pppd_version_minor = ( Tool->Version.section ( '.', 1, 1 ) ).toInt(); + pppd_version_subminor = ( Tool->Version.section ( '.', 2, 2 ) ).toInt(); + if ( config->KvpncDebugLevel > 5 ) + { + config->appendLogEntry ( i18n ( "pppd version (major): \"%1\"" ).arg ( pppd_version_major ) , config->debug ); + config->appendLogEntry ( i18n ( "pppd version (minor): \"%1\"" ).arg ( pppd_version_minor ) , config->debug ); + config->appendLogEntry ( i18n ( "pppd version (subminor): \"%1\"" ).arg ( pppd_version_subminor ) , config->debug ); + } + } + + if ( pppd_version_major <2 || (pppd_version_major ==2 && pppd_version_minor < 4 ) ) + { + // pppd < 2.4.0 + if ( config->KvpncDebugLevel > 5 ) + config->appendLogEntry ( i18n ( "pppd version is lower than 2.4.0" ) , config->debug ); + + pppdcap.RequireMppeOption=""; + pppdcap.Require128BitMppeOption=""; + pppdcap.RefuseMppeOption=""; + pppdcap.Refuse40BitMppeOption=""; + pppdcap.Refuse128BitMppeOption=""; + + pppdcap.RequireStatelessOption=""; + pppdcap.RequireStatefulOption=""; + pppdcap.MppeOptionsInALine = false; + pppdcap.RequireAuthMschapOption=""; + pppdcap.RequireAuthMschapv2Option=""; + pppdcap.RequireAuthPapOption=""; + } + + if (pppd_version_major ==2 && pppd_version_minor == 4 && (pppd_version_subminor == 0 || pppd_version_subminor == 0 ) ) + { + // pppd == 2.4.0/2.4.1 + if ( config->KvpncDebugLevel > 5 ) + config->appendLogEntry ( i18n ( "pppd version is 2.4.0" ) , config->debug ); + + pppdcap.RequireMppeOption="mppe-40"; + pppdcap.Require128BitMppeOption="mppe-128"; + pppdcap.RefuseMppeOption=""; + pppdcap.Refuse40BitMppeOption=""; + pppdcap.Refuse128BitMppeOption=""; + + pppdcap.RequireStatelessOption="mppe-stateless"; + pppdcap.RequireStatefulOption=""; + pppdcap.MppeOptionsInALine = false; + pppdcap.RequireAuthChapOption=""; + pppdcap.RequireAuthChapOption+="require-chap\n"; + pppdcap.RequireAuthChapOption+="refuse-chapms\n"; + pppdcap.RequireAuthChapOption+="refuse-chapms-v2\n"; + pppdcap.RequireAuthChapOption+="refuse-pap\n"; + pppdcap.RequireAuthChapOption+="refuse-eap"; + pppdcap.RequireAuthMschapOption=""; +// pppdcap.RequireAuthMschapOption+="refuse-chap\n"; + pppdcap.RequireAuthMschapOption+="require-chapms\n"; +// pppdcap.RequireAuthMschapOption+="require-chapms-v2\n"; + pppdcap.RequireAuthMschapOption+="refuse-pap\n"; + pppdcap.RequireAuthMschapOption+="refuse-eap"; + pppdcap.RequireAuthMschapv2Option=""; +// pppdcap.RequireAuthMschapv2Option+="refuse-chap\n"; +// pppdcap.RequireAuthMschapv2Option+="refuse-chapms\n"; + pppdcap.RequireAuthMschapv2Option+="require-chapms-v2\n"; + pppdcap.RequireAuthMschapv2Option+="refuse-pap\nrefuse-eap"; + pppdcap.RequireAuthPapOption=""; + pppdcap.RequireAuthPapOption+="require-pap\n"; + pppdcap.RequireAuthPapOption+="refuse-chap\n"; + pppdcap.RequireAuthPapOption+="refuse-chapms-v2\n"; + pppdcap.RequireAuthPapOption+="refuse-chapms-v2\n"; + pppdcap.RequireAuthPapOption+="refuse-eap"; + } + + if ( ( pppd_version_major ==2 && pppd_version_minor == 4 && pppd_version_subminor >= 2) || pppd_version_major >2 ) + { + // pppd >= 2.4.2 + if ( config->KvpncDebugLevel > 5 ) + config->appendLogEntry ( i18n ( "pppd version is >= 2.4.2, good" ) , config->debug ); + + pppdcap.RequireMppeOption="require-mppe"; + pppdcap.Require128BitMppeOption="require-mppe-128"; + pppdcap.RefuseMppeOption="nomppe"; + pppdcap.Refuse40BitMppeOption="nomppe-40"; + pppdcap.Refuse128BitMppeOption="nomppe-128"; + + pppdcap.RequireStatelessOption="nomppe-stateful"; + pppdcap.RequireStatefulOption=""; + pppdcap.MppeOptionsInALine = false; + pppdcap.RequireAuthChapOption=""; + pppdcap.RequireAuthChapOption+="refuse-pap\n"; + pppdcap.RequireAuthChapOption+="refuse-mschap\n"; + pppdcap.RequireAuthChapOption+="refuse-mschap-v2\n"; + pppdcap.RequireAuthChapOption+="refuse-eap"; + pppdcap.RequireAuthMschapOption=""; + pppdcap.RequireAuthMschapOption+="refuse-pap\n"; +// pppdcap.RequireAuthMschapOption+="refuse-chap\n"; +// pppdcap.RequireAuthMschapOption+="refuse-mschap-v2\n"; + pppdcap.RequireAuthMschapOption+="refuse-eap"; + pppdcap.RequireAuthMschapv2Option=""; + pppdcap.RequireAuthMschapv2Option+="refuse-pap\n"; + pppdcap.RequireAuthMschapv2Option+="refuse-chap\n"; + pppdcap.RequireAuthMschapv2Option+="refuse-mschap\n"; + pppdcap.RequireAuthMschapv2Option+="refuse-eap"; + pppdcap.RequireAuthPapOption=""; + pppdcap.RequireAuthPapOption+="refuse-mschap\n"; + pppdcap.RequireAuthPapOption+="refuse-mschap-v2\n"; + pppdcap.RequireAuthPapOption+="refuse-chap\n"; + pppdcap.RequireAuthPapOption+="refuse-eap"; + } + + + /* mppe test */ + + pppdcap.pppdHasMppeRequiredSupport=true; + pppdcap.pppdHasRequireMppeSupport=true; + pppdcap.pppdHasMppeSupport=true; + // first: new style + testOldPppdStyle = false; + testPppdRequireMppe=true; + testPppdMppeRequired=false; + TestPppdProcess = new QProcess ( this ); + TestPppdProcess->addArgument ( config->pathToPppd ); + TestPppdProcess->addArgument ( "/dev/null" ); + TestPppdProcess->addArgument ( "require-mppe" ); + + TestPppdProcess->setCommunication ( QProcess::Stdin | QProcess::Stdout | QProcess::Stderr | QProcess::DupStderr ); + TestPppdProcess->closeStdin (); + + connect ( TestPppdProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readPppdtestProcessOutput() ) ); +// connect ( TestPppdProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readPppdtestProcessOutput() ) ); + + if ( !TestPppdProcess->start ( env ) ) + { + config->appendLogEntry ( i18n ( "unable to start proc (%1)!" ).arg ( i18n ( "Test require-mppe support of pppd" ) ) , KVpncConfig::error ); + pppdcap.pppdOk=false; + } + else + { + pppdcap.pppdOk=true; + while ( TestPppdProcess->isRunning() ) + config->appPointer->processEvents(); + + + if (pppdcap.pppdHasRequireMppeSupport) + { + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( "pppdHasRequireMppeSupport: true", config->debug ); + pppdcap.RequireMppeOption="require-mppe"; + pppdcap.Require128BitMppeOption="require-mppe-128"; + pppdcap.RefuseMppeOption="nomppe"; + pppdcap.Refuse40BitMppeOption="nomppe-40"; + pppdcap.Refuse128BitMppeOption="nomppe-128"; + } + else + config->appendLogEntry ( "pppdHasRequireMppeSupport: false", config->debug ); + + } + disconnect ( TestPppdProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readPppdtestProcessOutput() ) ); +// disconnect ( TestPppdProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readPppdtestProcessOutput() ) ); + + delete TestPppdProcess; + TestPppdProcess=0L; + testPppdRequireMppe=false; + testPppdMppeRequired=true; + + + TestPppdProcess = new QProcess ( this ); + TestPppdProcess->addArgument ( config->pathToPppd ); + TestPppdProcess->addArgument ( "/dev/null" ); + TestPppdProcess->addArgument ( "mppe"); + TestPppdProcess->addArgument ( "required" ); + + TestPppdProcess->setCommunication ( QProcess::Stdin | QProcess::Stdout | QProcess::Stderr | QProcess::DupStderr ); + TestPppdProcess->closeStdin (); + + connect ( TestPppdProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readPppdtestProcessOutput() ) ); +// connect ( TestPppdProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readPppdtestProcessOutput() ) ); + + if ( !TestPppdProcess->start ( env ) ) + { + config->appendLogEntry ( i18n ( "unable to start proc (%1)!" ).arg ( i18n ( "Test mppe required support of pppd" ) ), KVpncConfig::error ); + pppdcap.pppdOk=false; + } + else + { + pppdcap.pppdOk=true; + while ( TestPppdProcess->isRunning() ) + { + config->appPointer->processEvents(); + sleep ( 1 ); + } + if (pppdcap.pppdHasMppeRequiredSupport) + { + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( "PppdMppeRequired: true", config->debug ); + + pppdcap.MppeOptionsInALine = true; + + pppdcap.RequireMppeOption="mppe required"; + pppdcap.Require128BitMppeOption=""; + pppdcap.RefuseMppeOption="nomppe"; + pppdcap.Refuse40BitMppeOption=",no40"; + pppdcap.Refuse128BitMppeOption=",no128"; + pppdcap.RequireStatefulOption=""; + pppdcap.RequireStatelessOption=",stateless"; + + } + else + config->appendLogEntry ( "PppdMppeRequired: false", config->debug ); + } + + disconnect ( TestPppdProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readPppdtestProcessOutput() ) ); +// disconnect ( TestPppdProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readPppdtestProcessOutput() ) ); + delete TestPppdProcess; + testPppdMppeRequired=false; + + + + + if (pppdcap.pppdHasRequireMppeSupport || pppdcap.pppdHasMppeRequiredSupport) + { + pppdcap.pppdHasMppeSupport = true; + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( " %1 has MPPE support." ) .arg ( config->pathToPppd ), config->debug ); + } + else + { + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( " %1 has no MPPE support." ) .arg ( config->pathToPppd ), config->debug ); + + } + + + /* defaultroute test */ + //unrecognized option 'replacedefaultroute' + // test defaultroute support of pppd + testPppdReplacedefaultroute = false; + TestPppdProcess = new QProcess ( this ); + TestPppdProcess->addArgument ( config->pathToPppd ); + TestPppdProcess->addArgument ( "replacedefaultroute" ); + TestPppdProcess->setCommunication ( QProcess::Stdin | QProcess::Stdout | QProcess::Stderr | QProcess::DupStderr ); + TestPppdProcess->closeStdin (); + + connect ( TestPppdProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readPppdtestProcessOutput() ) ); + connect ( TestPppdProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readPppdtestProcessOutput() ) ); + + + if ( !TestPppdProcess->start ( env ) ) + { + config->appendLogEntry ( i18n ( "unable to start proc (%1)!" ).arg ( i18n ( "Test support of replacedefaultroute pppd" ) ) , config->error ); + pppdcap.pppdOk=false; + } + else + { + while ( TestPppdProcess->isRunning() ) + { + config->appPointer->processEvents(); + sleep ( 1 ); + } + + + if ( pppdcap.pppdHasReplacedefaultrouteSupport ) + { + if ( config->KvpncDebugLevel > 4 ) + config->appendLogEntry ( i18n ( "Test support of replacedefaultroute pppd: %1" ).arg ( i18n ( "succeded" ) ) , config->debug ); + } + else + { + if ( config->KvpncDebugLevel > 4 ) + config->appendLogEntry ( i18n ( "Test support of replacedefaultroute pppd: %1" ).arg ( i18n ( "failed" ) ) , config->debug ); + } + } + disconnect ( TestPppdProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readPppdtestProcessOutput() ) ); + disconnect ( TestPppdProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readPppdtestProcessOutput() ) ); + delete TestPppdProcess; + TestPppdProcess=0L; + + return pppdcap; +} + +QStringList Utils::getOpenvpnDigests() +{ + OpenvpnDigests.clear(); + retrieveOpenvpnDigests = false; + OpenvpnDigestCount=0; + OpenvpnDigestString=""; + + ToolInfo *OpenvpnInfo = getToolInfo ( "openvpn" ); + QString pathToOpenvpn = OpenvpnInfo->PathToExec; + + if ( pathToOpenvpn.isEmpty() ) + return OpenvpnDigests; + + OpenvpnDigestProcess = new QProcess( this ); + OpenvpnDigestProcess->addArgument( pathToOpenvpn ); + OpenvpnDigestProcess->addArgument( "--show-digests" ); + + connect( OpenvpnDigestProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutRetriveOpenvpnDigests() ) ); + connect( OpenvpnDigestProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrRetriveOpenvpnDigests() ) ); + + if ( !OpenvpnDigestProcess->start( env ) ) { + disconnect( OpenvpnDigestProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutRetriveOpenvpnDigests() ) ); + disconnect( OpenvpnDigestProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrRetriveOpenvpnDigests() ) ); + delete OpenvpnDigestProcess; + OpenvpnDigestProcess=0L; + kdError() << "Unable to fetch openvpn digests!" << endl; + return false; + } + else + { + while ( OpenvpnDigestProcess->isRunning() ) + { + config->appPointer->processEvents(); + sleep ( 1 ); + } + + + OpenvpnDigests = QStringList().split("#",OpenvpnDigestString); + + for ( QStringList::Iterator it = OpenvpnDigests.begin(); it != OpenvpnDigests.end(); ++it ) + *it = QString(*it).section(' ',0,0); + + } + disconnect( OpenvpnDigestProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutRetriveOpenvpnDigests() ) ); + disconnect( OpenvpnDigestProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrRetriveOpenvpnDigests() ) ); + delete OpenvpnDigestProcess; + OpenvpnDigestProcess=0L; + return OpenvpnDigests; +} + +Utils::IpsecAlgos Utils::getKernelCrypto() +{ + IpsecAlgos salgos; + salgos.IpsecIkeEncryptionAlgorithms.clear(); + salgos.IpsecIkeHashAlgorithms.clear(); + salgos.IpsecIkeDhGroups.clear(); + salgos.IpsecEspEncryptionAlgorithms.clear(); + salgos.IpsecEspAuthenticationAlgorithms.clear(); + salgos.IpsecCompressionAlgorithms.clear(); + QString IpsecAlgoNameCurrent=""; + QString IpsecAlgoTypeCurrent=""; + QFile cryptoprocfile( "/proc/crypto" ); + + if ( cryptoprocfile.open( IO_ReadOnly ) ) + { + QTextStream stream( &cryptoprocfile ); + QString line; + if (config->KvpncDebugLevel > 4) + std::cout << "Kernel crypto list: " << std::endl; + while ( !stream.atEnd() ) + { + line = stream.readLine(); + if (line.find("name") > -1 ) + { + IpsecAlgoNameCurrent = line.section(':',1,1).stripWhiteSpace(); +// std::cout << "crypto name: " << IpsecAlgoNameCurrent.ascii() << std::endl; + } + if (line.find("type") >-1) + { + IpsecAlgoTypeCurrent=line.section(':',1,1).stripWhiteSpace(); +// std::cout << "crypto type: " << IpsecAlgoTypeCurrent.ascii() << std::endl; + + if (IpsecAlgoTypeCurrent != "blkcipher" && IpsecAlgoTypeCurrent == "cipher") + { +// std::cout << "adding cipher algo " << IpsecAlgoNameCurrent << std::endl; + salgos.IpsecEspEncryptionAlgorithms.append(IpsecAlgoNameCurrent); + } + if (IpsecAlgoTypeCurrent == "digest") + { +// std::cout << "adding digest algo " << IpsecAlgoNameCurrent << std::endl; + salgos.IpsecEspAuthenticationAlgorithms.append(IpsecAlgoNameCurrent); + } + if (IpsecAlgoTypeCurrent == "hash") + { +// std::cout << "adding hash algo " << IpsecAlgoNameCurrent << std::endl; + salgos.IpsecIkeHashAlgorithms.append(IpsecAlgoNameCurrent); + } + if (IpsecAlgoTypeCurrent == "compression") + { +// std::cout << "adding compression algo " << IpsecAlgoNameCurrent << std::endl; + salgos.IpsecCompressionAlgorithms.append(IpsecAlgoNameCurrent); + } + + } + } + cryptoprocfile.close(); + salgos.IpsecIkeEncryptionAlgorithms.sort(); + salgos.IpsecIkeHashAlgorithms.sort(); + salgos.IpsecIkeDhGroups.sort(); + salgos.IpsecEspEncryptionAlgorithms.sort(); + salgos.IpsecEspAuthenticationAlgorithms.sort(); + salgos.IpsecCompressionAlgorithms.sort(); + } + else + { + config->appendLogEntry(i18n("%1 cant be opened!").arg("/proc/crypto"),config->error); + } + return salgos; +} + +QString Utils::getNameAndPidOfProgramListen( int port ) +{ + if ( port == 0 ) + return ""; + + ListenPort = port; + retrieveNameAndPidOfProgramListen = false; + + NameAndPidOfProgramListenProcess = new QProcess( this ); + NameAndPidOfProgramListenProcess->addArgument( config->pathToNetstat ); + NameAndPidOfProgramListenProcess->addArgument( "-ntupl" ); + + connect( NameAndPidOfProgramListenProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutGetNameAndPidOfProgramListen() ) ); + connect( NameAndPidOfProgramListenProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrGetNameAndPidOfProgramListen() ) ); + + if ( !NameAndPidOfProgramListenProcess->start( env ) ) { + disconnect( NameAndPidOfProgramListenProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutGetNameAndPidOfProgramListen() ) ); + disconnect( NameAndPidOfProgramListenProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrGetNameAndPidOfProgramListen() ) ); + delete NameAndPidOfProgramListenProcess; + NameAndPidOfProgramListenProcess=0L; + kdError() << "netstat fails!" << endl; + return false; + } + else + { + while ( NameAndPidOfProgramListenProcess->isRunning() ) + { + config->appPointer->processEvents(); + sleep ( 1 ); + } + + + disconnect( NameAndPidOfProgramListenProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutGetNameAndPidOfProgramListen() ) ); + disconnect( NameAndPidOfProgramListenProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrGetNameAndPidOfProgramListen() ) ); + delete NameAndPidOfProgramListenProcess; + NameAndPidOfProgramListenProcess=0L; + } + return NameAndPidOfProgramListen; +} + +QString Utils::getEmailAddressOfCert(QString cert) +{ + if (cert.isEmpty()) + return ""; + + GetEmailAddressOfCertProcess = new QProcess ( this ); + GetEmailAddressOfCertProcess->setCommunication( QProcess::Stdin | QProcess::Stdout | QProcess::Stderr | QProcess::DupStderr ); + GetEmailAddressOfCertProcess->addArgument( config->pathToOpenssl ); + GetEmailAddressOfCertProcess->addArgument( "x509"); + GetEmailAddressOfCertProcess->addArgument( "-noout"); + GetEmailAddressOfCertProcess->addArgument( "-in"); + GetEmailAddressOfCertProcess->addArgument( cert ); + GetEmailAddressOfCertProcess->addArgument( "-subject"); + + connect( GetEmailAddressOfCertProcess, SIGNAL( readyReadStdout() ), this, SLOT( readOutGetEmailAddressOfCert() ) ); + + if ( !GetEmailAddressOfCertProcess->start( env ) ) { + disconnect( GetEmailAddressOfCertProcess, SIGNAL( readyReadStdout() ), this, SLOT( readOutGetEmailAddressOfCert() ) ); + delete GetEmailAddressOfCertProcess; + GetEmailAddressOfCertProcess=0L; + kdError() << "GetEmailAddressOfCertProcess" << endl; + return false; + } + else + { + while ( GetEmailAddressOfCertProcess->isRunning() ) + { + config->appPointer->processEvents(); + sleep ( 1 ); + } + disconnect( GetEmailAddressOfCertProcess, SIGNAL( readyReadStdout() ), this, SLOT( readOutGetEmailAddressOfCert() ) ); + delete GetEmailAddressOfCertProcess; + GetEmailAddressOfCertProcess=0L; + } + + return EmailAddressOfCert; +} + +QStringList Utils::getSmartcardSlots(QString ProviderLib) +{ + SmartcardSlots.clear(); + + ToolInfo *Pkcs11ToolInfo = getToolInfo ( "pkcs11-tool" ); + Pkcs11ToolInfo->collectToolInfo(); +// if (Pkcs11ToolInfo == 0) +// return SmartcardSlots; + QString pathToPkcs11Tool; + pathToPkcs11Tool = Pkcs11ToolInfo->PathToExec; + + if ( pathToPkcs11Tool.isEmpty() ) + return SmartcardSlots; + + GetSmartcardSlotsProcess = new KProcess; + + *GetSmartcardSlotsProcess << pathToPkcs11Tool; + if (!ProviderLib.isEmpty()) + { + *GetSmartcardSlotsProcess << "--module"; + *GetSmartcardSlotsProcess << ProviderLib ; + } + *GetSmartcardSlotsProcess << "-L" ; + + connect( GetSmartcardSlotsProcess, SIGNAL( receivedStdout ( KProcess *, char *, int)), this, SLOT(readOutGetSmartcardSlots())); + + if ( !GetSmartcardSlotsProcess->start ( KProcess::NotifyOnExit, KProcess::All ) ) + { + disconnect( GetSmartcardSlotsProcess, SIGNAL( receivedStdout ( KProcess *, char *, int)), this, SLOT(readOutGetSmartcardSlots())); + delete GetSmartcardSlotsProcess; + GetSmartcardCertsFromSlotProcess=0L; + config->appendLogEntry(i18n("Unable to fetch smartcard slots via pkcs11-tool!"), config->error); + return false; + } + else + { + if (config->KvpncDebugLevel > 5) + config->appendLogEntry ( i18n("Fetch smartcard slots via pkcs11-tool started.") ,config->debug ); + + while ( GetSmartcardSlotsProcess->isRunning() ) + { + usleep ( 500 ); + config->appPointer->processEvents(); + } + disconnect( GetSmartcardSlotsProcess, SIGNAL( receivedStdout ( KProcess *, char *, int)), this, SLOT(readOutGetSmartcardSlots())); + delete GetSmartcardSlotsProcess; + GetSmartcardCertsFromSlotProcess=0L; + if (config->KvpncDebugLevel > 5) + config->appendLogEntry ( i18n("Fetch smartcard slots via pkcs11-tool finished.") ,config->debug ); + } + return SmartcardSlots; +} + +QStringList Utils::getSmartcardCertsFromSlot(QString slot,QString IdType,QString ProviderLib) +{ + Pkcs11CertFound=false; + SmartcardCertsFromSlot.clear(); + + if (!IdType.isEmpty()) + this->IdType= IdType; + else + this->IdType = "id"; + + ToolInfo *Pkcs11ToolInfo = getToolInfo ( "pkcs11-tool" ); + Pkcs11ToolInfo->collectToolInfo(); +// if (Pkcs11ToolInfo == 0) +// return SmartcardSlots; + QString pathToPkcs11Tool; + pathToPkcs11Tool = Pkcs11ToolInfo->PathToExec; + + if ( pathToPkcs11Tool.isEmpty() ) + return SmartcardSlots; + + GetSmartcardCertsFromSlotProcess = new QProcess( this ); + GetSmartcardCertsFromSlotProcess->setCommunication( QProcess::Stdin | QProcess::Stdout | QProcess::Stderr | QProcess::DupStderr ); + GetSmartcardCertsFromSlotProcess->addArgument( pathToPkcs11Tool); + + if (!ProviderLib.isEmpty()) + { + GetSmartcardCertsFromSlotProcess->addArgument( "--module"); + GetSmartcardCertsFromSlotProcess->addArgument( ProviderLib ); + } + + GetSmartcardCertsFromSlotProcess->addArgument( "-O" ); + + GetSmartcardCertsFromSlotProcess->addArgument( "--slot" ); + if (!slot.isEmpty()) + GetSmartcardCertsFromSlotProcess->addArgument( slot ); + else + GetSmartcardCertsFromSlotProcess->addArgument("0"); + + connect( GetSmartcardCertsFromSlotProcess, SIGNAL( readyReadStdout() ), this, SLOT( readOutGetSmartcardCertsFromSlot() ) ); + + if ( !GetSmartcardCertsFromSlotProcess->start( env ) ) { + disconnect( GetSmartcardCertsFromSlotProcess, SIGNAL( readyReadStdout() ), this, SLOT( readOutGetSmartcardCertsFromSlot() ) ); + delete GetSmartcardCertsFromSlotProcess; + GetSmartcardCertsFromSlotProcess=0L; + kdError() << "Unable to fetch smartcard slots via pkcs11-tool!" << endl; + return false; + } + else + { + + while ( GetSmartcardCertsFromSlotProcess->isRunning() ) + { + usleep ( 500 ); + config->appPointer->processEvents(); + } + disconnect( GetSmartcardCertsFromSlotProcess, SIGNAL( readyReadStdout() ), this, SLOT( readOutGetSmartcardCertsFromSlot() ) ); + delete GetSmartcardCertsFromSlotProcess; + GetSmartcardCertsFromSlotProcess=0L; + } + + return SmartcardCertsFromSlot; +} + +QStringList Utils::getCertsFromCiscoCertStore(QString type) +{ + + if (type != "user" && type != "ca" && type != "enrollment") + type="user"; + + if (config->KvpncDebugLevel > 2) + config->appendLogEntry("getCertsFromCiscoCertStore: "+i18n("type: %1").arg(type),config->debug ); + + CertsFromCiscoCertStore.clear(); + CertsFromCiscoCertPos=0; + + if ( config->pathToCiscoCertMgr.isEmpty() ) + return CertsFromCiscoCertStore; + + GetCertsFromCiscoCertStoreProcess = new QProcess( this ); + GetCertsFromCiscoCertStoreProcess->setCommunication( QProcess::Stdin | QProcess::Stdout | QProcess::Stderr | QProcess::DupStderr ); + GetCertsFromCiscoCertStoreProcess->addArgument( config->pathToCiscoCertMgr ); + + if (type == "user") + GetCertsFromCiscoCertStoreProcess->addArgument( "-U"); + if (type == "ca") + GetCertsFromCiscoCertStoreProcess->addArgument( "-R"); + GetCertsFromCiscoCertStoreProcess->addArgument( "-op"); + if (type == "enrollent") + GetCertsFromCiscoCertStoreProcess->addArgument( "-E"); + GetCertsFromCiscoCertStoreProcess->addArgument( "-op"); + + + GetCertsFromCiscoCertStoreProcess->addArgument( "list"); + + connect( GetCertsFromCiscoCertStoreProcess, SIGNAL( readyReadStdout() ), this, SLOT( readOutGetCertsFromCiscoCertStoreSlot() ) ); + + if ( !GetCertsFromCiscoCertStoreProcess->start( env ) ) + { + disconnect( GetCertsFromCiscoCertStoreProcess, SIGNAL( readyReadStdout() ), this, SLOT( readOutGetCertsFromCiscoCertStoreSlot() ) ); + delete GetCertsFromCiscoCertStoreProcess; + GetCertsFromCiscoCertStoreProcess=0L; + kdError() << "Unable to fetch certificates via cisco_cert_mgr!" << endl; + return false; + } + else + { + + while ( GetCertsFromCiscoCertStoreProcess->isRunning() ) + { + usleep ( 500 ); + if ( config->appPointer->hasPendingEvents () ) + config->appPointer->processEvents(); + } + disconnect( GetCertsFromCiscoCertStoreProcess, SIGNAL( readyReadStdout() ), this, SLOT( readOutGetCertsFromCiscoCertStoreSlot() ) ); + delete GetCertsFromCiscoCertStoreProcess; + GetCertsFromCiscoCertStoreProcess=0L; + } + + return CertsFromCiscoCertStore; +} + +QStringList Utils::getOpenvpnPkcs11Ids(QString ProviderLib) +{ + Pkcs11CertFound=false; + OpenvpnPkcs11Ids.clear(); + OpenvpnPkcs11IdsProcess = new QProcess( this ); + OpenvpnPkcs11IdsProcess->setCommunication( QProcess::Stdin | QProcess::Stdout | QProcess::Stderr | QProcess::DupStderr ); + //openvpn --show-pkcs11-ids /usr/lib/opensc-pkcs11.so + OpenvpnPkcs11IdsProcess->addArgument(config->pathToOpenvpn); + OpenvpnPkcs11IdsProcess->addArgument("--show-pkcs11-ids"); + if (!ProviderLib.isEmpty()) + OpenvpnPkcs11IdsProcess->addArgument( ProviderLib ); + + + connect( OpenvpnPkcs11IdsProcess, SIGNAL( readyReadStdout() ), this, SLOT( readOutGetOpenvpnPkcs11Ids() ) ); + + if ( !OpenvpnPkcs11IdsProcess->start( env ) ) { + disconnect( OpenvpnPkcs11IdsProcess, SIGNAL( readyReadStdout() ), this, SLOT( readOutGetOpenvpnPkcs11Ids() ) ); + delete OpenvpnPkcs11IdsProcess; + OpenvpnPkcs11IdsProcess=0L; + kdError() << "Unable to fetch pkcs11 ids via openvpn!" << endl; + return false; + } + else + { + + while ( OpenvpnPkcs11IdsProcess->isRunning() ) + { + usleep ( 500 ); + config->appPointer->processEvents(); + } + disconnect( OpenvpnPkcs11IdsProcess, SIGNAL( readyReadStdout() ), this, SLOT( readOutGetOpenvpnPkcs11Ids() ) ); + delete OpenvpnPkcs11IdsProcess; + OpenvpnPkcs11IdsProcess=0L; + } + + return OpenvpnPkcs11Ids; +} + +bool Utils::getNeedsPassphrase(QString key) +{ + + if (key.isEmpty() || !QFile(key).exists()) + return false; + + needsPassphrase=false; + + //openssl rsa -noout -in client.key -passin pass:aaa + + ToolInfo *OpensslToolInfo = getToolInfo ( "openssl" ); + OpensslToolInfo->collectToolInfo(); + + QString pathToOpenssl = OpensslToolInfo->PathToExec; + + if ( pathToOpenssl.isEmpty() ) + return needsPassphrase; + + NeedsPassphraseProcess = new QProcess( this ); + NeedsPassphraseProcess->setCommunication( QProcess::Stdin | QProcess::Stdout | QProcess::Stderr | QProcess::DupStderr ); + NeedsPassphraseProcess->addArgument( pathToOpenssl); + NeedsPassphraseProcess->addArgument("rsa"); + NeedsPassphraseProcess->addArgument("-noout"); + NeedsPassphraseProcess->addArgument("-in"); + NeedsPassphraseProcess->addArgument(key); + NeedsPassphraseProcess->addArgument("-passin"); + NeedsPassphraseProcess->addArgument("pass:aaa"); + + + connect( NeedsPassphraseProcess, SIGNAL( readyReadStdout() ), this, SLOT( readOutNeedsPassphrase() ) ); + + if ( !NeedsPassphraseProcess->start( env ) ) { + disconnect( NeedsPassphraseProcess, SIGNAL( readyReadStdout() ), this, SLOT( readOutNeedsPassphrase() ) ); + delete NetworkDeviceTestProcess; + NeedsPassphraseProcess=0L; + kdError() << "Unable to start openssl!" << endl; + return false; + } + else + { + while ( NeedsPassphraseProcess->isRunning() ) + { + usleep ( 500 ); + config->appPointer->processEvents(); + } + disconnect( NeedsPassphraseProcess, SIGNAL( readyReadStdout() ), this, SLOT( readOutNeedsPassphrase() ) ); + delete NetworkDeviceTestProcess; + NeedsPassphraseProcess=0L; + } + + return needsPassphrase; +} + +QString Utils::getHostname() +{ + Hostname="linux.local"; + + GetHostnameProcess = new QProcess( this ); + GetHostnameProcess->addArgument( "hostname" ); + + connect( GetHostnameProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutGetHostname() ) ); + connect( GetHostnameProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrGetHostname() ) ); + if ( !GetHostnameProcess->start( env ) ) { + disconnect( GetHostnameProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutGetHostname() ) ); + disconnect( GetHostnameProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrGetHostname() ) ); + delete GetHostnameProcess; + GetHostnameProcess=0L; + kdError() << "Unable to start getHostname process!" << endl; + return Hostname; + } + else + { + while ( GetHostnameProcess->isRunning() ) + { + usleep(200); + } + disconnect( GetHostnameProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutGetHostname() ) ); + disconnect( GetHostnameProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrGetHostname() ) ); + delete GetHostnameProcess; + GetHostnameProcess=0L; + return Hostname; + } + + +} + +/* === Slots === */ +void Utils::readStdOutCreateTunDev() { + QString msg = QString( createProcess->readStderr() ); + kdDebug() << "readStdOutCreateTunDev(): " << msg << endl; +} + +void Utils::readStdErrCreateTunDev() +{ + QString msg = QString( createProcess->readStderr() ); + kdError() << "readStdErrCreateTunDev" << msg << endl; + +} + +void Utils::readStdOutLoadKernelModule() +{ + QString msg = QString( ModprobeProcess->readStdout() ); + kdDebug() << "readStdErrreadStdOutLoadKernelModule" << msg << endl; +} + +void Utils::readStdErrLoadKernelModule() +{ + QString msg = QString( ModprobeProcess->readStderr() ); + // kdDebug() << "readStdErrreadStderrLoadKernelModule" << msg << endl; + + /* FATAL: Module not found. */ + if ( msg.find( "not found", 0, FALSE ) > -1 ) { + modprobeSuccess = false; + } + + if ( msg.find( "could not find module", 0 , FALSE ) > -1 ) { + modprobeSuccess = false; + } + + if ( msg.find( "not permitted", 0 , FALSE ) > -1 ) { + modprobeSuccess = false; + } +} + +void Utils::readStdOutToolsTest() +{ +} + +void Utils::readStdErrToolsTest() +{ +} + +void Utils::readStdOutRetriveOpenvpnCiphers() +{ + while ( OpenvpnCiphersProcess->canReadLineStdout() ) { + QString msg = QString( OpenvpnCiphersProcess->readLineStdout() ); + if ( msg.contains( "default key" ) ) { + //std::cout << msg.ascii() << std::endl; + OpenvpnCiphers.append( msg.section( ' ', 0, 0 ) ); + } + } +} + +void Utils::readStdErrRetriveOpenvpnCiphers() +{ + while ( OpenvpnCiphersProcess->canReadLineStderr() ) { + QString msg = QString( OpenvpnCiphersProcess->readLineStderr() ); + + } +} + +void Utils::readStdOutRetriveIpsecAlgos() +{ + while ( IpsecAlgosProcess->canReadLineStdout() ) { + QString msg = QString( IpsecAlgosProcess->readLineStdout() ); + bool newIpsecAlgoFound=false; +// std::cout << "[ipsec algos raw] "<< msg.ascii() << std::endl; + if (msg.find ( "000 algorithm", 0, -1 ) > -1) + { + std::cout << "[ipsec algos line] "<< msg.ascii() << std::endl; + if (msg.find ( "000 algorithm ESP", 0, -1 ) > -1) + { + + QString Algo = msg.stripWhiteSpace().section(":",1,1).section(",",1,1).section("=",1,1); + QString MinKeySize = msg.stripWhiteSpace().section(":",1,1).section(",",3,3).section("=",1,1); + QString MaxKeySize = msg.stripWhiteSpace().section(":",1,1).section(",",4,4).section("=",1,1); + std::cout << "IKE encryption algo found: \"" << Algo << "\", Min: " << MinKeySize << ", Max: " << MaxKeySize << std::endl; +// QStringList AlgoOptList = QStringList::split("-",AlgoOpt); +// for (QStringList::Iterator it = AlgoOptList.begin(); it != AlgoOptList.end(); ++it) +// { +// std::cout << "IKE encryption algo subtypes found: \"" << Algo << "-" << *it << "\"" << std::endl; +// } + } + + } + } +} + +void Utils::readStdErrRetriveIpsecAlgos() +{ + while ( IpsecAlgosProcess->canReadLineStderr() ) { + QString msg = QString( IpsecAlgosProcess->readLineStderr() ); + std::cout << "[ipsec algos raw err] "<< msg.ascii() << std::endl; + } +} + +void Utils::readPppdtestProcessOutput() +{ + QString msg = ""; + msg += QString ( TestPppdProcess->readStdout() ); +// msg += QString ( TestPppdProcess->readStderr() ); + +// if ( msg == "" ) +// return ; + + + + /* mppe test */ + if (testPppdRequireMppe) + { + if (config->KvpncDebugLevel > 2) + config->appendLogEntry("Testing require-mppe",config->debug); + + if (config->KvpncDebugLevel > 4) + config->appendLogEntry("[test pppd raw]: "+msg,config->debug); + + if ( msg.contains ( "unrecognized option 'require-mppe'" ) ) + { + pppdcap.oldPppdStyle = true; + pppdcap.pppdHasMppeSupport = false; + pppdcap.pppdHasRequireMppeSupport=false; + + if ( config->KvpncDebugLevel > 4 ) + config->appendLogEntry ( i18n ( "%1 has no MPPE support using \"require mppe\"." ) .arg ( config->pathToPppd ), config->debug ); + } + else + { + if ( msg.contains ( "The remote system is required to authenticate itself" ) ) + { + // old style found + pppdcap.oldPppdStyle = false; + pppdcap.pppdHasMppeSupport = true; + pppdcap.pppdHasRequireMppeSupport=true; + + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "%1 has MPPE support and uses require mppe." ) .arg ( config->pathToPppd ), config->debug ); + } + } + } + + if ( testPppdMppeRequired) + { + if (config->KvpncDebugLevel > 2) + config->appendLogEntry("Testing mppe-required",config->debug); + + if (config->KvpncDebugLevel > 4) + config->appendLogEntry("[test pppd raw]: "+msg,config->debug); + + // try old style + if ( msg.contains ( "unrecognized option 'mppe'" ) ) + { + // no mppe support :( + pppdcap.oldPppdStyle = false; + pppdcap.pppdHasMppeSupport = false; + pppdcap.pppdHasMppeRequiredSupport=false; + if ( config->KvpncDebugLevel > 4 ) + config->appendLogEntry ( i18n ( "%1 has no MPPE support using \"mppe-required\"." ) .arg ( config->pathToPppd ), config->debug ); + } + else + { + if ( msg.contains ( "The remote system is required to authenticate itself" ) ) + { + // old style found + pppdcap.oldPppdStyle = true; + pppdcap.pppdHasMppeSupport = true; + pppdcap.pppdHasMppeRequiredSupport=true; + + if ( config->KvpncDebugLevel > 0 ) + config->appendLogEntry ( i18n ( "%1 has MPPE support and uses mppe-required." ) .arg ( config->pathToPppd ), config->debug ); + } + } + } + + + /* default route test */ + if ( testPppdReplacedefaultroute ) + { + + if (config->KvpncDebugLevel > 1) + config->appendLogEntry("[test pppd raw]: "+msg,config->debug); + + if ( msg.contains ( "unrecognized option 'replacedefaultroute'" ) ) + { + pppdcap.pppdHasReplacedefaultrouteSupport = false; + + if (config->KvpncDebugLevel > 1) + config->appendLogEntry(i18n("Testing %1: %2").arg("replacedefaultroute").arg(i18n("failed")),config->debug); + } + else + { + pppdcap.pppdHasReplacedefaultrouteSupport = true; + if (config->KvpncDebugLevel > 1) + config->appendLogEntry(i18n("Testing %1: %2").arg("replacedefaultroute").arg(i18n("succeded")),config->debug); + } + } + + +} + +void Utils::readStdOutRetriveOpenvpnDigests() +{ + while ( OpenvpnDigestProcess->canReadLineStdout() ) { + QString msg = QString( OpenvpnDigestProcess->readLineStdout() ); + OpenvpnDigestCount+=1; + if ( OpenvpnDigestCount > 5 ) + { +// std::cout << msg.simplifyWhiteSpace().ascii() << std::endl; + OpenvpnDigestString += msg+"#"; + } + } +} + +void Utils::readStdErrRetriveOpenvpnDigests() +{ + while ( OpenvpnDigestProcess->canReadLineStderr() ) { + QString msg = QString( OpenvpnDigestProcess->readLineStderr() ); + + } +} + +void Utils::readStdOutGetNameAndPidOfProgramListen() +{ + while ( NameAndPidOfProgramListenProcess->canReadLineStdout() ) { + QString msg = QString( NameAndPidOfProgramListenProcess->readLineStdout() ); + if ( msg.contains( "/" ) && msg.contains( QString().setNum( ListenPort ) ) && msg.simplifyWhiteSpace().section( ' ', 3, 3 ).section(':',1,1) == QString().setNum( ListenPort ) ) { + std::cout << msg.ascii() << std::endl; + NameAndPidOfProgramListen = ( msg.simplifyWhiteSpace().section( ' ', 5, 5 ) ); + if (NameAndPidOfProgramListen.contains( "LISTEN")) + NameAndPidOfProgramListen = ( msg.simplifyWhiteSpace().section( ' ', 6, 6 ) ); + break; + } + } +} + +void Utils::readStdErrGetNameAndPidOfProgramListen() +{ + while ( NameAndPidOfProgramListenProcess->canReadLineStderr() ) { + QString msg = QString( NameAndPidOfProgramListenProcess->readLineStderr() ); + + } +} + +void Utils::readOutGetEmailAddressOfCert() +{ + while ( GetEmailAddressOfCertProcess->canReadLineStdout() ) { + QString msg = QString( GetEmailAddressOfCertProcess->readLineStdout() ); + if ( msg.contains( "emailAddress" ) ) { + std::cout << "msg: " << msg.ascii() << std::endl; + QStringList fields = QStringList::split( '/', msg); + for ( QStringList::iterator field = fields.begin(); field != fields.end();++field ) + { + if (QString (*field).contains("emailAddress")) + { + if (config->KvpncDebugLevel > 2) + std::cout << "field: " << QString(*field).ascii() << std::endl; + // subject= /C=de/L=WR/O=crissi/CN=Christoph Thielecke/emailAddress=crissi99@gxm.de + // crissi99@gxm.de + EmailAddressOfCert = QString(*field).section('=',1,1); + break; + } + } + break; + } + } +} + +void Utils::readOutGetSmartcardSlots(KProcess * proc, char * buffer, int buflen) +{ + QString msg_raw = QString::fromLatin1(buffer, buflen); + if (config->KvpncDebugLevel > 5) + config->appendLogEntry ( QString("[readOutGetSmartcardSlots raw] "+QString(msg_raw)) ,config->debug ); + + + QStringList msg_raw_list = QStringList::split ( "\n",msg_raw ); + + for ( QStringList::Iterator it = msg_raw_list.begin(); it != msg_raw_list.end(); ++it ) + { + QString msg = *it; + if (config->KvpncDebugLevel > 5) + config->appendLogEntry ( QString("[readOutGetSmartcardSlots] "+QString(msg)) ,config->debug ); + + + if ( msg.contains( "Slot" ) && !msg.contains("empty") ) + { + //std::cout << msg.ascii() << std::endl; +// KMessageBox::information( 0, i18n( "msg: %1" ).arg( msg.stripWhiteSpace() ), QString("foo") ); + // we put in this format: : + QString id = msg.stripWhiteSpace().section( ' ', 1, 1 ); + QString name = msg.stripWhiteSpace().remove(QString("Slot "+id)).stripWhiteSpace(); + QString slot = id+" : "+name; + SmartcardSlots.append( slot ); + } + } +} + +void Utils::readOutGetSmartcardCertsFromSlot() +{ + while ( GetSmartcardCertsFromSlotProcess->canReadLineStdout() ) { + QString msg = QString( GetSmartcardCertsFromSlotProcess->readLineStdout() ); + + if (config->KvpncDebugLevel > 5) + config->appendLogEntry ( QString("[readOutGetSmartcardCertsFromSlot] "+QString(msg)) ,config->debug ); + + if ( msg.contains( "Certificate Object" ) ) { +// KMessageBox::sorry( 0, QString("msg: "+msg), QString("foo1"),0 ); + Pkcs11CertFound=true; + } +// KMessageBox::information( 0, i18n( "msg: %1" ).arg( msg ), QString("foo") ); + if (IdType == "id") + { + if ( msg.contains( "ID:" ) && Pkcs11CertFound==true ) { + //std::cout << msg.ascii() << std::endl; + QString msg2 = msg.section( ':', 1, 1 ); + msg2 = msg2.stripWhiteSpace(); +// KMessageBox::sorry( 0, QString("id: "+msg), QString("foo"),0 ); + SmartcardCertsFromSlot.append( msg2 ); + Pkcs11CertFound=false; + } + } + else if (IdType == "label") + { + if ( msg.contains( "label:" ) && Pkcs11CertFound==true ) { + //std::cout << msg.ascii() << std::endl; + QString msg2 = msg.section( ':', 1, 1 ); + msg2 = msg2.stripWhiteSpace(); +// KMessageBox::sorry( 0, QString("label: "+msg2), QString("foo"),0 ); + SmartcardCertsFromSlot.append( msg2 ); + Pkcs11CertFound=false; + } + } + else if (IdType == "subject") + { + if ( msg.contains( "Subject:" ) && Pkcs11CertFound==true ) { + //std::cout << msg.ascii() << std::endl; + QString msg2 = msg.section( ':', 1, 1 ); + msg2 = msg2.stripWhiteSpace(); +// KMessageBox::sorry( 0, QString("subject: "+msg), QString("foo"),0 ); + SmartcardCertsFromSlot.append( msg2 ); + Pkcs11CertFound=false; + } + } + } + +} + +void Utils::readOutGetCertsFromCiscoCertStoreSlot() +{ + while ( GetCertsFromCiscoCertStoreProcess->canReadLineStdout() ) { + QString msg = QString( GetCertsFromCiscoCertStoreProcess->readLineStdout() ); + +// samle output :( + +// Cisco Systems VPN Client Version 4.8.00 (0490) +// Copyright (C) 1998-2005 Cisco Systems, Inc. All Rights Reserved. +// Client Type(s): Linux +// Running on: Linux 2.6.22-2-686 #1 SMP Fri Aug 31 00:24:01 UTC 2007 i686 +// +// +// Cert # Common Name +// ------- ------------ +// +// 0 crissi + +// if (config->KvpncDebugLevel > 2) +// std::cout << "readOutGetCertsFromCiscoCertStoreSlot: " << msg << std::endl; + + if (msg.find("Cert #",0,FALSE) > -1) + CertsFromCiscoCertPos=1; + if (CertsFromCiscoCertPos==1 || CertsFromCiscoCertPos ==2 | CertsFromCiscoCertPos ==3) + { + CertsFromCiscoCertPos++; + continue; + } + else if (CertsFromCiscoCertPos>=4) + { + if (msg.length() > 2) + { + // " 0 crissi " + int idx=0; // first non space => 0 + int idx2=0; // second nonspace => c + for (idx=0;idx<(int)msg.length();idx++) + if (!msg.at(idx).isSpace()) + break; + +// if (config->KvpncDebugLevel > 2) +// std::cout << "readOutGetCertsFromCiscoCertStoreSlot: idx " << idx << std::endl; + + for (idx2=idx+1;idx2<(int)msg.length();idx2++) + if (!msg.at(idx2).isSpace()) + break; +// if (config->KvpncDebugLevel > 2) +// std::cout << "readOutGetCertsFromCiscoCertStoreSlot: idx2 " << idx2 << std::endl; + QString common_name = msg.right(msg.length()-idx2); + if (common_name.length() > 0) + { +// if (config->KvpncDebugLevel > 2) +// std::cout << "readOutGetCertsFromCiscoCertStoreSlot => cert " << common_name << std::endl; + CertsFromCiscoCertStore.append( common_name ); + } + } + } + } +} + +void Utils::readOutGetOpenvpnPkcs11Ids() +{ + while ( OpenvpnPkcs11IdsProcess->canReadLineStdout() ) + { + QString msg = QString( OpenvpnPkcs11IdsProcess->readLineStdout() ); + + /* + sample output: + Serial:         21 + Serialized id: + OpenSC\x20Project/PKCS\x20\x2315\x20SCard/2322222222222222/OpenSC\x20Card\x20\x28User1\x20Name22\x29/45 + */ + + if (config->KvpncDebugLevel > 5) + config->appendLogEntry ( QString("[readOutGetOpenvpnPkcs11Ids] "+QString(msg)) ,config->debug ); + +// KMessageBox::information( 0, i18n( "msg: %1" ).arg( msg ), QString("foo") ); + if ( msg.contains( "Serialized id:" )) + { + //std::cout << msg.ascii() << std::endl; + QString msg2 = msg.section( ':', 1, 1 ); + msg2 = msg2.stripWhiteSpace(); +// KMessageBox::sorry( 0, QString("id: "+msg), QString("foo"),0 ); + OpenvpnPkcs11Ids.append( msg2 ); + } + } +} + +void Utils::readOutNeedsPassphrase() +{ + while ( NeedsPassphraseProcess->canReadLineStdout() ) { + QString msg = QString( NeedsPassphraseProcess->readLineStdout() ); +// KMessageBox::sorry( 0, QString("msg: "+msg), QString("foo1"),0 ); + if ( msg.contains( "unable to load Private Key" ) ) { + needsPassphrase=true; + } + } + +} + +void Utils::readStdOutGetHostname() +{ + while ( GetHostnameProcess->canReadLineStdout() ) { + QString msg = QString( GetHostnameProcess->readLineStdout() ).simplifyWhiteSpace().section(' ',0,0); +// KMessageBox::sorry( 0, QString("msg: "+msg), QString("foo1"),0 ); + if (!msg.isEmpty()) + Hostname=msg; + } +} + +void Utils::readStdErrGetHostname() +{ + while ( GetHostnameProcess->canReadLineStderr() ) { + QString msg = QString( GetHostnameProcess->readLineStderr() ); + KMessageBox::error( 0, QString(msg), QString("getHostname()"),0 ); + } +} + +QString Utils::dec2bin(int n) +{ + if (0 == n) + { + return "0"; + } + else + { + QString ret =""; + QString ret2 = dec2bin(n/2); + ret+= ret2; + if(n % 2) + ret +="1"; + else + ret+= "0"; + return ret; + } +} + +int Utils::dottedIpv4Netmask2NetmaskBytes(QString dottedIpv4Netmask) +{ + if (dottedIpv4Netmask.isEmpty() || dottedIpv4Netmask.contains( '.' ) != 3) + return 0; + int byteSetCount =0; + int part0 = dottedIpv4Netmask.section( '.', 0, 0 ).toInt(); + int part1 = dottedIpv4Netmask.section( '.', 1, 1 ).toInt(); + int part2 = dottedIpv4Netmask.section( '.', 2, 2 ).toInt(); + int part3 = dottedIpv4Netmask.section( '.', 3, 3 ).toInt(); + + std::cout << "part0: " << part0 << std::endl; + std::cout << "part1: " << part1 << std::endl; + std::cout << "part2: " << part2 << std::endl; + std::cout << "part3: " << part3 << std::endl; + QString block=""; + QString block0 = dec2bin(part0); + QString block1 = dec2bin(part1); + QString block2 = dec2bin(part2); + QString block3 = dec2bin(part3); + + std::cout << "block0: " << block0 << std::endl; + std::cout << "block1: " << block1 << std::endl; + std::cout << "block2: " << block2 << std::endl; + std::cout << "block3: " << block3 << std::endl; + block = block0 + block1 +block2 + block3; + std::cout << "block: " << block.ascii() << std::endl; + + for (int i=0; i< 31;i++) + { + if (block.mid(i,1) == "1") + byteSetCount++; + } + return byteSetCount; +} diff --git a/src/utils.h b/src/utils.h new file mode 100644 index 0000000..50492e0 --- /dev/null +++ b/src/utils.h @@ -0,0 +1,202 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef __UTILS_H____ +#define __UTILS_H____ + +#include +#include +#include +#include "kvpncconfig.h" +#include "kvpnc.h" +#include "toolinfo.h" +#include +#include + +/** +Provides various help functions. + +@author Christoph Thielecke +*/ +class Utils : public QObject +{ + Q_OBJECT +public: + Utils(KVpncConfig* config,QObject *parent = 0, const char *name = 0); + + ~Utils(); + + bool isValidIPv4Address(QString Address); + bool isValidIPv4NetworkAddress(QString Address); + bool isValidIPv4BroadcastAddress(QString Address); + bool isValidIPv4Netmask(QString Netmask); + bool tunDevExists(); + bool createTunDev(); + bool loadKernelModule(QString Name,QApplication *app); + bool unloadKernelModule(QString Name,QApplication *app, bool force=true); + bool doChmod(QString file, QString mode); + bool resolvConfAvailable(); + QStringList getOpenvpnCiphers(); + QStringList getOpenvpnDigests(); + QPtrList* getToolList(); + ToolInfo* getToolInfo( QString name); + QString resolveName(QString Name); + QString removeSpecialCharsForFilename(QString filename); + QString getNameAndPidOfProgramListen(int port); + QString getEmailAddressOfCert(QString cert); + QString getHostname(); + QStringList getSmartcardSlots(QString ProviderLib); + QStringList getSmartcardCertsFromSlot(QString slot,QString IdType,QString ProviderLib); + QStringList getOpenvpnPkcs11Ids(QString ProviderLib); + bool getNeedsPassphrase(QString key); + QStringList getCertsFromCiscoCertStore(QString type="user"); + QString dec2bin(int n); + int dottedIpv4Netmask2NetmaskBytes(QString dottedIpv4Netmask); + QString IpsecAlgoCurrent; + struct IpsecAlgos { + QStringList IpsecIkeEncryptionAlgorithms; + QStringList IpsecIkeHashAlgorithms; + QStringList IpsecIkeDhGroups; + QStringList IpsecEspEncryptionAlgorithms; + QStringList IpsecEspAuthenticationAlgorithms; + QStringList IpsecCompressionAlgorithms; + }; + + struct PppdCapabilities { + bool pppdHasMppeRequiredSupport; + bool pppdHasRequireMppeSupport; + bool pppdHasReplacedefaultrouteSupport; + + /* options for pppd depending on pppd version */ + + // MPPE + QString RequireMppeOption; + QString Require128BitMppeOption; + QString RefuseMppeOption; + QString Refuse40BitMppeOption; + QString Refuse128BitMppeOption; + QString RequireStatelessOption; + QString RequireStatefulOption; + bool MppeOptionsInALine; // older pppd need all in one line + + // AUTH + QString RequireAuthChapOption; + QString RequireAuthMschapOption; + QString RequireAuthMschapv2Option; + QString RequireAuthPapOption; + + bool pppdHasMppeSupport; //< true if pppd has mppe support + bool oldPppdStyle; //< true if old style was found ('mppe require') + bool pppdOk; // if pppd could started + }; + + struct IpsecAlgos getKernelCrypto(); + struct IpsecAlgos getIpsecAlgos(); + struct PppdCapabilities checkPppdCapabilities(); + +public slots: + void readStdOutCreateTunDev(); + void readStdErrCreateTunDev(); + void readStdOutLoadKernelModule(); + void readStdErrLoadKernelModule(); + void readStdOutToolsTest(); + void readStdErrToolsTest(); + void readStdOutRetriveOpenvpnCiphers(); + void readStdErrRetriveOpenvpnCiphers(); + void readStdOutRetriveIpsecAlgos(); + void readStdErrRetriveIpsecAlgos(); + void readStdOutRetriveOpenvpnDigests(); + void readStdErrRetriveOpenvpnDigests(); + void readStdOutGetNameAndPidOfProgramListen(); + void readStdErrGetNameAndPidOfProgramListen(); + void readOutGetEmailAddressOfCert(); + void readOutGetSmartcardSlots(KProcess * proc, char * buffer, int buflen); + void readOutGetSmartcardCertsFromSlot(); + void readOutGetOpenvpnPkcs11Ids(); + void readOutNeedsPassphrase(); + void readOutGetCertsFromCiscoCertStoreSlot(); + void readPppdtestProcessOutput(); + void readStdOutGetHostname(); + void readStdErrGetHostname(); + + +private: + bool modprobeSuccess; + bool toolsTestSuccess; + bool retrieveOpenvpnCiphers; + bool retrieveOpenvpnDigests; + bool retrieveIpsecAlgos; + bool retrieveNameAndPidOfProgramListen; + bool retrieveHotsname; + bool needsPassphrase; + bool testPppdReplacedefaultroute; + bool testPppdRequireMppe128; + bool testPppdMppeRequiredSupport; + bool testPppdNomppeStatefulSupport; + bool testPppdStatelessSupport; + bool testOldPppdStyle; + bool testPppdRequireMppe; + bool testPppdMppeRequired; + + QString tooltest_logfile; + QProcess *ModprobeProcess; + QProcess *createProcess; + QProcess *NetworkDeviceTestProcess; + QProcess *toolsTestProcess; + QProcess *OpenvpnCiphersProcess; + QProcess *OpenvpnDigestProcess; + QProcess *NameAndPidOfProgramListenProcess; + QProcess *GetEmailAddressOfCertProcess; + KProcess *GetSmartcardSlotsProcess; + QProcess *GetSmartcardCertsFromSlotProcess; + QProcess *OpenvpnPkcs11IdsProcess; + QProcess *GetCertsFromCiscoCertStoreProcess; + QProcess *NeedsPassphraseProcess; + QProcess *IpsecAlgosProcess; + QProcess *TestPppdProcess; + QProcess *GetHostnameProcess; + + QString resolvedIP; + bool resolveFinished; + QValueList list; + QStringList *env; + KVpncConfig *config; + KTempFile *tmpfile; + bool retrieveValidNetworkdevice; + bool Pkcs11CertFound; + QStringList OpenvpnCiphers; + QStringList OpenvpnDigests; + QStringList KernelCrypto; + QString NameAndPidOfProgramListen; + QString EmailAddressOfCert; + QString OpenvpnDigestString; + QString IdType; + QString Hostname; + QStringList SmartcardSlots; + QStringList SmartcardCertsFromSlot; + QStringList CertsFromCiscoCertStore; + QStringList OpenvpnPkcs11Ids; + + int CertsFromCiscoCertPos; + int ListenPort; + int OpenvpnDigestCount; + PppdCapabilities pppdcap; +}; + +#endif diff --git a/src/vpnaccountdata.cpp b/src/vpnaccountdata.cpp new file mode 100644 index 0000000..44db7e8 --- /dev/null +++ b/src/vpnaccountdata.cpp @@ -0,0 +1,2291 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "vpnaccountdata.h" + +VpnAccountData::VpnAccountData( ConnectionType ConnType,const QString& Name) +{ + this->RemoteNetAddr = ""; + this->RemoteNetMask = "24"; + this->CertPath = ""; + this->doPingIP = false; + this->pingHostIP = ""; + this->PrivateKeyPass=""; + this->PrivateKey=""; + this->NetworkDevice=""; + this->connectiontype = ConnType; + this->Name = Name; + + Gateway=""; + ID=""; + Username=""; + UserPassword=""; + IkeGroup="modp2048"; + EncryptionAlgorithm="3des"; + AuthenticationAlgorithm="hmac_md5"; + PerfectForwardSecrecy=""; + NtDomainName=""; + ApplicationVersion=""; + RemoteNetAddr=""; + RemoteNetMask=""; + PreSharedKey=""; + x509Certificate=""; + CaCertificate=""; + NetworkDevice=""; + PrivateKeyPass=""; + PrivateKey=""; + CertPath=""; + AuthType=""; + pingHostIP=""; + SpecialRemoteID=""; + SpecialLocalID=""; + LocalIDType="asn1dn"; + RemoteIDType="none"; + LocalVirtualIP=""; + RemoteVirtualIP=""; + PreSharedKeyFile=""; + HashAlgo="md5"; + Description=""; + HttpProxyAuthType=""; + HttpProxyUser=""; + HttpProxyPass=""; + RightNextHop=""; + LeftNextHop=""; + AuthMethod="mschap-v2"; + TunnelDeviceType="tun"; + SearchDomainInResolvConf=""; + DomainInResolvConf=""; + AuthenticationDirection="none"; + CiscoNatMode="natt"; + IpsecEsp="3des-md5,3des-sha1,aes128-sha1,aes256-sha1"; + IpsecIke="aes256-sha1,aes128-sha1,3des-sha1-modp2048,3des-md5,3des-sha1"; + VtunProfile=""; + IpsecVpnMode="tunnel"; + LeftSourceIp=""; + RightSourceIp=""; + VirtualSubnetworks=""; + SshConfigRemoteScript=""; + saveUserPassword=false; + savePsk=false; + useAdvancedSettings=false; + useIkeGroup=false; + usePerfectForwardSecrety=false; + useNtDomainName=false; + useApplicationVersion=false; + useSingleDes=false; + useGlobalIpsecSecret=false; + doPingIP=false; + useSpecialRemoteID=false; + useSpecialLocalID=false; + useUdp=true; + useUdpPort=false; + useDnsServer=false; + DnsServer=""; + refuse40BitEncryption=true; + refuse128BitEncryption=false; + allowStatefulMode=false; + requireMppe=true; + useNoIpDefault=false; + disableMPPEComp=false; + executeCmdBeforeConnect=false; + executeCmdAfterConnect=false; + executeCmdBeforeDisconnect=false; + executeCmdAfterDisconnect=false; + CommandBeforeConnect=""; + CommandAfterConnect=""; + CommandBeforeDisconnect=""; + CommandAfterDisconnect=""; + useNoBsdComp=true; + useNoDeflate=true; + replaceDefaultRoute=true; + useMtu=false; + useMru=false; + useVirtualIP=false; + VirtualIP=""; + PskIsInFile=false; + useAdditionalNetworkRoutes=false; + useUserdefinedPort = false; + SpecialServerCertificate=""; + useSpecialServerCertificate=false; + TunnelDeviceType="tun"; + allowEmptyGroupPassword=false; + useReconnectDelay=false; + useHttpProxy=false; + PskIsInFile=false; + RemoteNetMask="24"; + RemoteNetAddr=""; + saveUserPassword=true; + savePsk=true; + useIkeGroup=false; + usePerfectForwardSecrety=false; + useNtDomainName=false; + useApplicationVersion=false; + useLocalPort=false; + useRemotePort=false; + useSingleDes=false; + useGlobalIpsecSecret=false; + doPingIP=false; + useSpecialRemoteID=false; + useSpecialLocalID=false; + useUdp=false; + useUdpPort=false; + useDnsServer=false; + refuse40BitEncryption=false; + refuse128BitEncryption=false; + allowStatefulMode=false; + requireMppe=true; + useNoIpDefault=false; + disableMPPEComp=false; + executeCmdBeforeConnect=false; + executeCmdAfterConnect=false; + executeCmdBeforeDisconnect=false; + executeCmdAfterDisconnect=false; + useNoBsdComp=false; + useNoDeflate=false; + useMtu=false; + useMru=false; + useVirtualIP=false; + PskIsInFile=false; + useAdditionalNetworkRoutes=false; + useSpecialServerCertificate=false; + useUserdefinedPort=false; + useNsCertType=false; + useConnectionStatusCheck=true; + doReconnectAfterConnectionLost=true; + disableLzoCompression=true; + authWithUsernameAndPassword=false; + allowEmptyGroupPassword=false; + useUserdefiniedCipher=false; + useRedirectGateway=false; + useTlsAuth=false; + useTlsRemoteHost=false; + dontSaveUsername=false; + disableLzoCompression=false; + disableOpportunisticEncryption=true; + useMssfix=false; + useFragment=false; + disableCcp=false; + useXauthInteractive=false; + savePrivateKeyPassword=false; + useHttpProxyAuth=false; + useOnlyCaCertAndUserAuth=false; + useMailAddressAsIdentifier=false; + useRightNextHop=false; + useLeftNextHop=false; + usePkcs11Providers=false; + allowEmptyPrivateKeyPassword=false; + useSmartcard=false; + allowIpAddressChangeOfPeer=false; + useSearchDomainInResolvConf=false; + useDomainInResolvConf=false; + disableDataEncryption=false; + useAuthenticationAlgorithm=false; + fixPathMtuDiscoveryProblem=true; + useRemoteNetwork=false; + disableHeaderCompression=false; + disableMagicNumberNegotiation=false; + disableIpx=false; + disableProtocolFieldCompression=false; + disableAdressControlCompression=false; + useCustomIke=false; + useCustomEsp=false; + verifyCaCert=true; + useDpdIdleTimeout=false; + hideGroupPasswordInAccountDataDialog=false; + usePerfectForwardSecrety=true; + useLeftSourceIp=false; + useRightSourceIp=false; + useVirtualSubnetworks=false; + disablePushFromServer=false; + disableBind=false; + useRenegSec=false; + useTunnelPing=false; + useTunnelPingRestart=false; + requireEap=false; + useSshConfigRemoteScript=false; + askUserPasswordOnEachConnect = false; + useCiscoCertStore = false; + useNat = true; + + PeerTimeout=60; + ReconnectDelay=5; + connectionStatusInterval=20; + Mtu=1500; + Mru=1500; + LocalPort=500; + RemotePort=500; + UserdefinedPort=10000; + UdpPort=4500; + HttpProxyPort=3128; + HttpProxyTimeout=100; + Mssfix=1300; + Fragment=1300; + CommandAfterConnectDelayTime=3; + DpdIdleTimeout = 300; + MaxConnectTries=3; + int RenegSec=3600; + int TunnelPing=10; + int TunnelPingRestart=120; + + L2tpDaemon=VpnAccountData::l2tpd; + +} + + +VpnAccountData::~VpnAccountData() +{} + +/* +VpnAccountData::VpnAccountData(const VpnAccountData& data) +{ + Name = data.Name; + Gateway = data.Gateway; + ID = data.ID; + Username = data.Username; + UserPassword = data.UserPassword; + IkeGroup = data.IkeGroup; + PerfectForwardSecrecy = data.PerfectForwardSecrecy; + EncryptionAlgorithm = data.EncryptionAlgorithm; + AuthenticationAlgorithm = data.AuthenticationAlgorithm; + NtDomainName = data.NtDomainName; + ApplicationVersion = data.ApplicationVersion; + RemoteNetAddr = data.RemoteNetAddr; + RemoteNetMask = data.RemoteNetMask; + PreSharedKey = data.PreSharedKey; + x509Certificate = data.x509Certificate; + CaCertificate = data.CaCertificate; + NetworkDevice = data.NetworkDevice; + PrivateKeyPass = data.PrivateKeyPass; + PrivateKey = data.PrivateKey; + CertPath = data.CertPath; + AuthType = data.AuthType; + pingHostIP = data.pingHostIP; + SpecialRemoteID = data.SpecialRemoteID; + SpecialLocalID = data.SpecialLocalID; + LocalIDType = data.LocalIDType; + LocalVirtualIP = data.LocalVirtualIP; + RemoteVirtualIP = data.RemoteVirtualIP; + PreSharedKeyFile = data.PreSharedKeyFile; + HashAlgo = data.HashAlgo; + UseUserdefiniedCipher = data.UseUserdefiniedCipher; + DnsServer = data.DnsServer; + CommandBeforeConnect= data.CommandBeforeConnect; + CommandAfterConnect= data.CommandAfterConnect; + CommandBeforeDisconnect= data.CommandBeforeDisconnect; + CommandAfterDisconnect= data.CommandAfterDisconnect; + Description = data.Description; + SpecialServerCertificate= data.SpecialServerCertificate; + VirtualIP = data.VirtualIP; + TunnelDeviceType = data.TunnelDeviceType; + NsCertType = data.NsCertType; + UserdefiniedCipher = data.UserdefiniedCipher; + TlsAuthFile= data.TlsAuthFile; + HttpProxy= data.HttpProxy; + ExchangeMode = data.ExchangeMode; + TlsRemoteHost= data.TlsRemoteHost; + RightNextHop = data.RightNextHop; + LeftNextHop = data.LeftNextHop; + HttpProxyAuthType= data.HttpProxyAuthType; + HttpProxyUser= data.HttpProxyUser; + HttpProxyPass= data.HttpProxyPass; + Pkcs11Providers= data.Pkcs11Providers; + Pkcs11SlotType= data.Pkcs11SlotType; + Pkcs11Slot= data.Pkcs11Slot; + Pkcs11IdType= data.Pkcs11IdType; + Pkcs11Id= data.Pkcs11Id; + Pkcs11SignMode= data.Pkcs11SignMode; + AuthMethod = data.AuthMethod; + SearchDomainInResolvConf= data.SearchDomainInResolvConf; + DomainInResolvConf= data.DomainInResolvConf; + AuthenticationDirection = data.AuthenticationDirection; + CiscoNatMode= data.CiscoNatMode; + IpsecEsp= data.IpsecEsp; + IpsecIke= data.IpsecIke; + AdditionalNetworkRoutes= data.QStringList AdditionalNetworkRoutes; + saveUserPassword = data.saveUserPassword; + savePsk = data.savePsk; + useAdvancedSettings = data.useAdvancedSettings; + useIkeGroup = data.useIkeGroup; + usePerfectForwardSecrety = data.usePerfectForwardSecrety; + useNtDomainName = data.useNtDomainName; + useApplicationVersion = data.useApplicationVersion; + useLocalPort = data.useLocalPort; + useRemotePort = data.useRemotePort; + useSingleDes = data.useSingleDes; + useGlobalIpsecSecret = data.useGlobalIpsecSecret; + doPingIP = data.doPingIP; + useSpecialRemoteID = data.useSpecialRemoteID; + useSpecialLocalID = data.useSpecialLocalID; + useUdp = data.useUdp; + useUdpPort = data.useUdpPort; + useDnsUpdate = data.useDnsUpdate; + useDnsServer = data.useDnsServer; + refuse40BitEncryption = data.refuse40BitEncryption; + refuse128BitEncryption = data.refuse128BitEncryption; + allowStatefulMode= data.allowStatefulMode; + requireMppe = data.requireMppe; + useNoIpDefault= data.useNoIpDefault; + disableMPPEComp= data.disableMPPEComp; + executeCmdBeforeConnect= data.executeCmdBeforeConnect; + executeCmdAfterConnect= data.executeCmdAfterConnect; + executeCmdBeforeDisconnect= data.executeCmdBeforeDisconnect; + executeCmdAfterDisconnect= data.executeCmdAfterDisconnect; + useNoBsdComp= data.useNoBsdComp; + useNoDeflate= data.useNoDeflate; + replaceDefaultRoute = data.replaceDefaultRoute; + useMtu= data.useMtu; + useMru= data.useMru; + useVirtualIP = data.useVirtualIP; + PskIsInFile = data.PskIsInFile; + useAdditionalNetworkRoutes= data.useAdditionalNetworkRoutes; + useSpecialServerCertificate= data.useSpecialServerCertificate; + useUserdefinedPort= data.useUserdefinedPort; + useNsCertType = data.useNsCertType; + useConnectionStatusCheck = data.useConnectionStatusCheck; + doReconnectAfterConnectionLost= data.doReconnectAfterConnectionLost; + disableLzoCompression= data.disableLzoCompression; + authWithUsernameAndPassword = data.authWithUsernameAndPassword; + allowEmptyGroupPassword = data.allowEmptyGroupPassword; + useUserdefiniedCipher= data.useUserdefiniedCipher; + useRedirectGateway= data.useRedirectGateway; + useTlsAuth = data.useTlsAuth; + useHttpProxy= data.useHttpProxy; + dontSaveUsername= data.dontSaveUsername; + useModeConfig= data.useModeConfig; + useReconnectDelay= data.useReconnectDelay; + useTlsRemoteHost= data.useTlsRemoteHost; + disableOpportunisticEncryption= data.disableOpportunisticEncryption; + useMssfix= data.useMssfix; + useFragment= data.useFragment; + disableCcp= data.disableCcp; + useSmartcard= data.useSmartcard; + useXauthInteractive= data.useXauthInteractive; + savePrivateKeyPassword= data.savePrivateKeyPassword; + useHttpProxyAuth= data.useHttpProxyAuth; + useOnlyCaCertAndUserAuth = data.useOnlyCaCertAndUserAuth; + useMailAddressAsIdentifier = data.useMailAddressAsIdentifier; + useRightNextHop= data.useRightNextHop; + useLeftNextHop= data.useLeftNextHop; + usePkcs11Providers= data.usePkcs11Providers; + allowEmptyPrivateKeyPassword= data.allowEmptyPrivateKeyPassword; + allowIpAddressChangeOfPeer= data.allowIpAddressChangeOfPeer; + useSearchDomainInResolvConf= data.useSearchDomainInResolvConf; + useDomainInResolvConf= data.useDomainInResolvConf; + Mtu= data.Mtu; + Mru= data.Mru; + UdpPort = data.UdpPort; + LocalPort = data.LocalPort; + RemotePort = data.RemotePort; + UserdefinedPort= data.UserdefinedPort; + connectionStatusCheckSuccessCount = data.connectionStatusCheckSuccessCount; + connectionStatusInterval = data.connectionStatusInterval; + HttpProxyPort= data.HttpProxyPort; + HttpProxyTimeout= data.HttpProxyTimeout; + ReconnectDelay= data.ReconnectDelay; + Mssfix= data.Mssfix; + Fragment= data.Fragment; + PeerTimeout = data.PeerTimeout; + CommandAfterConnectDelayTime = data.CommandAfterConnectDelayTime; +} +*/ + +QString VpnAccountData::getName() const +{ + return Name; +} + +VpnAccountData::ConnectionType VpnAccountData::getConnectionType() const +{ + return connectiontype; +} + +QString VpnAccountData::getGateway() const +{ + return Gateway; +} + +QString VpnAccountData::getID() const +{ + return ID; +} + +QString VpnAccountData::getTunnelDeviceType() const +{ + return TunnelDeviceType; +} + +QString VpnAccountData::getUserName() const +{ + return Username; +} + +QString VpnAccountData::getUserPassword() const +{ + return UserPassword; +} + +bool VpnAccountData::getSaveUserPassword() const +{ + return saveUserPassword; +} + +bool VpnAccountData::getSavePsk() const +{ + return savePsk; +} + +QString VpnAccountData::getIkeGroup() const +{ + return IkeGroup; +} + +QString VpnAccountData::getEncryptionAlgorithm() const +{ + return EncryptionAlgorithm; +} + +QString VpnAccountData::getAuthenticationAlgorithm() const +{ + return AuthenticationAlgorithm; +} + +QString VpnAccountData::getPerfectForwardSecrety() const +{ + return PerfectForwardSecrecy; +} + +QString VpnAccountData::getNtDomainName() const +{ + return NtDomainName; +} + +QString VpnAccountData::getApplicationVersion() const +{ + return ApplicationVersion; +} + +bool VpnAccountData::getUseSingleDes() const +{ + return useSingleDes; + +} + +bool VpnAccountData::getUseIkeGroup() const +{ + return useIkeGroup; +} + +bool VpnAccountData::getUsePerfectForwardSecrety() const +{ + return usePerfectForwardSecrety; +} + +bool VpnAccountData::getUseNtDomainName() const +{ + return useNtDomainName; +} + +bool VpnAccountData::getUseApplicationVersion() const +{ + return useApplicationVersion; +} + +bool VpnAccountData::getUseLocalPort() const +{ + return useLocalPort; +} + +bool VpnAccountData::getUseRemotePort() const +{ + return useRemotePort; +} + +bool VpnAccountData::getUseAdvancedSettings() const +{ + return useAdvancedSettings; +} + +bool VpnAccountData::getUseGlobalIpsecSecret() const +{ + return useGlobalIpsecSecret; +} + +int VpnAccountData::getLocalPort() const +{ + return LocalPort; +} + +int VpnAccountData::getRemotePort() const +{ + return RemotePort; +} + +QString VpnAccountData::getRemoteNetAddr() const +{ + return RemoteNetAddr; +} + +QString VpnAccountData::getRemoteNetMask() const +{ + return RemoteNetMask; +} + +QString VpnAccountData::getPreSharedKey() const +{ + return PreSharedKey; +} + +QString VpnAccountData::getX509Certificate() const +{ + return x509Certificate; +} + +QString VpnAccountData::getCaCertificate() const +{ + return CaCertificate; +} + +QString VpnAccountData::getNetworkDevice() const +{ + if (NetworkDevice != QString::null) + return NetworkDevice; + else + return ""; +} + +QString VpnAccountData::getCertPath() const +{ + return CertPath; +} + +VpnAccountData::AuthenticationType VpnAccountData::getAuthType() const +{ + return authtype; +} + +bool VpnAccountData::getDoPingIP() const +{ + return doPingIP; +} + +QString VpnAccountData::getPingHostIP() const +{ + return pingHostIP; +} + +QString VpnAccountData::getPrivateKeyPass() const +{ + return PrivateKeyPass; +} + +QString VpnAccountData::getPrivateKey() const +{ + return PrivateKey; +} + +bool VpnAccountData::getUseSpecialRemoteID() const +{ + return useSpecialRemoteID; +} + +bool VpnAccountData::getUseSpecialLocalID() const +{ + return useSpecialLocalID; +} + +QString VpnAccountData::getSpecialRemoteID() const +{ + return SpecialRemoteID; +} + +QString VpnAccountData::getSpecialLocalID() const +{ + return SpecialLocalID; +} + +QString VpnAccountData::getLocalIDType() const +{ + return LocalIDType; +} + +QString VpnAccountData::getRemoteIDType() const +{ + return RemoteIDType; +} + +bool VpnAccountData::getUseUdp() const +{ + return useUdp; +} + +bool VpnAccountData::getUseUdpPort() const +{ + return useUdpPort; +} + +int VpnAccountData::getUdpPort() const +{ + return UdpPort; +} + +bool VpnAccountData::getUseDnsUpdate() const +{ + return useDnsUpdate; +} + +bool VpnAccountData::getUseDnsServer() const +{ + return useDnsServer; +} + +QString VpnAccountData::getDnsServer() const +{ + return DnsServer; +} + +bool VpnAccountData::getRefuse40BitEncryption() const +{ + return refuse40BitEncryption; +} + +bool VpnAccountData::getRefuse128BitEncryption() const +{ + return refuse128BitEncryption; +} + +bool VpnAccountData::getAllowStatefulMode() const +{ + return allowStatefulMode; +} + +bool VpnAccountData::getRequireMppe() const +{ + return requireMppe; +} + +bool VpnAccountData::getUseNoIpDefault() const +{ + return useNoIpDefault; +} + +bool VpnAccountData::getDisableMPPEComp() const +{ + return disableMPPEComp; +} + +bool VpnAccountData::getUseSpecialServerCertificate() const +{ + return useSpecialServerCertificate; +} + +QString VpnAccountData::getSpecialServerCertificate() const +{ + return SpecialServerCertificate; +} + +QString VpnAccountData::getLocalVirtualIP() const +{ + return LocalVirtualIP; +} + +QString VpnAccountData::getRemoteVirtualIP() const +{ + return RemoteVirtualIP; +} + +QString VpnAccountData::getPreSharedKeyFile() const +{ + return PreSharedKeyFile; +} + +bool VpnAccountData::getExecuteCmdBeforeConnect() const +{ + return executeCmdBeforeConnect; +} + +bool VpnAccountData::getExecuteCmdAfterConnect() const +{ + return executeCmdAfterConnect; +} + +bool VpnAccountData::getExecuteCmdBeforeDisconnect() const +{ + return executeCmdBeforeDisconnect; +} + +bool VpnAccountData::getExecuteCmdAfterDisconnect() const +{ + return executeCmdAfterDisconnect; +} + +QString VpnAccountData::getCommandBeforeConnect() const +{ + return CommandBeforeConnect; +} + +QString VpnAccountData::getCommandAfterConnect() const +{ + return CommandAfterConnect; +} + +QString VpnAccountData::getCommandBeforeDisconnect() const +{ + return CommandBeforeDisconnect; +} + +QString VpnAccountData::getCommandAfterDisconnect() const +{ + return CommandAfterDisconnect; +} + +bool VpnAccountData::getUseNoBsdComp() const +{ + return useNoBsdComp; +} + +bool VpnAccountData::getUseNoDeflate() const +{ + return useNoDeflate; +} + +bool VpnAccountData::getReplaceDefaultRoute() const +{ + return replaceDefaultRoute; +} + +bool VpnAccountData::getUseMtu() const +{ + return useMtu; +} + +int VpnAccountData::getMtu() const +{ + return Mtu; +} + +bool VpnAccountData::getUseMru() const +{ + return useMru; +} + +int VpnAccountData::getMru() const +{ + return Mru; +} + +bool VpnAccountData::getUseVirtualIP() const +{ + return useVirtualIP; +} + +QString VpnAccountData::getVirtualIP() const +{ + return VirtualIP; +} + +bool VpnAccountData::getPskIsInFile() const +{ + return PskIsInFile; +} + +bool VpnAccountData::getUseAdditionalNetworkRoutes() const +{ + return useAdditionalNetworkRoutes; +} + +QStringList VpnAccountData::getAdditionalNetworkRoutes() const +{ + return AdditionalNetworkRoutes; +} + +QString VpnAccountData::getHashAlgo() const +{ + return HashAlgo; +} + +bool VpnAccountData::getUseUserdefinedPort() const +{ + return useUserdefinedPort; +} + +int VpnAccountData::getUserdefinedPort() const +{ + return UserdefinedPort; +} + +QString VpnAccountData::getDescription() const +{ + return Description; +} + +QString VpnAccountData::getNsCertType() const +{ + return NsCertType; +} + +bool VpnAccountData::getUseNsCertType() const +{ + return useNsCertType; +} + +bool VpnAccountData::getUseConnectionStatusCheck() const +{ + return useConnectionStatusCheck; +} + +int VpnAccountData::getConnectionStatusCheckSuccessCount() const +{ + return connectionStatusCheckSuccessCount; +} + +int VpnAccountData::getConnectionStatusInterval() const +{ + return connectionStatusInterval; +} + +bool VpnAccountData::getDoReconnectAfterConnectionLost() const +{ + return doReconnectAfterConnectionLost; +} + +bool VpnAccountData::getDisableLzoCompression() const +{ + return disableLzoCompression; +} + +bool VpnAccountData::getAuthWithUsernameAndPassword() const +{ + return authWithUsernameAndPassword; +} + +bool VpnAccountData::getAllowEmptyGroupPassword() const +{ + return allowEmptyGroupPassword; +} + +bool VpnAccountData::getUseUserdefiniedCipher() const +{ + return useUserdefiniedCipher; +} + +QString VpnAccountData::getUserdefiniedCipher() const +{ + return UserdefiniedCipher; +} + +bool VpnAccountData::getUseRedirectGateway() const +{ + return useRedirectGateway; +} + +bool VpnAccountData::getUseTlsAuth() const +{ + return useTlsAuth; +} + +QString VpnAccountData::getTlsAuthFile() const +{ + return TlsAuthFile; +} + +QString VpnAccountData::getHttpProxy() const +{ + return HttpProxy; +} + +bool VpnAccountData::getUseHttpProxy() const +{ + return useHttpProxy; +} + +int VpnAccountData::getHttpProxyPort() const +{ + return HttpProxyPort; +} + +int VpnAccountData::getHttpProxyTimeout() const +{ + return HttpProxyTimeout; +} + +bool VpnAccountData::getDontSaveUsername() const +{ + return dontSaveUsername; +} + +bool VpnAccountData::getUseModeConfig() const +{ + return useModeConfig; +} + +QString VpnAccountData::getExchangeMode() const +{ + return ExchangeMode; +} + +bool VpnAccountData::getUseReconnectDelay() const +{ + return useReconnectDelay; +} + +int VpnAccountData::getReconnectDelay() const +{ + return ReconnectDelay; +} + +bool VpnAccountData::getUseTlsRemoteHost() const +{ + return useTlsRemoteHost; +} + +QString VpnAccountData::getTlsRemoteHost() const +{ + return TlsRemoteHost; +} + +QString VpnAccountData::getRightNextHop() const +{ + return RightNextHop; +} + +QString VpnAccountData::getLeftNextHop() const +{ + return LeftNextHop; +} + +bool VpnAccountData::getDisableOpportunisticEncryption() const +{ + return disableOpportunisticEncryption; +} + +bool VpnAccountData::getUseMssfix() const +{ + return useMssfix; +} + +bool VpnAccountData::getUseFragment() const +{ + return useFragment; +} + +int VpnAccountData::getMssfix() const +{ + return Mssfix; +} + +int VpnAccountData::getFragment() const +{ + return Fragment; +} + +int VpnAccountData::getPeerTimeout() const +{ + return PeerTimeout; +} + +bool VpnAccountData::getDisableCcp() const +{ + return disableCcp; +} + +bool VpnAccountData::getUseSmartcard() const +{ + return useSmartcard; +} + +bool VpnAccountData::getUseXauthInteractive() const +{ + return useXauthInteractive; +} + +bool VpnAccountData::getSavePrivateKeyPassword() const +{ + return savePrivateKeyPassword; +} + +bool VpnAccountData::getUseHttpProxyAuth() const +{ + return useHttpProxyAuth; +} + +QString VpnAccountData::getHttpProxyAuthType() const +{ + return HttpProxyAuthType; +} + +QString VpnAccountData::getHttpProxyUser() const +{ + return HttpProxyUser; +} + +QString VpnAccountData::getHttpProxyPass() const +{ + return HttpProxyPass; +} + +bool VpnAccountData::getUseOnlyCaCertAndUserAuth() const +{ + return useOnlyCaCertAndUserAuth; +} + +bool VpnAccountData::getUseMailAddressAsIdentifier() const +{ + return useMailAddressAsIdentifier; +} + +bool VpnAccountData::getUseRightNextHop() const +{ + return useRightNextHop; +} + +bool VpnAccountData::getUseLeftNextHop() const +{ + return useLeftNextHop; +} + +QString VpnAccountData::getPkcs11Providers() const +{ + return Pkcs11Providers; +} + +QString VpnAccountData::getPkcs11SlotType() const +{ + return Pkcs11SlotType; +} + +QString VpnAccountData::getPkcs11Slot() const +{ + return Pkcs11Slot; +} + +QString VpnAccountData::getPkcs11IdType() const +{ + return Pkcs11IdType; +} + +QString VpnAccountData::getPkcs11Id() const +{ + return Pkcs11Id; +} + +QString VpnAccountData::getPkcs11SignMode() const +{ + return Pkcs11SignMode; +} + +bool VpnAccountData::getUsePkcs11Providers() const +{ + return usePkcs11Providers; +} + +bool VpnAccountData::getAllowEmptyPrivateKeyPassword() const +{ + return allowEmptyPrivateKeyPassword; +} + +bool VpnAccountData::getAllowIpAddressChangeOfPeer() const +{ + return allowIpAddressChangeOfPeer; +} + +QString VpnAccountData::getAuthMethod() const +{ + return AuthMethod; +} + +int VpnAccountData::getCommandAfterConnectDelayTime() const +{ + return CommandAfterConnectDelayTime; +} + +bool VpnAccountData::getUseSearchDomainInResolvConf() const +{ + return useSearchDomainInResolvConf; +} + +bool VpnAccountData::getUseDomainInResolvConf() const +{ + return useDomainInResolvConf; +} + +QString VpnAccountData::getSearchDomainInResolvConf() const +{ + return SearchDomainInResolvConf; +} + +QString VpnAccountData::getDomainInResolvConf() const +{ + return DomainInResolvConf; +} + +QString VpnAccountData::getAuthenticationDirection() const +{ + return AuthenticationDirection; +} + +QString VpnAccountData::getCiscoNatMode() const +{ + return CiscoNatMode; +} + +QString VpnAccountData::getIpsecEsp() const +{ + return IpsecEsp; +} + +QString VpnAccountData::getIpsecIke() const +{ + return IpsecIke; +} + +QString VpnAccountData::getVtunProfile() const +{ + return VtunProfile; +} + +bool VpnAccountData::getDisableDataEncryption() const +{ + return disableDataEncryption; +} + +bool VpnAccountData::getUseAuthenticationAlgorithm() const +{ + return useAuthenticationAlgorithm; +} + +bool VpnAccountData::getFixPathMtuDiscoveryProblem() const +{ + return fixPathMtuDiscoveryProblem; +} + +bool VpnAccountData::getUseRemoteNetwork() const +{ + return useRemoteNetwork; +} + +QString VpnAccountData::getIpsecVpnMode() const +{ + return IpsecVpnMode; +} + +bool VpnAccountData::getDisableHeaderCompression() const +{ + return disableHeaderCompression; +} + +bool VpnAccountData::getDisableMagicNumberNegotiation() const +{ + return disableMagicNumberNegotiation; +} + +bool VpnAccountData::getDisableIpx() const +{ + return disableIpx; +} + +bool VpnAccountData::getDisableProtocolFieldCompression() const +{ + return disableProtocolFieldCompression; +} + +bool VpnAccountData::getDisableAdressControlCompression() const +{ + return disableAdressControlCompression; +} + +bool VpnAccountData::getUseCustomIke() const +{ + return useCustomIke; +} + +bool VpnAccountData::getUseCustomEsp() const +{ + return useCustomEsp; +} + +bool VpnAccountData::getVerifyCaCert() const +{ + return verifyCaCert; +} + +bool VpnAccountData::getUseDpdIdleTimeout() const +{ + return useDpdIdleTimeout; +} + +int VpnAccountData::getDpdIdleTimeout() const +{ + return DpdIdleTimeout; +} + +bool VpnAccountData::getHideGroupPasswordInAccountDataDialog() const +{ + return hideGroupPasswordInAccountDataDialog; +} + +int VpnAccountData::getMaxConnectTries() const +{ + return MaxConnectTries; +} + +VpnAccountData::L2tpDaemonType VpnAccountData::getL2tpDaemon() const +{ + return L2tpDaemon; +} + +bool VpnAccountData::getUseLeftSourceIp() const +{ + return useLeftSourceIp; +} + +bool VpnAccountData::getUseRightSourceIp() const +{ + return useRightSourceIp; +} + +QString VpnAccountData::getLeftSourceIp() const +{ + return LeftSourceIp; +} + +QString VpnAccountData::getRightSourceIp() const +{ + return RightSourceIp; +} + +bool VpnAccountData::getUseVirtualSubnetworks() const +{ + return useVirtualSubnetworks; +} + +QString VpnAccountData::getVirtualSubnetworks() const +{ + return VirtualSubnetworks; +} + +bool VpnAccountData::getDisablePushFromServer() const +{ + return disablePushFromServer; +} + +bool VpnAccountData::getDisableBind() const +{ + return disableBind; +} + +bool VpnAccountData::getUseRenegSec() const +{ + return useRenegSec; +} + +int VpnAccountData::getRenegSec() const +{ + return RenegSec; +} + +bool VpnAccountData::getUseTunnelPing() const +{ + return useTunnelPing; +} + +int VpnAccountData::getTunnelPing() const +{ + return TunnelPing; +} + +bool VpnAccountData::getUseTunnelPingRestart() const +{ + return useTunnelPingRestart; +} + +int VpnAccountData::getTunnelPingRestart() const +{ + return TunnelPingRestart; +} + +bool VpnAccountData::getRequireEap() const +{ + return requireEap; +} + +bool VpnAccountData::getUseSshConfigRemoteScript() const +{ + return useSshConfigRemoteScript; +} + +QString VpnAccountData::getSshConfigRemoteScript() const +{ + return SshConfigRemoteScript; +} + +bool VpnAccountData::getAskUserPasswordOnEachConnect() const +{ + return askUserPasswordOnEachConnect; +} + +bool VpnAccountData::getUseCiscoCertStore() const +{ + return useCiscoCertStore; +} + +bool VpnAccountData::getUseNat() const +{ + return useNat; +} + +/* set methods */ +void VpnAccountData::setConnectionType( ConnectionType type ) +{ + this->connectiontype = type; +} + +void VpnAccountData::setName( const QString &Name ) +{ + this->Name = Name; +} + +void VpnAccountData::setGateway( const QString &Gateway ) +{ + this->Gateway = Gateway; +} + +void VpnAccountData::setID( const QString &ID ) +{ + this->ID = ID; +} + +void VpnAccountData::setUserName( const QString &Username ) +{ + this->Username = Username; +} + +void VpnAccountData::setUserPassword( const QString& UserPassword ) +{ + this->UserPassword = UserPassword; +} + +void VpnAccountData::setSaveUserPassword( bool saveUserPassword ) +{ + this->saveUserPassword = saveUserPassword; +} + +void VpnAccountData::setSavePsk( bool savePsk ) +{ + this->savePsk = savePsk; +} + +void VpnAccountData::setIkeGroup( const QString &IkeGroup ) +{ + this->IkeGroup = IkeGroup; +} + +void VpnAccountData::setEncryptionAlgorithm( const QString &EncryptionAlgorithm ) +{ + this->EncryptionAlgorithm = EncryptionAlgorithm; +} + +void VpnAccountData::setAuthenticationAlgorithm( const QString &AuthenticationAlgorithm) +{ + this->AuthenticationAlgorithm= AuthenticationAlgorithm; +} + +void VpnAccountData::setPerfectForwardSecrety( const QString &PerfectForwardSecrecy ) +{ + this->PerfectForwardSecrecy = PerfectForwardSecrecy; +} + +void VpnAccountData::setNtDomainName( const QString& Name ) +{ + this->NtDomainName = Name; +} + +void VpnAccountData::setApplicationVersion( const QString& version ) +{ + this->ApplicationVersion = version; +} + +void VpnAccountData::setUseSingleDes( bool useSingleDes ) +{ + this->useSingleDes = useSingleDes; +} + +void VpnAccountData::setUseIkeGroup( bool useIkeGroup ) +{ + this->useIkeGroup = useIkeGroup; +} + +void VpnAccountData::setUsePerfectForwardSecrety( bool usePerfectForwardSecrety ) +{ + this->usePerfectForwardSecrety = usePerfectForwardSecrety; +} + +void VpnAccountData::setUseNtDomainName( bool useNtDomainName ) +{ + this->useNtDomainName = useNtDomainName; +} + +void VpnAccountData::setUseApplicationVersion( bool useApplicationVersion ) +{ + this->useApplicationVersion = useApplicationVersion; +} + +void VpnAccountData::setUseLocalPort( bool useLocalPort ) +{ + this->useLocalPort = useLocalPort; +} + +void VpnAccountData::setUseRemotePort( bool useRemotePort ) +{ + this->useRemotePort = useRemotePort; +} + +void VpnAccountData::setUseAdvancedSettings( bool useAdvancedSettings ) +{ + this->useAdvancedSettings = useAdvancedSettings; +} + +void VpnAccountData::setUseGlobalIpsecSecret( bool useGlobalIpsecSecret ) +{ + this->useGlobalIpsecSecret = useGlobalIpsecSecret; +} + +void VpnAccountData::setLocalPort( int port ) +{ + this->LocalPort = port; +} + +void VpnAccountData::setRemotePort( int port ) +{ + this->RemotePort = port; +} + +void VpnAccountData::setRemoteNetAddr( const QString& RemoteNetAddr ) +{ + this->RemoteNetAddr = RemoteNetAddr; +} + +void VpnAccountData::setRemoteNetMask( const QString& RemoteNetMask ) +{ + this->RemoteNetMask = RemoteNetMask; +} + +void VpnAccountData::setPreSharedKey( const QString& PreSharedKey ) +{ + this->PreSharedKey = PreSharedKey; +} + +void VpnAccountData::setX509Certificate( const QString& x509Certificate ) +{ + this->x509Certificate = x509Certificate; +} + +void VpnAccountData::setCaCertificate( const QString& CaCertificate ) +{ + this->CaCertificate = CaCertificate; +} + +void VpnAccountData::setNetworkDevice( const QString& NetworkDevice ) +{ + this->NetworkDevice = NetworkDevice; +} + +void VpnAccountData::setCertPath( const QString& CertPath ) +{ + this->CertPath = CertPath; +} + +void VpnAccountData::setAuthType( VpnAccountData::AuthenticationType authtype ) +{ + this->authtype = authtype; +} + +void VpnAccountData::setDoPingIP(bool doPingIP) +{ + this->doPingIP=doPingIP; +} + +void VpnAccountData::setPingHostIP(const QString& pingHostIP) +{ + this->pingHostIP = pingHostIP; +} + +void VpnAccountData::setPrivateKeyPass(const QString& PrivateKeyPass) +{ + this->PrivateKeyPass = PrivateKeyPass; +} + +void VpnAccountData::setPrivateKey(const QString& PrivateKey) +{ + this->PrivateKey = PrivateKey; +} + +void VpnAccountData::setUseSpecialRemoteID(bool useSpecialRemoteID) +{ + this->useSpecialRemoteID = useSpecialRemoteID; +} + +void VpnAccountData::setUseSpecialLocalID(bool useSpecialLocalID) +{ + this->useSpecialLocalID = useSpecialLocalID; +} + +void VpnAccountData::setSpecialRemoteID(const QString& SpecialRemoteID) +{ + this->SpecialRemoteID = SpecialRemoteID; +} + +void VpnAccountData::setSpecialLocalID(const QString& SpecialLocalID) +{ + this->SpecialLocalID = SpecialLocalID; +} + +void VpnAccountData::setLocalIDType(const QString& LocalIDType) +{ + this->LocalIDType = LocalIDType; +} + +void VpnAccountData::setRemoteIDType(const QString& RemoteIDType) +{ + this->RemoteIDType = RemoteIDType; +} + +void VpnAccountData::setUseUdp(bool useUdp) +{ + this->useUdp = useUdp; +} + +void VpnAccountData::setUseUdpPort(bool useUdpPort) +{ + this->useUdpPort = useUdpPort; +} + +void VpnAccountData::setUdpPort(int UdpPort) +{ + this->UdpPort = UdpPort; +} + +void VpnAccountData::setUseDnsUpdate(bool useDnsUpdate ) +{ + this->useDnsUpdate = useDnsUpdate; +} + +void VpnAccountData::setUseDnsServer(bool useDnsServer ) +{ + this->useDnsServer = useDnsServer; +} + +void VpnAccountData::setDnsServer(const QString& DnsServer ) +{ + this->DnsServer = DnsServer; +} + +void VpnAccountData::setRefuse40BitEncryption(bool refuse40BitEncryption ) +{ + this->refuse40BitEncryption = refuse40BitEncryption; +} + +void VpnAccountData::setRefuse128BitEncryption(bool refuse128BitEncryption ) +{ + this->refuse128BitEncryption = refuse128BitEncryption; +} + +void VpnAccountData::setAllowStatefulMode(bool allowStatefulMode ) +{ + this->allowStatefulMode = allowStatefulMode; +} + +void VpnAccountData::setRequireMppe(bool requireMppe ) +{ + this->requireMppe = requireMppe; +} + +void VpnAccountData::setUseNoIpDefault(bool useNoIpDefault ) +{ + this->useNoIpDefault = useNoIpDefault; +} + +void VpnAccountData::setDisableMPPEComp(bool disableMPPEComp ) +{ + this->disableMPPEComp = disableMPPEComp; +} + +void VpnAccountData::setLocalVirtualIP( const QString& LocalVirtualIP ) +{ + this->LocalVirtualIP = LocalVirtualIP; +} + +void VpnAccountData::setRemoteVirtualIP( const QString& RemoteVirtualIP ) +{ + this->RemoteVirtualIP = RemoteVirtualIP; +} + +void VpnAccountData::setPreSharedKeyFile( const QString& PreSharedKeyFile) +{ + this->PreSharedKeyFile = PreSharedKeyFile; +} + +void VpnAccountData::setExecuteCmdBeforeConnect(bool executeCmdBeforeConnect) +{ + this->executeCmdBeforeConnect = executeCmdBeforeConnect; +} + +void VpnAccountData::setExecuteCmdAfterConnect(bool executeCmdAfterConnect) +{ + this->executeCmdAfterConnect = executeCmdAfterConnect; +} + +void VpnAccountData::setExecuteCmdBeforeDisconnect( bool executeCmdBeforeDisconnect) +{ + this->executeCmdBeforeDisconnect = executeCmdBeforeDisconnect; +} + +void VpnAccountData::setExecuteCmdAfterDisconnect( bool executeCmdAfterDisconnect) +{ + this->executeCmdAfterDisconnect = executeCmdAfterDisconnect; +} + +void VpnAccountData::setCommandBeforeConnect(const QString& CommandBeforeConnect) +{ + this->CommandBeforeConnect = CommandBeforeConnect; +} + +void VpnAccountData::setCommandAfterConnect(const QString& CommandAfterConnect) +{ + this->CommandAfterConnect = CommandAfterConnect; +} + +void VpnAccountData::setCommandBeforeDisconnect(const QString& CommandBeforeDisconnect) +{ + this->CommandBeforeDisconnect = CommandBeforeDisconnect; +} + +void VpnAccountData::setCommandAfterDisconnect(const QString& CommandAfterDisconnect) +{ + this->CommandAfterDisconnect = CommandAfterDisconnect; +} + +void VpnAccountData::setUseNoBsdComp(bool useNoBsdComp) +{ + this->useNoBsdComp = useNoBsdComp; +} + +void VpnAccountData::setUseNoDeflate(bool useNoDeflate) +{ + this->useNoDeflate = useNoDeflate; +} + +void VpnAccountData::setReplaceDefaultRoute(bool replaceDefaultRoute) +{ + this->replaceDefaultRoute = replaceDefaultRoute; +} + +void VpnAccountData::setUseMtu(bool useMtu) +{ + this->useMtu = useMtu; +} + +void VpnAccountData::setMtu(int Mtu) +{ + this->Mtu = Mtu; +} + +void VpnAccountData::setUseMru(bool useMru) +{ + this->useMru = useMru; +} + +void VpnAccountData::setMru(int Mru) +{ + this->Mru = Mru; +} + +void VpnAccountData::setUseVirtualIP(bool useVirtualIP ) +{ + this->useVirtualIP = useVirtualIP; +} + +void VpnAccountData::setVirtualIP(const QString& VirtualIP ) +{ + this->VirtualIP = VirtualIP; +} + +void VpnAccountData::setPskIsInFile(bool PskIsInFile) +{ + this->PskIsInFile = PskIsInFile; +} + +void VpnAccountData::setUseAdditionalNetworkRoutes( bool useAdditionalNetworkRoutes ) +{ + this->useAdditionalNetworkRoutes = useAdditionalNetworkRoutes; +} + +void VpnAccountData::setAdditionalNetworkRoutes( QStringList AdditionalNetworkRoutes ) +{ + this->AdditionalNetworkRoutes = AdditionalNetworkRoutes; +} + +void VpnAccountData::setUseSpecialServerCertificate(bool useSpecialServerCertificate) +{ + this->useSpecialServerCertificate = useSpecialServerCertificate; +} + +void VpnAccountData::setSpecialServerCertificate(const QString& SpecialServerCertificate) +{ + this->SpecialServerCertificate = SpecialServerCertificate; +} + +void VpnAccountData::setHashAlgo(const QString& HashAlgo) +{ + this->HashAlgo = HashAlgo; +} + +void VpnAccountData::setTunnelDeviceType(const QString& TunnelDeviceType) +{ + this->TunnelDeviceType = TunnelDeviceType; +} + +void VpnAccountData::setUseUserdefinedPort(bool useUserdefinedPort) +{ + this->useUserdefinedPort = useUserdefinedPort; +} + +void VpnAccountData::setUserdefinedPort(int UserdefinedPort) +{ + this->UserdefinedPort = UserdefinedPort; +} + +void VpnAccountData::setDescription(const QString& Description) +{ + this->Description = Description; +} + +void VpnAccountData::setNsCertType(const QString& NsCertType) +{ + this->NsCertType = NsCertType; +} + +void VpnAccountData::setUseNsCertType(bool useNsCertType) +{ + this->useNsCertType = useNsCertType; +} + +void VpnAccountData::setUseConnectionStatusCheck(bool useConnectionStatusCheck) +{ + this->useConnectionStatusCheck=useConnectionStatusCheck; +} + +void VpnAccountData::setConnectionStatusCheckSuccessCount(int connectionStatusCheckSuccessCount) +{ + this->connectionStatusCheckSuccessCount=connectionStatusCheckSuccessCount; +} + +void VpnAccountData::setConnectionStatusInterval(int connectionStatusInterval) +{ + this->connectionStatusInterval=connectionStatusInterval; +} + +void VpnAccountData::setDoReconnectAfterConnectionLost( bool doReconnectAfterConnectionLost ) +{ + this->doReconnectAfterConnectionLost = doReconnectAfterConnectionLost; +} + +void VpnAccountData::setDisableLzoCompression(bool disableLzoCompression ) +{ + this->disableLzoCompression = disableLzoCompression; +} + +void VpnAccountData::setAuthWithUsernameAndPassword(bool authWithUsernameAndPassword ) +{ + this->authWithUsernameAndPassword = authWithUsernameAndPassword; +} + +void VpnAccountData::setAllowEmptyGroupPassword( bool allowEmptyGroupPassword ) +{ + this->allowEmptyGroupPassword = allowEmptyGroupPassword; +} + +void VpnAccountData::setUseUserdefiniedCipher( bool useUserdefiniedCipher ) +{ + this->useUserdefiniedCipher = useUserdefiniedCipher; +} + +void VpnAccountData::setUserdefiniedCipher( QString UserdefiniedCipher ) +{ + this->UserdefiniedCipher = UserdefiniedCipher; +} + +void VpnAccountData::setUseRedirectGateway( bool useRedirectGateway ) +{ + this->useRedirectGateway = useRedirectGateway; +} + +void VpnAccountData::setUseTlsAuth( bool useTlsAuth ) +{ + this->useTlsAuth = useTlsAuth; +} + +void VpnAccountData::setTlsAuthFile( QString TlsAuthFile ) +{ + this->TlsAuthFile = TlsAuthFile; +} + +void VpnAccountData::setHttpProxy( QString HttpProxy ) +{ + this->HttpProxy = HttpProxy; +} + +void VpnAccountData::setUseHttpProxy( bool useHttpProxy ) +{ + this->useHttpProxy = useHttpProxy; +} + +void VpnAccountData::setHttpProxyPort( int HttpProxyPort ) +{ + this->HttpProxyPort = HttpProxyPort; +} + +void VpnAccountData::setHttpProxyTimeout( int HttpProxyTimeout ) +{ + this->HttpProxyTimeout = HttpProxyTimeout; +} + +void VpnAccountData::setDontSaveUsername( bool dontSaveUsername) +{ + this->dontSaveUsername = dontSaveUsername; +} + +void VpnAccountData::setUseModeConfig( bool useModeConfig) +{ + this->useModeConfig = useModeConfig; +} + +void VpnAccountData::setExchangeMode( QString ExchangeMode ) +{ + this->ExchangeMode = ExchangeMode; +} + +void VpnAccountData::setUseReconnectDelay( bool useReconnectDelay ) +{ + this->useReconnectDelay = useReconnectDelay; +} + +void VpnAccountData::setReconnectDelay( int ReconnectDelay ) +{ + this->ReconnectDelay = ReconnectDelay; +} + +void VpnAccountData::setUseTlsRemoteHost( bool useTlsRemoteHost ) +{ + this->useTlsRemoteHost = useTlsRemoteHost; +} + +void VpnAccountData::setTlsRemoteHost( QString TlsRemoteHost ) +{ + this->TlsRemoteHost = TlsRemoteHost; +} + +void VpnAccountData::setRightNextHop( QString RightNextHop ) +{ + this->RightNextHop = RightNextHop; +} + +void VpnAccountData::setLeftNextHop( QString LeftNextHop ) +{ + this->LeftNextHop = LeftNextHop; +} + + void VpnAccountData::setDisableOpportunisticEncryption( bool disableOpportunisticEncryption ) +{ + this->disableOpportunisticEncryption = disableOpportunisticEncryption; +} + + void VpnAccountData::setUseMssfix( bool useMssfix ) +{ + this->useMssfix = useMssfix; +} + + void VpnAccountData::setUseFragment( bool useFragment) +{ + this->useFragment = useFragment; +} + + void VpnAccountData::setMssfix( int Mssfix) +{ + this->Mssfix = Mssfix; +} + + void VpnAccountData::setFragment( int Fragment) +{ + this->Fragment = Fragment; +} + +void VpnAccountData::setPeerTimeout( int PeerTimeout ) +{ + this->PeerTimeout = PeerTimeout; +} + +void VpnAccountData::setDisableCcp( bool disableCcp ) +{ + this->disableCcp = disableCcp; +} + +void VpnAccountData::setUseSmartcard( bool useSmartcard) +{ + this->useSmartcard = useSmartcard; +} + +void VpnAccountData::setUseXauthInteractive( bool useXauthInteractive) +{ + this->useXauthInteractive = useXauthInteractive; +} + +void VpnAccountData::setSavePrivateKeyPassword( bool savePrivateKeyPassword) +{ + this->savePrivateKeyPassword = savePrivateKeyPassword; +} + +void VpnAccountData::setUseHttpProxyAuth( bool useHttpProxyAuth ) +{ + this->useHttpProxyAuth = useHttpProxyAuth; +} + +void VpnAccountData::setHttpProxyAuthType(QString HttpProxyAuthType) +{ + this->HttpProxyAuthType = HttpProxyAuthType; +} + +void VpnAccountData::setHttpProxyUser(QString HttpProxyUser) +{ + this->HttpProxyUser = HttpProxyUser; +} + +void VpnAccountData::setHttpProxyPass( QString HttpProxyPass ) +{ + this->HttpProxyPass = HttpProxyPass; +} + +void VpnAccountData::setUseOnlyCaCertAndUserAuth(bool useOnlyCaCertAndUserAuth) +{ + this->useOnlyCaCertAndUserAuth = useOnlyCaCertAndUserAuth; +} + +void VpnAccountData::setUseMailAddressAsIdentifier(bool useMailAddressAsIdentifier ) +{ + this->useMailAddressAsIdentifier = useMailAddressAsIdentifier; +} + +void VpnAccountData::setUseRightNextHop( bool useRightNextHop ) +{ + this->useRightNextHop = useRightNextHop; +} + +void VpnAccountData::setUseLeftNextHop( bool useLeftNextHop ) +{ + this->useLeftNextHop = useLeftNextHop; +} + +void VpnAccountData::setPkcs11Providers( QString Pkcs11Providers) +{ + this->Pkcs11Providers = Pkcs11Providers; +} + +void VpnAccountData::setPkcs11SlotType(QString Pkcs11SlotType) +{ + this->Pkcs11SlotType = Pkcs11SlotType; +} + +void VpnAccountData::setPkcs11Slot(QString Pkcs11Slot) +{ + this->Pkcs11Slot = Pkcs11Slot; +} + +void VpnAccountData::setPkcs11IdType(QString Pkcs11IdType) +{ + this->Pkcs11IdType = Pkcs11IdType; +} + +void VpnAccountData::setPkcs11Id(QString Pkcs11Id) +{ + this->Pkcs11Id = Pkcs11Id; +} + +void VpnAccountData::setPkcs11SignMode(QString Pkcs11SignMode) +{ + this->Pkcs11SignMode = Pkcs11SignMode; +} + +void VpnAccountData::setUsePkcs11Providers(bool usePkcs11Providers) +{ + this->usePkcs11Providers = usePkcs11Providers; +} + +void VpnAccountData::setAllowEmptyPrivateKeyPassword( bool allowEmptyPrivateKeyPassword) +{ + this->allowEmptyPrivateKeyPassword = allowEmptyPrivateKeyPassword; +} + +void VpnAccountData::setAllowIpAddressChangeOfPeer( bool allowIpAddressChangeOfPeer ) +{ + this->allowIpAddressChangeOfPeer = allowIpAddressChangeOfPeer; +} + +void VpnAccountData::setAuthMethod( QString AuthMethod ) +{ + this->AuthMethod = AuthMethod; +} + +void VpnAccountData::setCommandAfterConnectDelayTime( int CommandAfterConnectDelayTime) +{ + this->CommandAfterConnectDelayTime = CommandAfterConnectDelayTime; +} + +void VpnAccountData::setUseSearchDomainInResolvConf( bool useSearchDomainInResolvConf) +{ + this->useSearchDomainInResolvConf = useSearchDomainInResolvConf; +} + +void VpnAccountData::setUseDomainInResolvConf( bool useDomainInResolvConf) +{ + this->useDomainInResolvConf = useDomainInResolvConf; +} + +void VpnAccountData::setSearchDomainInResolvConf(QString SearchDomainInResolvConf) +{ + this->SearchDomainInResolvConf = SearchDomainInResolvConf; +} + +void VpnAccountData::setDomainInResolvConf(QString DomainInResolvConf) +{ + this->DomainInResolvConf = DomainInResolvConf; +} + +void VpnAccountData::setAuthenticationDirection(QString AuthenticationDirection) +{ + this->AuthenticationDirection = AuthenticationDirection; +} + +void VpnAccountData::setCiscoNatMode(QString CiscoNatMode) +{ + this->CiscoNatMode = CiscoNatMode; +} + +void VpnAccountData::setIpsecEsp(QString IpsecEsp) +{ + this->IpsecEsp = IpsecEsp; +} + +void VpnAccountData::setIpsecIke(QString IpsecIke) +{ + this->IpsecIke = IpsecIke; +} + +void VpnAccountData::setVtunProfile(QString VtunProfile) +{ + this->VtunProfile = VtunProfile; +} + +void VpnAccountData::setDisableDataEncryption(bool disableDataEncryption) +{ + this->disableDataEncryption = disableDataEncryption; +} + +void VpnAccountData::setUseAuthenticationAlgorithm(bool useAuthenticationAlgorithm) +{ + this->useAuthenticationAlgorithm = useAuthenticationAlgorithm; +} + +void VpnAccountData::setFixPathMtuDiscoveryProblem(bool fixPathMtuDiscoveryProblem) +{ + this->fixPathMtuDiscoveryProblem = fixPathMtuDiscoveryProblem; +} + +void VpnAccountData::setUseRemoteNetwork(bool useRemoteNetwork) +{ + this->useRemoteNetwork=useRemoteNetwork; +} + +void VpnAccountData::setIpsecVpnMode(QString IpsecVpnMode) +{ + this->IpsecVpnMode = IpsecVpnMode; +} + +void VpnAccountData::setDisableHeaderCompression(bool disableHeaderCompression) +{ + this->disableHeaderCompression = disableHeaderCompression; +} + +void VpnAccountData::setDisableMagicNumberNegotiation(bool disableMagicNumberNegotiation) +{ + this->disableMagicNumberNegotiation = disableMagicNumberNegotiation; +} + +void VpnAccountData::setDisableIpx(bool disableIpx) +{ + this->disableIpx = disableIpx; +} + +void VpnAccountData::setDisableProtocolFieldCompression(bool disableProtocolFieldCompression) +{ + this->disableProtocolFieldCompression=disableProtocolFieldCompression; +} + +void VpnAccountData::setDisableAdressControlCompression(bool disableAdressControlCompression) +{ + this->disableAdressControlCompression=disableAdressControlCompression; +} + +void VpnAccountData::setUseCustomEsp(bool useCustomEsp) +{ + this->useCustomEsp=useCustomEsp; +} + +void VpnAccountData::setUseCustomIke(bool useCustomIke) +{ + this->useCustomIke=useCustomIke; +} + +void VpnAccountData::setVerifyCaCert(bool verifyCaCert) +{ + this->verifyCaCert=verifyCaCert; +} + +void VpnAccountData::setUseDpdIdleTimeout(bool useDpdIdleTimeout) +{ + this->useDpdIdleTimeout = useDpdIdleTimeout; +} + +void VpnAccountData::setDpdIdleTimeout(int DpdIdleTimeout) +{ + this->DpdIdleTimeout = DpdIdleTimeout; +} + +void VpnAccountData::setHideGroupPasswordInAccountDataDialog(bool hideGroupPasswordInAccountDataDialog) +{ + this->hideGroupPasswordInAccountDataDialog = hideGroupPasswordInAccountDataDialog; +} + +void VpnAccountData::setMaxConnectTries(int MaxConnectTries) +{ + this->MaxConnectTries = MaxConnectTries; +} + +void VpnAccountData::setL2tpDaemon(L2tpDaemonType L2tpDaemon) +{ + this->L2tpDaemon = L2tpDaemon; +} + +void VpnAccountData::setUseLeftSourceIp(bool useLeftSourceIp) +{ + this->useLeftSourceIp = useLeftSourceIp; +} + +void VpnAccountData::setUseRightSourceIp(bool useRightSourceIp) +{ + this->useRightSourceIp = useRightSourceIp; +} + +void VpnAccountData::setLeftSourceIp(QString LeftSourceIp) +{ + this->LeftSourceIp = LeftSourceIp; +} + +void VpnAccountData::setRightSourceIp(QString RightSourceIp) +{ + this->RightSourceIp = RightSourceIp; +} + +void VpnAccountData::setUseVirtualSubnetworks(bool useVirtualSubnetworks) +{ + this->useVirtualSubnetworks = useVirtualSubnetworks; +} + +void VpnAccountData::setVirtualSubnetworks(QString VirtualSubnetworks) +{ + this->VirtualSubnetworks = VirtualSubnetworks; +} + +void VpnAccountData::setDisablePushFromServer(bool disablePushFromServer) +{ + this->disablePushFromServer = disablePushFromServer; +} + +void VpnAccountData::setDisableBind(bool disableBind) +{ + this->disableBind = disableBind; +} + +void VpnAccountData::setUseRenegSec(bool useRenegSec) +{ + this->useRenegSec = useRenegSec; +} + +void VpnAccountData::setRenegSec(int RenegSec) +{ + this->RenegSec = RenegSec; +} + +void VpnAccountData::setUseTunnelPing(bool useTunnelPing) +{ + this->useTunnelPing = useTunnelPing; +} + +void VpnAccountData::setTunnelPing(int TunnelPing) +{ + this->TunnelPing = TunnelPing; +} + +void VpnAccountData::setUseTunnelPingRestart(bool useTunnelPingRestart) +{ + this->useTunnelPing = useTunnelPing; +} + +void VpnAccountData::setTunnelPingRestart(int TunnelPingRestart) +{ + this->TunnelPingRestart = TunnelPingRestart; +} + +void VpnAccountData::setRequireEap(bool requireEap) +{ + this->requireEap = requireEap; +} + +void VpnAccountData::setUseSshConfigRemoteScript(bool useSshConfigRemoteScript) +{ + this->useSshConfigRemoteScript = useSshConfigRemoteScript; +} + +void VpnAccountData::setSshConfigRemoteScript(QString SshConfigRemoteScript) +{ + this->SshConfigRemoteScript = SshConfigRemoteScript; +} + +void VpnAccountData::setAskUserPasswordOnEachConnect( bool askUserPasswordOnEachConnect ) +{ + this->askUserPasswordOnEachConnect = askUserPasswordOnEachConnect; +} + +void VpnAccountData::setUseCiscoCertStore( bool useCiscoCertStore) +{ + this->useCiscoCertStore = useCiscoCertStore; +} + +void VpnAccountData::setUseNat( bool useNat ) +{ + this->useNat = useNat; +} diff --git a/src/vpnaccountdata.h b/src/vpnaccountdata.h new file mode 100644 index 0000000..ed83ce7 --- /dev/null +++ b/src/vpnaccountdata.h @@ -0,0 +1,689 @@ +/*************************************************************************** +* Copyright (C) 2004 by Christoph Thielecke * +* crissi99@gmx.de * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef VPNACCOUNTDATA_H +#define VPNACCOUNTDATA_H + +#include +#include +#include + +/** +* holds the data for a account +* @author Christoph Thielecke +*/ +class VpnAccountData : public QObject +{ +public: + enum ConnectionType {cisco=0, racoon=1, freeswan=2, pptp=3,openvpn=4,l2tpd_racoon=5,l2tpd_freeswan=6,ciscoorig=7,vtun=8,ssh=9,other=99}; + enum AuthenticationType {cert=0, psk=1, hybrid=2, unknownauth=99}; + enum L2tpDaemonType { l2tpd=0, openl2tp=1}; + + /** + * Konstruktor + * @param ConnType Type (cisco, freeswan,racoon, etc) + * @param Name The name of the account + * @param Gateway The hostname/IP of the VPN gateway + * @return nothing + */ + VpnAccountData( ConnectionType ConnType, const QString &Name); + + /** + * Destruktor + */ + ~VpnAccountData(); + + /* + Copy constructor + */ + VpnAccountData(const VpnAccountData&); + + ConnectionType getConnectionType() const; //< returns Connection type + QString getName() const; //< returns Name + QString getGateway() const; //< returns Gateway + QString getID() const; //< returns ID + QString getUserName() const; //< returns UserName + QString getUserPassword() const; //< returns UserPassword + QString getIkeGroup() const; //< returns IkeGroup + QString getEncryptionAlgorithm() const; //< returns EncryptionAlgorithm + QString getAuthenticationAlgorithm() const; //< returns AuthenticationAlgorithm + QString getPerfectForwardSecrety() const; //< returns PerfectForwardSecrecy + QString getNtDomainName() const; //< returns NtDomainName + QString getApplicationVersion() const; //< returns ApplicationVersion + QString getRemoteNetAddr() const; // +//#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "utils.h" + +/** + @author Christoph Thielecke +*/ +class VpnTypesListViewToolTip : public QToolTip +{ + public: + VpnTypesListViewToolTip ( QListView* parent ); + protected: + void maybeTip ( const QPoint& p ); + private: + QListView* listView; + public: + +}; +inline VpnTypesListViewToolTip::VpnTypesListViewToolTip ( QListView* parent ) : QToolTip ( parent->viewport() ), listView ( parent ) {} +inline void VpnTypesListViewToolTip::maybeTip ( const QPoint& p ) +{ + if ( !listView ) + return; + const QListViewItem* item = listView->itemAt ( p ); + if ( !item ) + return; + const QRect itemRect = listView->itemRect ( item ); + if ( !itemRect.isValid() ) + return; + const int col = listView->header()->sectionAt ( p.x() ); + const int row = listView->header()->sectionAt ( p.y() ); + if ( col == -1 && row == -1 ) + return; + + const QRect headerRect = listView->header()->sectionRect ( col ); + if ( !headerRect.isValid() ) + return; +// const QRect cellRect ( headerRect.left(), itemRect.top(), +// headerRect.width(), itemRect.height() ); + const QRect cellRect ( headerRect.left(), itemRect.top(), 400, 200 ); + QString tipStr; + + + + QStringList RequirementsList = QStringList::split( ",",item->text(2)); + QString RequirementsString="
    "; + for ( QStringList::Iterator it = RequirementsList.begin(); it != RequirementsList.end(); ++it ) + RequirementsString+="
  • "+*it+"
  • "; + RequirementsString+="
"; + + tipStr = QString ( "

"+item->text ( 0 )+"

  • "+i18n("Requirements:")+" "+RequirementsString+"
  • "+i18n("Comment:")+" "+item->text(3)+"
"); + + tip ( cellRect, tipStr ); +} + + +VpnTypesInfoDialog::VpnTypesInfoDialog ( KVpncConfig *GlobalConfig, QWidget *parent, const char * ) + :KDialogBase ( parent, "Tool_information", true, "", + KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, true ) +{ + main = new ToolsInfoWidgetBase(this); + setMainWidget(main); + main->InfoListView->setMinimumSize(main->InfoListView->sizeHint()); + main->InfoListView->removeColumn(6); + main->InfoListView->removeColumn(5); + main->InfoListView->removeColumn(4); + + main->InfoListView->setColumnText(0,i18n("VPN type")); + main->InfoListView->setColumnText(1,i18n("State")); + main->InfoListView->setColumnText(2,i18n("Requirements")); + main->InfoListView->setColumnText(3,i18n("Comment")); + + main->textLabel1->setText(i18n("The following information about the VPN tyes has been collected:")); + + QPixmap ok_icon = KGlobal::iconLoader()->loadIcon( "button_ok", KIcon::NoGroup, 16 ); + QPixmap wrong_icon = KGlobal::iconLoader()->loadIcon( "button_cancel", KIcon::NoGroup, 16 ); + ToolInfo *tool=0; + main->InfoListView->setSorting(1); + + VpnTypesInfoList = new QPtrList(); + VpnTypesInfoList->setAutoDelete( TRUE ); // the list owns the objects + + VpnTypeInfo *it; + + GlobalConfig->appPointer->setOverrideCursor( QCursor(Qt::WaitCursor) ); + + Utils UtilsInstance(GlobalConfig); + + it = new VpnTypeInfo(); + it->VpnType = "cisco"; + it->Name= i18n("Cisco VPN"); + it->Requirements.append("vpnc / vpnclient"); + + bool vpnc_found = UtilsInstance.getToolInfo("vpnc")->found; + bool vpnclient_found = UtilsInstance.getToolInfo("vpnclient")->found; + + if (vpnc_found || vpnclient_found) + { + it->VpnState=true; + it->state=i18n("%1 found").arg(i18n("all tools")); + } + else + { + it->VpnState=false; + it->state=i18n("%1 missing").arg(i18n("some tools")); + } + + if (vpnc_found && !vpnclient_found ) + { + it->Comment+=i18n("no certificate support"); + } + if (vpnc_found && vpnclient_found ) + { + it->Comment+=i18n("certificate support only with vpnclient (original Cisco client)"); + } + if (vpnc_found ) + { + it->Comment+=", "+i18n("hybrid support only if vpnc compiled with OpenSSL support"); + } + + QListViewItem *item = new QListViewItem(main->InfoListView, it->VpnType,it->state, it->Requirements.join(" "+i18n("and")+" "), it->Comment); + if (it->VpnState == true) + item->setPixmap(1,ok_icon); + else + item->setPixmap(1,wrong_icon); + + main->InfoListView->insertItem(item); + VpnTypesInfoList->append(it); + + it = new VpnTypeInfo(); + it->VpnType = "ipsec"; + it->Name= i18n("IPsec VPN"); + it->Requirements.append("Openswan / strongSwan / FreeS/Wan / ipsec-tools"); + + bool ipsec_found = UtilsInstance.getToolInfo("ipsec")->found; + bool racoon_found = UtilsInstance.getToolInfo("racoon")->found; + + + if (ipsec_found || racoon_found) + { + it->VpnState=true; + it->state=i18n("%1 found").arg(i18n("all tools")); + } + else + { + it->VpnState=false; + it->state=i18n("%1 missing").arg(i18n("some tools")); + } + + if (ipsec_found && ( !UtilsInstance.getToolInfo("ipsec")->Version.contains ( "Openswan" ) && !UtilsInstance.getToolInfo("ipsec")->Version.contains ( "strongswan" ) )) + { + it->Comment+=i18n("FreeS/WAN detected, please upgrade to Openswan/strongSwan"); + } + if (ipsec_found &&UtilsInstance.getToolInfo("ipsec")->Version.contains ( "Openswan" ) ) + { + it->Comment+=i18n("Openswan detected, no smartcard support"); + } + if (ipsec_found &&UtilsInstance.getToolInfo("ipsec")->Version.contains ( "strongswan" ) ) + { + it->Comment+=i18n("%1 detected").arg(i18n("strongSwan")); + } + + item = new QListViewItem(main->InfoListView, it->VpnType,it->state, it->Requirements.join(" "+i18n("and")+" "), it->Comment); + if (it->VpnState == true) + item->setPixmap(1,ok_icon); + else + item->setPixmap(1,wrong_icon); + + main->InfoListView->insertItem(item); + VpnTypesInfoList->append(it); + + it = new VpnTypeInfo(); + it->VpnType = "pptp"; + it->Name= i18n("Microsoft PPTP VPN"); + it->Requirements.append("pptpclient"); + it->Requirements.append("pppd"); + it->Requirements.append(i18n("MPPE extensions in kernel")); + bool pptpd_found = UtilsInstance.getToolInfo("pptp")->found; + bool pppd_found = UtilsInstance.getToolInfo("pppd")->found; + + Utils::PppdCapabilities pppdcap = UtilsInstance.checkPppdCapabilities(); + + if (pppd_found && pptpd_found && (pppdcap.pppdHasMppeRequiredSupport || pppdcap.pppdHasRequireMppeSupport)) + { + it->VpnState=true; + it->state=i18n("%1 found").arg(i18n("all tools")); + } + else + { + it->VpnState=false; + it->state=i18n("%1 missing").arg(i18n("some tools")); + } + + if (pptpd_found && !pppd_found ) + { + it->Comment+=i18n("%1 is missing").arg("pppd"); + } + if (!pptpd_found && pppd_found) + { + it->Comment+=i18n("%1 is missing").arg("pptpclient"); + } + + if (!pptpd_found && !pppd_found) + { + it->Comment+=i18n("%1 are missing").arg(i18n("pptpclient and pppd")); + } + + if (!it->Comment.isEmpty()) + it->Comment+=", "; + if (!pppdcap.pppdHasMppeRequiredSupport && !pppdcap.pppdHasRequireMppeSupport ) + it->Comment+=i18n("%1 are missing").arg(i18n("MPPE support")); + + item = new QListViewItem(main->InfoListView, it->VpnType,it->state, it->Requirements.join(" "+i18n("and")+" "), it->Comment); + if (it->VpnState == true) + item->setPixmap(1,ok_icon); + else + item->setPixmap(1,wrong_icon); + + main->InfoListView->insertItem(item); + VpnTypesInfoList->append(it); + + it = new VpnTypeInfo(); + it->VpnType = "openvpn"; + it->Name= i18n("OpenVPN SSL-VPN"); + it->Requirements.append("openvpn"); + it->Requirements.append("openssl"); + + bool openvpn_found = UtilsInstance.getToolInfo("openvpn")->found; + bool openssl_found = UtilsInstance.getToolInfo("openvpn")->found; + + if (openvpn_found && openssl_found) + { + it->VpnState=true; + it->state=i18n("%1 found").arg(i18n("all tools")); + } + else + { + it->VpnState=false; + it->state=i18n("%1 missing").arg(i18n("some tools")); + } + + if (!openvpn_found && openssl_found ) + { + it->Comment+=i18n("%1 is missing").arg("openvpn"); + } + if (openvpn_found && !openssl_found ) + { + it->Comment+=i18n("%1 is missing").arg("openssl"); + } + if (!openvpn_found && !openssl_found) + { + it->Comment+=i18n("%1 are missing").arg(i18n("openvpn and openssl")); + } + + item = new QListViewItem(main->InfoListView, it->VpnType,it->state, it->Requirements.join(" "+i18n("and")+" "), it->Comment); + if (it->VpnState == true) + item->setPixmap(1,ok_icon); + else + item->setPixmap(1,wrong_icon); + + main->InfoListView->insertItem(item); + VpnTypesInfoList->append(it); + + it = new VpnTypeInfo(); + it->VpnType = "l2tpd_ipsec"; + it->Name= i18n("L2TP over IPSec"); + it->Requirements.append("Openswan / strongSwan / FreeS/Wan / ipsec-tools"); + it->Requirements.append("l2tpd / xl2tpd / openl2tp"); + + ipsec_found = UtilsInstance.getToolInfo("ipsec")->found; + racoon_found = UtilsInstance.getToolInfo("racoon")->found; + bool l2tpd_found = UtilsInstance.getToolInfo("l2tpd")->found; + bool xl2tpd_found = UtilsInstance.getToolInfo("xl2tpd")->found; + bool openl2tp_found = UtilsInstance.getToolInfo("openl2tpd")->found; + + + if ((ipsec_found || racoon_found) && (l2tpd_found || xl2tpd_found || openl2tp_found)) + { + it->VpnState=true; + it->state=i18n("%1 found").arg(i18n("all tools")); + } + else + { + it->VpnState=false; + it->state=i18n("%1 missing").arg(i18n("some tools")); + } + + if (ipsec_found && ( !UtilsInstance.getToolInfo("ipsec")->Version.contains ( "Openswan" ) && !UtilsInstance.getToolInfo("ipsec")->Version.contains ( "strongswan" ) )) + { + it->Comment+=i18n("FreeS/WAN detected, please upgrade to Openswan/strongSwan"); + } + if (ipsec_found && UtilsInstance.getToolInfo("ipsec")->Version.contains ( "Openswan" ) ) + { + it->Comment+=i18n("Openswan detected, no smartcard support"); + } + if (ipsec_found && UtilsInstance.getToolInfo("ipsec")->Version.contains ( "strongswan" ) ) + { + it->Comment+=i18n("%1 detected").arg(i18n("strongSwan")); + } + + if (l2tpd_found) + { + it->Comment+=", "; + it->Comment+=i18n("%1 detected").arg(i18n("l2tpd")); + } + if (xl2tpd_found) + { + it->Comment+=", "; + it->Comment+=i18n("%1 detected").arg(i18n("xl2tpd")); + } + if (openl2tp_found) + { + it->Comment+=", "; + it->Comment+=i18n("%1 detected").arg(i18n("openl2tp")); + } + + item = new QListViewItem(main->InfoListView, it->VpnType,it->state, it->Requirements.join(" "+i18n("and")+" "), it->Comment); + if (it->VpnState == true) + item->setPixmap(1,ok_icon); + else + item->setPixmap(1,wrong_icon); + + main->InfoListView->insertItem(item); + VpnTypesInfoList->append(it); + + it = new VpnTypeInfo(); + it->VpnType = "vtun"; + it->Name= i18n("Vtun VPN"); + it->Requirements.append("vtund"); + it->Requirements.append("pppd"); + + bool vtund_found = UtilsInstance.getToolInfo("vtund")->found; + pppd_found = UtilsInstance.getToolInfo("pppd")->found; + + if (vtund_found && pppd_found) + { + it->VpnState=true; + it->state=i18n("%1 found").arg(i18n("all tools")); + } + else + { + it->VpnState=false; + it->state=i18n("%1 are missing").arg(i18n("some tools")); + } + + if (vtund_found && !pppd_found) + { + it->Comment+=i18n("%1 is missing").arg("pppd"); + } + if (!vtund_found && pppd_found ) + { + it->Comment+=i18n("%1 is missing").arg("vtun"); + } + + item = new QListViewItem(main->InfoListView, it->VpnType,it->state, it->Requirements.join(" "+i18n("and")+" "), it->Comment); + if (it->VpnState == true) + item->setPixmap(1,ok_icon); + else + item->setPixmap(1,wrong_icon); + + main->InfoListView->insertItem(item); + VpnTypesInfoList->append(it); + + it = new VpnTypeInfo(); + it->VpnType = "ssh"; + it->Name= i18n("SSH VPN"); + it->Requirements.append("ssh"); + it->Requirements.append("ksshaskpass / gnome-ssh-askpass"); + + bool ssh_found = UtilsInstance.getToolInfo("ssh")->found; + bool ksshaskpass_found = UtilsInstance.getToolInfo("ksshaskpass")->found; + bool sshaskpassgnome_found = UtilsInstance.getToolInfo("gnome-ssh-askpass")->found; + + if (ssh_found && (ksshaskpass_found || sshaskpassgnome_found)) + { + it->VpnState=true; + it->state=i18n("%1 found").arg(i18n("all tools")); + } + else + { + it->VpnState=false; + if (!ssh_found && (ksshaskpass_found || sshaskpassgnome_found) ) + it->Comment+=i18n("%1 is missing").arg("ssh"); + else + it->Comment+=i18n("%1 is missing").arg(i18n("Password entry tool")); + + } + + item = new QListViewItem(main->InfoListView, it->VpnType,it->state, it->Requirements.join(" "+i18n("and")+" "), it->Comment); + if (it->VpnState == true) + item->setPixmap(1,ok_icon); + else + item->setPixmap(1,wrong_icon); + + main->InfoListView->insertItem(item); + VpnTypesInfoList->append(it); + + main->InfoListView->setResizeMode(QListView::NoColumn); +// main->InfoListView->setColumnWidthMode(0,QListView::Manual); +// main->InfoListView->setColumnWidthMode(1,QListView::Manual); +// main->InfoListView->setColumnWidthMode(2,QListView::Manual); +// main->InfoListView->setColumnWidthMode(3,QListView::Maximum); +// main->InfoListView->setColumnWidthMode(4,QListView::Maximum); + resize(800,600); + + QToolTip::remove( main->InfoListView ); + new VpnTypesListViewToolTip( main->InfoListView ); + + GlobalConfig->appPointer->restoreOverrideCursor(); +} + + +VpnTypesInfoDialog::~VpnTypesInfoDialog() +{ +} + + diff --git a/src/vpntypesinfodialog.h b/src/vpntypesinfodialog.h new file mode 100644 index 0000000..4b4fdcb --- /dev/null +++ b/src/vpntypesinfodialog.h @@ -0,0 +1,51 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef VPNTYPESINFODIALOG_H +#define VPNTYPESINFODIALOG_H + +#include +#include +#include "kvpnc.h" +#include "kvpncconfig.h" +#include "toolsinfowidgetbase.h" + +/** + @author Christoph Thielecke +*/ +class VpnTypesInfoDialog: public KDialogBase +{ + public: + VpnTypesInfoDialog(KVpncConfig *GlobalConfig, QWidget *parent = 0, const char *name = 0); + ToolsInfoWidgetBase *main; + ~VpnTypesInfoDialog(); + + struct VpnTypeInfo { + QString VpnType; + QString Name; + QString state; + bool VpnState; + QString Comment; + QStringList Requirements; + }; + QPtrList *VpnTypesInfoList; + +}; + +#endif diff --git a/src/widgetnotifyhelper.cpp b/src/widgetnotifyhelper.cpp new file mode 100644 index 0000000..6140453 --- /dev/null +++ b/src/widgetnotifyhelper.cpp @@ -0,0 +1,93 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "widgetnotifyhelper.h" +#include + +#include + + +WidgetNotifyHelper::WidgetNotifyHelper(QObject *parent, const char *name) + : QObject(parent, name) +{ +} + + +WidgetNotifyHelper::~WidgetNotifyHelper() +{ +} + +void WidgetNotifyHelper::setupChangedAction(QWidget *w) +{ + // connect changed signals to own signal + QObject *obj; + QObjectList *list; + + list = w->queryList( "QComboBox" ); + for ( obj = list->first(); obj; obj = list->next() ) + { +// std::cout << "obj found: " << obj->name() << std::endl; + connect(obj,SIGNAL(textChanged ( const QString & )),w,SIGNAL(changed())); + } + + list = w->queryList( "KLineEdit" ); + for ( obj = list->first(); obj; obj = list->next() ) + { +// std::cout << "obj found: " << obj->name() << std::endl; + connect(obj,SIGNAL(textChanged ( const QString & )),w,SIGNAL(changed())); + } + + list = w->queryList( "QLineEdit" ); + for ( obj = list->first(); obj; obj = list->next() ) + { +// std::cout << "obj found: " << obj->name() << std::endl; + connect(obj,SIGNAL(textChanged (const QString & )),w,SIGNAL(changed())); + } + + list = w->queryList( "KUrlRquester" ); + for ( obj = list->first(); obj; obj = list->next() ) + { +// std::cout << "obj found: " << obj->name() << std::endl; + connect(obj,SIGNAL(textChanged ( const QString & )),w,SIGNAL(changed())); + } + + list = w->queryList( "QSpinBox" ); + for ( obj = list->first(); obj; obj = list->next() ) + { +// std::cout << "obj found: " << obj->name() << std::endl; + connect(obj,SIGNAL(valueChanged ( int )),w,SIGNAL(changed())); + } + + list = w->queryList( "QCheckBox" ); + for ( obj = list->first(); obj; obj = list->next() ) + { +// std::cout << "obj found: " << obj->name() << std::endl; + connect(obj,SIGNAL(stateChanged ( int )),w,SIGNAL(changed())); + } + + list = w->queryList( "QRadioButton" ); + for ( obj = list->first(); obj; obj = list->next() ) + { +// std::cout << "obj found: " << obj->name() << std::endl; + connect(obj,SIGNAL(stateChanged ( int )),w,SIGNAL(changed())); + } + + // connect changed to slot + connect(w,SIGNAL(changed ()),w,SLOT(dialogChanged())); +} diff --git a/src/widgetnotifyhelper.h b/src/widgetnotifyhelper.h new file mode 100644 index 0000000..0f01671 --- /dev/null +++ b/src/widgetnotifyhelper.h @@ -0,0 +1,39 @@ +/*************************************************************************** + * Copyright (C) 2004 by Christoph Thielecke * + * crissi99@gmx.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef WIDGETNOTIFYHELPER_H +#define WIDGETNOTIFYHELPER_H + +#include +#include + +/** + @author Christoph Thielecke +*/ +class WidgetNotifyHelper : public QObject +{ +public: + WidgetNotifyHelper(QObject *parent = 0, const char *name = 0); + + ~WidgetNotifyHelper(); +public: + void setupChangedAction(QWidget *w); +}; + +#endif diff --git a/src/x-cisco.desktop b/src/x-cisco.desktop new file mode 100644 index 0000000..25265a5 --- /dev/null +++ b/src/x-cisco.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] +Encoding=UTF-8 +Type=MimeType +MimeType=application/x-cisco +Icon=pcfimport +Patterns=*.pcf;*.PCF; +Comment=Cisco VPN profile +Comment[de]=Cisco-VPN-Profil + diff --git a/src/x-openvpn.desktop b/src/x-openvpn.desktop new file mode 100644 index 0000000..57f8637 --- /dev/null +++ b/src/x-openvpn.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] +Encoding=UTF-8 +Type=MimeType +MimeType=application/x-openvpn +Icon= +Patterns=*.ovpn;*.OVPN; +Comment=OpenVPN profile file +Comment[de]=OpenVPN-Profildatei + -- cgit v1.2.1