summaryrefslogtreecommitdiffstats
path: root/src/kvpnc.h
blob: e331fdb2db1742c5d70cdfee8e6103534fc11ad0 (plain)
1
2
3
4
5
6
7
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
/***************************************************************************
*   Copyright (C) 2004 by Christoph Thielecke                             *
*   [email protected]                                                       *
*                                                                         *
*   Contains parts of code from klcc project                              *
*   (Peter Simonsson <[email protected]>).                                      *
*                                                                         *
*   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 <tqwidget.h>
#include <tqstrlist.h>
#include <tqpixmap.h>
#include <tqtimer.h>
#include <tqfile.h>
#include <tqdatetime.h>
#include <tqptrlist.h>
#include <tqlabel.h>
#include <tqtextstream.h>
#include <tqpoint.h>
#include <tqsize.h>
#include <tqpopupmenu.h>
#include <tdeapplication.h>
#include <tdemainwindow.h>
#include <tdeaction.h>
#include <tdeprocess.h>
#include <kwizard.h>
#include <knotifyclient.h>
#include <knotifydialog.h>
#include <kfeedback.h>
#include <dcopobject.h>
#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 TDEMainWindow , DCOPObject
{
	TQ_OBJECT
  
	K_DCOP
public:
	/**
	* Konstruktor
	* @param parent Parent widget
	* @param name Name of the Mainwindow
	*/
	KVpnc( TDEApplication *parent, TQWidget *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 ( TQProcess *proc );
	/**
	* called when quit requested
	*/
	virtual bool queryExit();

	void saveProperties( TDEConfig* );
	void readProperties( TDEConfig* );

public:
	void restore(TDEConfig *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
	*/
	TQString getX509CertificateID( TQString 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};

	TDEApplication *parent;
	TQStringList *env;

	KVpncConfig *GlobalConfig;
	KVpncKicker* KVpncDock; //< kicker menu
	TDEAction* ConnectAction; //< connect action
	TDEAction* DisconnectAction; //< disconnect action
	TDEAction *NewSessionAction;
	TDEAction *SaveSessionAction;
	TDEAction *DeleteSessionAction;
	TDEAction *RenameSessionAction;
	TDEAction *ImportSessionAction;
	TDEAction *ImportOpenvpnProfileAction;
	TDEAction *ExportOpenvpnProfileAction;
	TDEAction *ImportFreeswanProfileAction;
	TDEAction *ImportFritzboxProfileAction;
	TDEAction *ImportKvpncSettingsAction;
	TDEAction *ExportKvpncSettingsAction;
	TDEAction *ImportCertAction;
	TDEAction *SelectAction; //< line select action
	TDEAction *ProfileManagerAction;
	TDEAction *NewProfileWizardAction;
	TDEAction *HelpAction;
	TDEAction *PrefAction;
//	TDEAction *DonateAction;
	TDEAction *ReportBugAction;
	TDEAction *SendFeedbackMailAction;
	TDEAction *PreferencesAction; //< show preferences dialog
	TDEAction *ManageCiscoCertAction; //< show cisco cert manager
	TDEAction *CiscoCertEnrollmentAction; //< show cisco cert enrollment dialog
	TDEToggleAction *ToolsInfoAction;
	TDEToggleAction *VpnTypesInfoAction;
	TDEToggleAction *LogViewerAction;
	TDEToggleAction *ShowToolbarAction; //< toggle toolbar on/off
	TDEToggleAction *ShowStatusbarAction; //< toggle statusbar on/off
	TDEToggleAction *DebugconsoleAction; //< toggle debug console
	TDEToggleAction *GenerateOpenvpnKeyAction; //< generate OpenVPN key
	MainView* mw; //< Main gui
	TQTimer timer;
	TQTimer durationTimer; //< timer for counting connection time
	TQTimer IpsecWhackStatusTimer; //< getting ipsec status periodically
	TQTimer 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;

	TQString OldDefaultroute;
	TQString VpncConnectScript;
	TQString VpncDisconnectScript;
	TQString tmpPath;
	TQString ProcessMsg_connect;
	TQString ProcessMsg_disconnect;
	TQString deviceaddrstr;
	TQString deviceaddr;
	TQString tmpInterface;
	TQString LocalIP;
	TQString VpncGateway;
	TQString PptpGateway;
	TQString VpncScript;
	TQString issuerID; // for id extract
	TQString userID;   // for id extract
	TQString TunnelInterfaceIP;
	TQString TmpDns1;
	TQString TmpDns2;
	TQString VpncDevice;
	TQString CiscoVpncDevice;
	TQString L2tpPppDevice;
	TQString PppdDevice;
	TQString OpenvpnDevice;
	TQString SshDevice;
	TQString IpsecType; //< openswan, strongswan, freeswan
	TQString Pkcs11PIN;
	TQString PrettyTypeString;
	TQString PrettyStatusMessage;

	TQProcess *VpncProcess;
	TDEProcess *IpsecConnectProcess;
	TQProcess *DisconnectProcess;
	TQProcess *CiscoVpncProcess; //< vpnclient
	TQProcess *RacoonProcess; //< racoon
	TQProcess *RacoonHelperProcess;
	TQProcess *IpsecProcess; //< freeswan/openswan/strongswan
	TQProcess *IpsecStartProcess;
	TQProcess *IpsecWhackProcess; //< ipsec whack --initate
	TQProcess *IpsecWhackStatusProcess; //< ipsec whack --status
	TQProcess *IpsecWhackListenProcess; //< ipsec whack --listen
	TQProcess *IpsecWhackDeleteProcess; //< ipsec whack --delete
	TQProcess *PingProcess;
	TQProcess *RacoonTailProcess;
	TQProcess *RacoonctlProcess; //< racoonctl
	TQProcess *X509CertificateExtractProcess;
	TQProcess *PptpProcess;
	TQProcess *OpenvpnProcess;
	TQProcess *CmdBeforeConnectProcess;
	TQProcess *CmdBeforeDisconnectProcess;
	TQProcess *CmdAfterConnectProcess;
	TQProcess *CmdAfterDisconnectProcess;
	TQProcess *SetFirewallAfterConnectProcess;
	TQProcess *SetFirewallBeforeDisconnectProcess;
	TQProcess *RouteProcess;
	TQProcess *SetVirtualIPProcess;
	TQProcess *ReplaceDefaultRouteProcess;
	TQProcess *ConnectionStatusCheckProcess;
	TQProcess *TestCiscoVpncProcess;
	TQProcess *IptablesProcess;
	TQProcess *KillProcess;
	TQProcess *PptpRouteProcess;
	TQProcess *ChmodProcess;
	TQProcess *pppdUpProcess;
	TQProcess *pppdDelDefaultRouteProcess;
	TQProcess *L2tpdProcess;
	TQProcess *OpenL2tpProcess;
	TQProcess *RemoveSetkeyProcess;
	TQProcess *BugReportProcess;
//	TQProcess *DonateProcess;
	TQProcess *VtundProcess;
	TQProcess *StartStopOpenl2tpProcess;
	TDEProcess *SshProcess;
	TQProcess *backupDefaultRouteProcess;
	TQProcess *pptpdKillProcess;
	TQProcess *SshDownProcess;
	TQProcess *pppdDownProcess;
	TQProcess *killracoonprocess;
	TQProcess *killl2tpdprocess;
	TQProcess *SshUpProcess;

	int TimeOutProcess; //< for timeout
	int ConnectingProcess; //< for killing process
	TQPixmap connectedIcon;
	TQPixmap disconnectedIcon;
	TQPixmap connectingIcon;
	TQPixmap *connectingStatusPixmap;
	TQPixmap *disconnectedStatusPixmap;
	TQPixmap *connectedStatusPixmap;

	TQLabel *statusColorLabel;
	TQPopupMenu *QuickConnectMenu;

	OpenvpnManagementHandler *managementhandler ;
	KFeedbackDialog *FeedbackDialog;

	TQString L2tpdBufferStdoutString;
	TQString 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 TQString &text, int id = ID_STATUS_MSG );

	void connectClicked();
	void disconnectClicked();
	void saveSessionClicked();
	void newSessionClicked();
	void deleteSessionClicked();
	void renameSessionClicked ();
	void sessionToggled( const TQString& );
	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( TQCloseEvent* 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(TDEProcess *proc, char *buffer, int buflen);
	void readFromStderr_ssh(TDEProcess *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(TQString 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(TQString Name);
	
public:
	void importOpenvpnProfileClicked(TQString file); //< OpenVPN config file import
	void importProfileClicked(TQString file); //< PCF import

	bool backupResolvConf();
	bool restoreResolvConf();

public:
k_dcop:
	TQString getVersion();
	void doConnect();
	void doDisconnect();
	uint getConnectedTime();
	TQString getStatus();
	TQString getCurrentProfile();
	void setProfile(TQString profilename);
	void createNewProfile();
	void createNewProfileWithWizard();
	void deleteCurrentProfile();
	void openPreferences();
	void doImportCert();
	void doImportPcf();
	void doImportPcf(TQString file);
	void doImportOpenvpnConfig();
	void doImportOpenvpnConfig(TQString file);
	TQStringList profiles();
	TQStringList toolinfo();
	void doQuit();
	void doGenerateOpenvpnKey();
	void doSendFeedbackMail();
	TQStringList getProfileTypes();

};

#endif