summaryrefslogtreecommitdiffstats
path: root/src/vpntypesinfodialog.cpp
blob: 862494f84d2f50aa3f1f938d3c697b84d3584965 (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
/***************************************************************************
 *   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 "vpntypesinfodialog.h"
#include <klistview.h>
//#include <tqlistviewitem.h>
#include <tqpixmap.h>
#include <kglobal.h>
#include <tqstring.h>
#include <kiconloader.h>
#include <iostream>
#include <klocale.h>
#include <tqcursor.h>
#include <tqtooltip.h>
#include <tqlistview.h>
#include <tqheader.h>
#include "utils.h"

/**
	@author Christoph Thielecke <crissi99@gmx.de>
*/
class VpnTypesListViewToolTip : public TQToolTip
{
	public:
		VpnTypesListViewToolTip ( TQListView* parent );
	protected:
		void maybeTip ( const TQPoint& p );
	private:
		TQListView* listView;
	public:

};
inline VpnTypesListViewToolTip::VpnTypesListViewToolTip ( TQListView* parent ) : TQToolTip ( parent->viewport() ), listView ( parent ) {}
inline void VpnTypesListViewToolTip::maybeTip ( const TQPoint& p )
{
	if ( !listView )
		return;
	const TQListViewItem* item = listView->itemAt ( p );
	if ( !item )
		return;
	const TQRect 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 TQRect headerRect = listView->header()->sectionRect ( col );
	if ( !headerRect.isValid() )
		return;
// 	const TQRect cellRect ( headerRect.left(), itemRect.top(),
// 	                       headerRect.width(), itemRect.height() );
	const TQRect cellRect ( headerRect.left(), itemRect.top(), 400, 200 );
	TQString tipStr;

	

	TQStringList RequirementsList = TQStringList::split( ",",item->text(2));
	TQString RequirementsString="<ul>";
	for ( TQStringList::Iterator it = RequirementsList.begin(); it != RequirementsList.end(); ++it )
		RequirementsString+="<li>"+*it+"</li>";
	RequirementsString+="</ul>";

	tipStr = TQString ( "<h2>"+item->text ( 0 )+"</h2><ul><li>"+i18n("Requirements:")+" "+RequirementsString+"</li><li>"+i18n("Comment:")+" "+item->text(3)+"</li></ul>");

	tip ( cellRect, tipStr );
}


VpnTypesInfoDialog::VpnTypesInfoDialog ( KVpncConfig *GlobalConfig, TQWidget *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:"));

	TQPixmap ok_icon = KGlobal::iconLoader()->loadIcon( "button_ok", KIcon::NoGroup, 16 );
	TQPixmap wrong_icon = KGlobal::iconLoader()->loadIcon( "button_cancel", KIcon::NoGroup, 16 );
	ToolInfo *tool=0;
	main->InfoListView->setSorting(1);

	VpnTypesInfoList = new TQPtrList<VpnTypeInfo>();
	VpnTypesInfoList->setAutoDelete( TRUE ); // the list owns the objects

	VpnTypeInfo *it;

	GlobalConfig->appPointer->setOverrideCursor( TQCursor(TQt::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");
	}

	TQListViewItem *item = new TQListViewItem(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 TQListViewItem(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 TQListViewItem(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 TQListViewItem(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 TQListViewItem(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 TQListViewItem(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 TQListViewItem(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(TQListView::NoColumn);
// 	main->InfoListView->setColumnWidthMode(0,TQListView::Manual);
// 	main->InfoListView->setColumnWidthMode(1,TQListView::Manual);
// 	main->InfoListView->setColumnWidthMode(2,TQListView::Manual);
// 	main->InfoListView->setColumnWidthMode(3,TQListView::Maximum);
// 	main->InfoListView->setColumnWidthMode(4,TQListView::Maximum);
	resize(800,600);

	TQToolTip::remove( main->InfoListView );
	new VpnTypesListViewToolTip( main->InfoListView );

	GlobalConfig->appPointer->restoreOverrideCursor();
}


VpnTypesInfoDialog::~VpnTypesInfoDialog()
{
}