~ubuntu-branches/ubuntu/vivid/kvpnc/vivid-proposed

« back to all changes in this revision

Viewing changes to src/utils.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2009-04-23 09:18:50 UTC
  • mfrom: (1.1.10 upstream) (8.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20090423091850-hweeg0jo64t0jx52
Tags: 0.9.1-1
* New upstream release (KDE4 is here)
* Add Build-Depends cmake and pkg-kde-tools
* Remove obsolete debian/patches
* Refresh debian/patches:
  - 10_su-to-root_usage.diff
  - 13_add_kuser_issuperuser.diff
* Cleanup debian/rules - simple under KDE4
* Update debian/watch for KDE4 version
* Update debian/copyright - use versionned licenses
* Update Section field - move to utils
* Remove obsolete dependencies: kdebase-bin, gksu, sux and modutils
* Update debian/kvpnc.{manpages,1}

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
***************************************************************************/ 
20
20
//BEGIN INCLUDES
21
21
#include "utils.h"
22
 
#include <qstring.h>
23
 
#include <qapplication.h>
 
22
#include <QtCore/QString>
 
23
#include <QtGui/qapplication.h>
 
24
#include <Qt3Support/Q3PtrList>
24
25
#include <iostream>
25
 
#include <qfile.h>
26
 
#include <qprocess.h>
27
 
#include <qstring.h>
 
26
#include <QtCore/qfile.h>
 
27
#include <Qt3Support/Q3Process>
 
28
#include <QtCore/QString>
28
29
#include <klocale.h>
29
 
#include <ksimpleconfig.h>
30
 
#include <qdir.h>
31
 
#include <kstddirs.h>
 
30
#include <QtCore/qdir.h>
 
31
#include <kstandarddirs.h>
32
32
#include <kdebug.h>
33
33
#include <kstandarddirs.h>
34
34
#include <netdb.h> // name resolving
35
35
#include <arpa/inet.h>
36
 
#include <qregexp.h>
 
36
#include <QtCore/qregexp.h>
37
37
#include <kmessagebox.h>
38
38
 
39
39
//END INCLUDES
40
40
 
41
 
Utils::Utils( KVpncConfig* config, QObject *parent, const char *name )
 
41
Utils::Utils( KVpncConfig* GlobalConfig, QObject *parent, const char *name )
42
42
                : QObject( parent, name )
43
43
{
44
44
        env = new QStringList();
45
45
        *env << "LC_ALL=C" << "LANG=C" << "PATH=/bin:/usr/bin:/usr/sbin:/sbin";
46
 
        this->config = config;
 
46
        this->GlobalConfig = GlobalConfig;
47
47
        retrieveValidNetworkdevice = false;
48
48
}
49
49
 
68
68
                int part2 = addr.section( '.', 2, 2 ).toInt();
69
69
                int part3 = addr.section( '.', 3, 3 ).toInt();
70
70
 
71
 
                //std::cout << "part0 " << part0 << ", part1 " << part1 <<  ", part2 " << part2 << ", part3 " << part3 << "\n";
 
71
                //std::cout << "part0 " << qPrintable(part0) << ", part1 " << qPrintable(part1) <<  ", part2 " << qPrintable(part2) << ", part3 " << qPrintable(part3) << "\n";
72
72
 
73
73
                if ( ( part0 > 1 && part0 < 255 ) &&
74
74
                        ( part1 >= 0 && part1 < 255 ) &&
137
137
 
138
138
bool Utils::createTunDev()
139
139
{
140
 
        createProcess = new QProcess( this );
 
140
        createProcess = new Q3Process( this );
141
141
        connect( createProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutCreateTunDev() ) );
142
142
        connect( createProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrCreateTunDev() ) );
143
143
 
149
149
 
150
150
 
151
151
                if ( !createProcess->start(env) ) {
152
 
                        kdError() << "Unable to create tunnel device file!" << endl;
 
152
                        kError() << "Unable to create tunnel device file!" << endl;
153
153
                        return false;
154
154
                } else {
155
155
                        //              while(createProcess->isRunning())
167
167
        createProcess->addArgument( "200" );
168
168
 
169
169
        if ( !createProcess->start(env) ) {
170
 
                kdError() << "Unable to create tunnel device file!" << endl;
 
170
                kError() << "Unable to create tunnel device file!" << endl;
171
171
                return false;
172
172
        } else
173
173
                return true;
179
179
{
180
180
        if ( !Name.isEmpty() ) {
181
181
                modprobeSuccess = true;
182
 
                ModprobeProcess = new QProcess( this );
 
182
                ModprobeProcess = new Q3Process( this );
183
183
                ModprobeProcess->addArgument( "/sbin/modprobe" );
184
184
                ModprobeProcess->addArgument( Name );
185
185
 
195
195
                }
196
196
 
197
197
        } else
 
198
                        return false;
 
199
}
 
200
 
 
201
bool Utils::unloadKernelModule( QString Name, QApplication *app , bool force)
 
202
{
 
203
        if ( !Name.isEmpty() ) {
 
204
                modprobeSuccess = true;
 
205
                ModprobeProcess = new Q3Process( this );
 
206
                ModprobeProcess->addArgument( "/sbin/rmmod" );
 
207
 
 
208
                if (force == true)
 
209
                        ModprobeProcess->addArgument( "-f" );
 
210
 
 
211
                ModprobeProcess->addArgument( Name );
 
212
 
 
213
                connect( ModprobeProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutLoadKernelModule() ) );
 
214
                connect( ModprobeProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrLoadKernelModule() ) );
 
215
                if ( !ModprobeProcess->start( env ) ) {
 
216
                        kdError() << "Unable to start kernel module loading process!" << endl;
 
217
                        return false;
 
218
                } else {
 
219
                        while ( ModprobeProcess->isRunning() )
 
220
                                app->processEvents();
 
221
                        return modprobeSuccess;
 
222
                }
 
223
 
 
224
        } else
198
225
                return false;
199
226
}
200
227
 
201
228
bool Utils::doChmod( QString file, QString mode )
202
229
{
203
 
        QProcess * chmodProcess = new QProcess( this );
 
230
        Q3Process * chmodProcess = new Q3Process( this );
204
231
        chmodProcess->addArgument( "chmod" );
205
232
        chmodProcess->addArgument( mode );
206
233
        chmodProcess->addArgument( file );
207
234
 
208
235
        if ( !chmodProcess->start(env) ) {
209
 
                // KMessageBox::sorry( this, i18n( "\"%1\" start failed!" ).arg( "PppdUpScript" ) );
210
 
                config->appendLogEntry( i18n( "Chmod of %1 failed!" ).arg( file ), config->error );
 
236
                // KMessageBox::sorry( this, i18n( "\"%1\" start failed!" , QString("PppdUpScript" )) );
 
237
                GlobalConfig->appendLogEntry( i18n( "Chmod of %1 failed!" ,  file ), GlobalConfig->error );
211
238
                return false;
212
239
        } else {
213
 
                if ( config->KvpncDebugLevel > 0 )
214
 
                        config->appendLogEntry ( i18n( "chmod of %1 (%2) started." ).arg( file ).arg( mode ) , config->debug );
 
240
                if ( GlobalConfig->KvpncDebugLevel > 0 )
 
241
                        GlobalConfig->appendLogEntry ( i18n( "chmod of %1 (%2) started." ,  file ,  mode ) , GlobalConfig->debug );
215
242
                while ( chmodProcess->isRunning() )
216
 
                        config->appPointer->QApplication::processEvents();
217
 
                //GlobalConfig->appendLogEntry ( i18n( "\"%1\" finished." ).arg("chmod"),GlobalConfig->info );
 
243
                        GlobalConfig->appPointer->QApplication::processEvents();
 
244
                //GlobalConfig->appendLogEntry ( i18n( "\"%1\" finished." , QString("chmod")),GlobalConfig->info );
218
245
                return true;
219
246
        }
220
247
}
229
256
        return resolvConfAvailable;
230
257
}
231
258
 
232
 
QPtrList<ToolInfo>* Utils::getToolList()
 
259
Q3PtrList<ToolInfo>* Utils::getToolList()
233
260
{
234
 
        QPtrList<ToolInfo> *ToolList = new QPtrList<ToolInfo>();
 
261
        Q3PtrList<ToolInfo> *ToolList = new Q3PtrList<ToolInfo>();
235
262
 
236
263
        //TODO move to KVpncConfig
237
264
        QStringList *ToolNamesList = new QStringList();
238
265
        ToolNamesList->append( "vpnc" );
239
266
        ToolNamesList->append( "vpnclient" );
240
267
        ToolNamesList->append( "racoon" );
 
268
        ToolNamesList->append( "racoonctl" );
241
269
        ToolNamesList->append( "ipsec" ); // freeswan
242
270
        ToolNamesList->append( "pppd" );
243
271
        ToolNamesList->append( "pptp" );
244
272
        ToolNamesList->append( "l2tpd" );
245
273
        ToolNamesList->append( "xl2tpd" );
 
274
        ToolNamesList->append( "openl2tpd" );
246
275
        ToolNamesList->append( "setkey" );
247
276
        ToolNamesList->append( "iptables" );
248
277
        ToolNamesList->append( "openssl" );
257
286
        ToolNamesList->append( "bash" );
258
287
        ToolNamesList->append( "vtund" );
259
288
        ToolNamesList->append( "cisco_cert_mgr" );
 
289
        ToolNamesList->append( "tail" );
 
290
        ToolNamesList->append( "ssh" );
 
291
        ToolNamesList->append( "ksshaskpass" );
 
292
        ToolNamesList->append( "gnome-ssh-askpass" );
260
293
 
261
294
        ToolInfo *currentTool;
262
295
        for ( QStringList::Iterator it = ToolNamesList->begin(); it != ToolNamesList->end(); it++ ) {
263
 
                //std::cout << "tool: " << *it << std::endl;
 
296
                //std::cout << "tool: " << qPrintable(QString(*it)) << std::endl;
264
297
 
265
298
                currentTool = new ToolInfo( *it );
266
 
                currentTool->programsInPath =config->programsInPath;
 
299
                currentTool->programsInPath =GlobalConfig->programsInPath;
267
300
                if ( currentTool->Name == "vpnc" )
268
 
                        currentTool->TryPath_first = config->pathToVpnc;
 
301
                        currentTool->TryPath_first = GlobalConfig->pathToVpnc;
269
302
                else if (currentTool->Name == "vpnclient")
270
 
                        currentTool->TryPath_first = config->pathToCiscoVpnc;
 
303
                        currentTool->TryPath_first = GlobalConfig->pathToCiscoVpnc;
271
304
                else    if ( currentTool->Name == "ipsec" )
272
 
                        currentTool->TryPath_first = config->pathToFreeswan;
 
305
                        currentTool->TryPath_first = GlobalConfig->pathToIpsec;
273
306
                else    if ( currentTool->Name == "racoon" )
274
 
                        currentTool->TryPath_first = config->pathToRacoon;
 
307
                        currentTool->TryPath_first = GlobalConfig->pathToRacoon;
 
308
                else    if ( currentTool->Name == "racoonctl" )
 
309
                        currentTool->TryPath_first = GlobalConfig->pathToRacoonctl;
275
310
                else    if ( currentTool->Name == "setkey" )
276
 
                        currentTool->TryPath_first = config->pathToSetkey;
 
311
                        currentTool->TryPath_first = GlobalConfig->pathToSetkey;
277
312
                else    if ( currentTool->Name == "openvpn" )
278
 
                        currentTool->TryPath_first = config->pathToOpenvpn;
 
313
                        currentTool->TryPath_first = GlobalConfig->pathToOpenvpn;
279
314
                else    if ( currentTool->Name == "openssl" )
280
 
                        currentTool->TryPath_first = config->pathToOpenssl;
 
315
                        currentTool->TryPath_first = GlobalConfig->pathToOpenssl;
281
316
                else    if ( currentTool->Name == "pppd" )
282
 
                        currentTool->TryPath_first = config->pathToPppd;
 
317
                        currentTool->TryPath_first = GlobalConfig->pathToPppd;
283
318
                else    if ( currentTool->Name == "iptables" )
284
 
                        currentTool->TryPath_first = config->pathToIptables;
 
319
                        currentTool->TryPath_first = GlobalConfig->pathToIptables;
285
320
                else    if ( currentTool->Name == "kill" )
286
 
                        currentTool->TryPath_first = config->pathToKill;
 
321
                        currentTool->TryPath_first = GlobalConfig->pathToKill;
287
322
                else    if ( currentTool->Name == "killall" )
288
 
                        currentTool->TryPath_first = config->pathToKillall;
 
323
                        currentTool->TryPath_first = GlobalConfig->pathToKillall;
289
324
                else    if ( currentTool->Name == "ping" )
290
 
                        currentTool->TryPath_first = config->pathToPing;
 
325
                        currentTool->TryPath_first = GlobalConfig->pathToPing;
291
326
                else    if ( currentTool->Name == "ip" )
292
 
                        currentTool->TryPath_first = config->pathToIp;
 
327
                        currentTool->TryPath_first = GlobalConfig->pathToIp;
293
328
                else    if ( currentTool->Name == "ifconfig" )
294
 
                        currentTool->TryPath_first = config->pathToIfconfig;
 
329
                        currentTool->TryPath_first = GlobalConfig->pathToIfconfig;
295
330
                else    if ( currentTool->Name == "route" )
296
 
                        currentTool->TryPath_first = config->pathToRoute;
 
331
                        currentTool->TryPath_first = GlobalConfig->pathToRoute;
297
332
                else    if ( currentTool->Name == "pptp" )
298
 
                        currentTool->TryPath_first = config->pathToPptp;
 
333
                        currentTool->TryPath_first = GlobalConfig->pathToPptp;
299
334
                else    if ( currentTool->Name == "l2tpd" )
300
 
                        currentTool->TryPath_first = config->pathToL2tpd;
 
335
                        currentTool->TryPath_first = GlobalConfig->pathToL2tpd;
301
336
                else    if ( currentTool->Name == "pkcs11-tool" )
302
 
                        currentTool->TryPath_first = config->pathToPkcs11Tool;
 
337
                        currentTool->TryPath_first = GlobalConfig->pathToPkcs11Tool;
303
338
                else    if ( currentTool->Name == "bash" )
304
 
                        currentTool->TryPath_first = config->InterpreterShell;
 
339
                        currentTool->TryPath_first = GlobalConfig->InterpreterShell;
305
340
                else    if ( currentTool->Name == "vtund" )
306
 
                        currentTool->TryPath_first = config->pathToVtund;
 
341
                        currentTool->TryPath_first = GlobalConfig->pathToVtund;
307
342
                else if ( currentTool->Name == "cisco_cert_mgr" )
308
 
                        currentTool->TryPath_first = config->pathToCiscoCertMgr;
 
343
                        currentTool->TryPath_first = GlobalConfig->pathToCiscoCertMgr;
 
344
                else if ( currentTool->Name == "tail" )
 
345
                        currentTool->TryPath_first = GlobalConfig->pathToTail;
 
346
                else if ( currentTool->Name == "ssh" )
 
347
                        currentTool->TryPath_first = GlobalConfig->pathToSsh;
 
348
                else if ( currentTool->Name == "ksshaskpass" )
 
349
                        currentTool->TryPath_first = GlobalConfig->pathToKsshAskpass;
 
350
                else if ( currentTool->Name == "gnome-ssh-askpass" )
 
351
                        currentTool->TryPath_first = GlobalConfig->pathToGnomeSshAskpass;
309
352
 
310
353
                ToolList->append( currentTool );
311
354
                currentTool->collectToolInfo();
312
355
                //currentTool=0L;
313
 
                //                      std::cout << "tool: " << currentTool->Name << std::endl;
314
 
                //                      std::cout << "Version: " << currentTool->Version << std::endl;
315
 
                //                      std::cout << "Path: " << currentTool->PathToExec << std::endl << std::endl;
 
356
                //                      std::cout << "tool: " << qPrintable(currentTool->Name) << std::endl;
 
357
                //                      std::cout << "Version: " << qPrintable(currentTool->Version) << std::endl;
 
358
                //                      std::cout << "Path: " << qPrintable(currentTool->PathToExec) << std::endl << std::endl;
316
359
        }
317
360
        ToolList->sort();
318
361
 
320
363
 
321
364
}
322
365
 
323
 
ToolInfo* Utils::getToolInfo( KVpncConfig *GlobalConfig, QString name )
 
366
ToolInfo* Utils::getToolInfo( QString name )
324
367
{
325
368
        ToolInfo * Tool = 0;
326
369
        for ( Tool = GlobalConfig->ToolList->first();Tool;Tool = GlobalConfig->ToolList->next() ) {
338
381
        struct hostent * server_entry;
339
382
 
340
383
        // get ip address to server name
341
 
        if ( ( server_entry = gethostbyname( Name.ascii() ) ) == NULL ) {
342
 
                printf( "gethostbyname failed\n" );
343
 
        } else
 
384
        if ( ( server_entry = gethostbyname( Name.ascii() ) ) == NULL )
 
385
        {
 
386
                std::cout << "gethostbyname failed" << std::endl;
 
387
        }
 
388
        else
344
389
                resolvedIP = QString( inet_ntoa( *( struct in_addr* ) server_entry->h_addr_list[ 0 ] ) );
345
390
        return resolvedIP;
346
391
}
374
419
        OpenvpnCiphers.clear();
375
420
        retrieveOpenvpnCiphers = false;
376
421
 
377
 
        ToolInfo *OpenvpnInfo = getToolInfo( config, "openvpn" );
 
422
        ToolInfo *OpenvpnInfo = getToolInfo( "openvpn" );
378
423
        QString pathToOpenvpn = OpenvpnInfo->PathToExec;
379
424
 
380
425
        if ( pathToOpenvpn.isEmpty() )
381
426
                return OpenvpnCiphers;
382
427
 
383
 
        OpenvpnCiphersProcess = new QProcess( this );
 
428
        OpenvpnCiphersProcess = new Q3Process( this );
384
429
        OpenvpnCiphersProcess->addArgument( pathToOpenvpn );
385
430
        OpenvpnCiphersProcess->addArgument( "--show-ciphers" );
386
431
 
387
 
        connect( OpenvpnCiphersProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutRetriveOpenvpnCiphers() ) );
388
 
        connect( OpenvpnCiphersProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrRetriveOpenvpnCiphers() ) );
 
432
        connect( OpenvpnCiphersProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutRetrieveOpenvpnCiphers() ) );
 
433
        connect( OpenvpnCiphersProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrRetrieveOpenvpnCiphers() ) );
389
434
 
390
435
        if ( !OpenvpnCiphersProcess->start( env ) ) {
391
 
                kdError() << "Unable to fetch openvpn ciphers!" << endl;
392
 
                return false;
 
436
                kError() << "Unable to fetch openvpn ciphers!" << endl;
 
437
                return OpenvpnCiphers;
393
438
        } else {
394
439
                while ( OpenvpnCiphersProcess->isRunning() )
395
 
                        config->appPointer->processEvents();
396
 
 
397
 
 
398
 
                disconnect( OpenvpnCiphersProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutRetriveOpenvpnCiphers() ) );
399
 
                disconnect( OpenvpnCiphersProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrRetriveOpenvpnCiphers() ) );
 
440
                        GlobalConfig->appPointer->processEvents();
 
441
 
 
442
 
 
443
                disconnect( OpenvpnCiphersProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutRetrieveOpenvpnCiphers() ) );
 
444
                disconnect( OpenvpnCiphersProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrRetrieveOpenvpnCiphers() ) );
400
445
 
401
446
        }
402
447
        return OpenvpnCiphers;
403
448
}
404
449
 
 
450
Utils::IpsecAlgos Utils::getIpsecAlgos()
 
451
{
 
452
 
 
453
        IpsecAlgos salgos;
 
454
        salgos.IpsecIkeEncryptionAlgorithms.clear();
 
455
        salgos.IpsecIkeHashAlgorithms.clear();
 
456
        salgos.IpsecIkeDhGroups.clear();
 
457
        salgos.IpsecEspEncryptionAlgorithms.clear();
 
458
        salgos.IpsecEspAuthenticationAlgorithms.clear();
 
459
        salgos.IpsecCompressionAlgorithms.clear();
 
460
        IpsecAlgoCurrent="";
 
461
        retrieveIpsecAlgos = false;
 
462
 
 
463
        ToolInfo *IpsecInfo = getToolInfo(  "ipsec" );
 
464
        QString pathToIpsec = IpsecInfo->PathToExec;
 
465
 
 
466
        if ( pathToIpsec.isEmpty() )
 
467
                return salgos;
 
468
 
 
469
        IpsecAlgosProcess = new Q3Process( this );
 
470
        IpsecAlgosProcess->addArgument( pathToIpsec);
 
471
        IpsecAlgosProcess->addArgument( "auto" );
 
472
        IpsecAlgosProcess->addArgument( "--status" );
 
473
 
 
474
        connect( IpsecAlgosProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutRetrieveIpsecAlgos() ) );
 
475
        connect( IpsecAlgosProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrRetrieveIpsecAlgos() ) );
 
476
 
 
477
        if ( !IpsecAlgosProcess->start( env ) ) {
 
478
                kdError() << "Unable to fetch ipsec algos!" << endl;
 
479
                return salgos;
 
480
        } else {
 
481
                while ( IpsecAlgosProcess->isRunning() )
 
482
                        GlobalConfig->appPointer->processEvents();
 
483
 
 
484
 
 
485
                disconnect( IpsecAlgosProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutRetrieveIpsecAlgos() ) );
 
486
                disconnect( IpsecAlgosProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrRetrieveIpsecAlgos() ) );
 
487
 
 
488
        }
 
489
        return salgos;
 
490
}
 
491
 
 
492
Utils::PppdCapabilities Utils::checkPppdCapabilities()
 
493
{
 
494
                pppdcap.pppdHasMppeRequiredSupport=false;
 
495
                pppdcap.pppdHasRequireMppeSupport=false;
 
496
                pppdcap.pppdHasReplacedefaultrouteSupport=false;
 
497
                pppdcap.pppdHasMppeSupport=false;
 
498
                pppdcap.oldPppdStyle=false;
 
499
                pppdcap.pppdOk=false;
 
500
 
 
501
                // test mppe support of pppd
 
502
                testPppdRequireMppe=true;
 
503
                testPppdReplacedefaultroute=false;
 
504
                testPppdMppeRequiredSupport=false;
 
505
                testOldPppdStyle=false;
 
506
                testPppdRequireMppe=false;
 
507
                testPppdMppeRequired=false;
 
508
 
 
509
 
 
510
                /* get pppd info */
 
511
                int pppd_version_major = 0;
 
512
                int pppd_version_minor = 0;
 
513
                int pppd_version_subminor = 0;
 
514
 
 
515
                ToolInfo *Tool = Utils (GlobalConfig  ).getToolInfo ( "pppd" );
 
516
                if ( !Tool->Version.isEmpty() )
 
517
                {
 
518
                        pppd_version_major = ( Tool->Version.section ( '.', 0, 0 ) ).toInt();
 
519
                        pppd_version_minor = ( Tool->Version.section ( '.', 1, 1 ) ).toInt();
 
520
                        pppd_version_subminor = ( Tool->Version.section ( '.', 2, 2 ) ).toInt();
 
521
                        if ( GlobalConfig->KvpncDebugLevel > 5 )
 
522
                        {
 
523
                                GlobalConfig->appendLogEntry ( i18n ( "pppd version (major): \"%1\"" , QString( pppd_version_major )) , GlobalConfig->debug );
 
524
                                GlobalConfig->appendLogEntry ( i18n ( "pppd version (minor): \"%1\"" , QString( pppd_version_minor )) , GlobalConfig->debug );
 
525
                                GlobalConfig->appendLogEntry ( i18n ( "pppd version (subminor): \"%1\"" , QString( pppd_version_subminor )) , GlobalConfig->debug );
 
526
                        }
 
527
                }
 
528
 
 
529
                if ( pppd_version_major <2 || (pppd_version_major ==2 && pppd_version_minor < 4  )  )
 
530
                {
 
531
                        // pppd < 2.4.0
 
532
                        if ( GlobalConfig->KvpncDebugLevel > 5 )
 
533
                                GlobalConfig->appendLogEntry ( i18n ( "pppd version is lower than 2.4.0" ) , GlobalConfig->debug );
 
534
                        
 
535
                        pppdcap.RequireMppeOption="";
 
536
                        pppdcap.Require128BitMppeOption="";
 
537
                        pppdcap.RefuseMppeOption="";
 
538
                        pppdcap.Refuse40BitMppeOption="";
 
539
                        pppdcap.Refuse128BitMppeOption="";
 
540
 
 
541
                        pppdcap.RequireStatelessOption="";
 
542
                        pppdcap.RequireStatefulOption="";
 
543
                        pppdcap.MppeOptionsInALine = false;
 
544
                        pppdcap.RequireAuthMschapOption="";
 
545
                        pppdcap.RequireAuthMschapv2Option="";
 
546
                        pppdcap.RequireAuthPapOption="";
 
547
                }
 
548
 
 
549
                if  (pppd_version_major ==2 && pppd_version_minor == 4  && (pppd_version_subminor == 0  || pppd_version_subminor == 0 ) )
 
550
                {
 
551
                        // pppd == 2.4.0/2.4.1
 
552
                        if ( GlobalConfig->KvpncDebugLevel > 5 )
 
553
                                GlobalConfig->appendLogEntry ( i18n ( "pppd version is 2.4.0" ) , GlobalConfig->debug );
 
554
                        
 
555
                        pppdcap.RequireMppeOption="mppe-40";
 
556
                        pppdcap.Require128BitMppeOption="mppe-128";
 
557
                        pppdcap.RefuseMppeOption="";
 
558
                        pppdcap.Refuse40BitMppeOption="";
 
559
                        pppdcap.Refuse128BitMppeOption="";
 
560
 
 
561
                        pppdcap.RequireStatelessOption="mppe-stateless";
 
562
                        pppdcap.RequireStatefulOption="";
 
563
                        pppdcap.MppeOptionsInALine = false;
 
564
                        pppdcap.RequireAuthChapOption="";
 
565
                        pppdcap.RequireAuthChapOption+="require-chap\n";
 
566
                        pppdcap.RequireAuthChapOption+="refuse-chapms\n";
 
567
                        pppdcap.RequireAuthChapOption+="refuse-chapms-v2\n";
 
568
                        pppdcap.RequireAuthChapOption+="refuse-pap\n";
 
569
                        pppdcap.RequireAuthChapOption+="refuse-eap";
 
570
                        pppdcap.RequireAuthMschapOption="";
 
571
//                      pppdcap.RequireAuthMschapOption+="refuse-chap\n";
 
572
                        pppdcap.RequireAuthMschapOption+="require-chapms\n";
 
573
//                      pppdcap.RequireAuthMschapOption+="require-chapms-v2\n";
 
574
                        pppdcap.RequireAuthMschapOption+="refuse-pap\n";
 
575
                        pppdcap.RequireAuthMschapOption+="refuse-eap";
 
576
                        pppdcap.RequireAuthMschapv2Option="";
 
577
//                      pppdcap.RequireAuthMschapv2Option+="refuse-chap\n";
 
578
//                      pppdcap.RequireAuthMschapv2Option+="refuse-chapms\n";
 
579
                        pppdcap.RequireAuthMschapv2Option+="require-chapms-v2\n";
 
580
                        pppdcap.RequireAuthMschapv2Option+="refuse-pap\nrefuse-eap";
 
581
                        pppdcap.RequireAuthPapOption="";
 
582
                        pppdcap.RequireAuthPapOption+="require-pap\n";
 
583
                        pppdcap.RequireAuthPapOption+="refuse-chap\n";
 
584
                        pppdcap.RequireAuthPapOption+="refuse-chapms-v2\n";
 
585
                        pppdcap.RequireAuthPapOption+="refuse-chapms-v2\n";
 
586
                        pppdcap.RequireAuthPapOption+="refuse-eap";
 
587
                }
 
588
 
 
589
                if ( ( pppd_version_major ==2 && pppd_version_minor == 4 && pppd_version_subminor >= 2) || pppd_version_major >2  )
 
590
                {
 
591
                        // pppd >= 2.4.2
 
592
                        if ( GlobalConfig->KvpncDebugLevel > 5 )
 
593
                                GlobalConfig->appendLogEntry ( i18n ( "pppd version is >= 2.4.2, good" ) , GlobalConfig->debug );
 
594
                        
 
595
                        pppdcap.RequireMppeOption="require-mppe";
 
596
                        pppdcap.Require128BitMppeOption="require-mppe-128";
 
597
                        pppdcap.RefuseMppeOption="nomppe";
 
598
                        pppdcap.Refuse40BitMppeOption="nomppe-40";
 
599
                        pppdcap.Refuse128BitMppeOption="nomppe-128";
 
600
 
 
601
                        pppdcap.RequireStatelessOption="nomppe-stateful";
 
602
                        pppdcap.RequireStatefulOption="";
 
603
                        pppdcap.MppeOptionsInALine = false;
 
604
                        pppdcap.RequireAuthChapOption="";
 
605
                        pppdcap.RequireAuthChapOption+="refuse-pap\n";
 
606
                        pppdcap.RequireAuthChapOption+="refuse-mschap\n";
 
607
                        pppdcap.RequireAuthChapOption+="refuse-mschap-v2\n";
 
608
                        pppdcap.RequireAuthChapOption+="refuse-eap";
 
609
                        pppdcap.RequireAuthMschapOption="";
 
610
                        pppdcap.RequireAuthMschapOption+="refuse-pap\n";
 
611
//                      pppdcap.RequireAuthMschapOption+="refuse-chap\n";
 
612
//                      pppdcap.RequireAuthMschapOption+="refuse-mschap-v2\n";
 
613
                        pppdcap.RequireAuthMschapOption+="refuse-eap";
 
614
                        pppdcap.RequireAuthMschapv2Option="";
 
615
                        pppdcap.RequireAuthMschapv2Option+="refuse-pap\n";
 
616
//                      pppdcap.RequireAuthMschapv2Option+="refuse-chap\n";
 
617
//                      pppdcap.RequireAuthMschapv2Option+="refuse-mschap\n";
 
618
                        pppdcap.RequireAuthMschapv2Option+="refuse-eap";
 
619
                        pppdcap.RequireAuthPapOption="";
 
620
                        pppdcap.RequireAuthPapOption+="refuse-mschap\n";
 
621
                        pppdcap.RequireAuthPapOption+="refuse-mschap-v2\n";
 
622
                        pppdcap.RequireAuthPapOption+="refuse-chap\n";
 
623
                        pppdcap.RequireAuthPapOption+="refuse-eap";
 
624
                }
 
625
 
 
626
 
 
627
                /* mppe test */
 
628
 
 
629
                pppdcap.pppdHasMppeRequiredSupport=true;
 
630
                pppdcap.pppdHasRequireMppeSupport=true;
 
631
                pppdcap.pppdHasMppeSupport=true;
 
632
                // first: new style
 
633
                testOldPppdStyle = false;
 
634
                testPppdRequireMppe=true;
 
635
                testPppdMppeRequired=false;
 
636
                TestPppdProcess = new Q3Process ( this );
 
637
                TestPppdProcess->addArgument ( GlobalConfig->pathToPppd );
 
638
                TestPppdProcess->addArgument ( "/dev/null" );
 
639
                TestPppdProcess->addArgument ( "require-mppe" );
 
640
 
 
641
                TestPppdProcess->setCommunication ( Q3Process::Stdin | Q3Process::Stdout | Q3Process::Stderr | Q3Process::DupStderr );
 
642
                TestPppdProcess->closeStdin ();
 
643
 
 
644
                connect ( TestPppdProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readPppdtestProcessOutput() ) );
 
645
//              connect ( TestPppdProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readPppdtestProcessOutput() ) );
 
646
                
 
647
                if ( !TestPppdProcess->start ( env ) )
 
648
                {
 
649
                        GlobalConfig->appendLogEntry ( i18n ( "unable to start proc (%1)!" , QString( i18n ( "Test require-mppe support of pppd" )) ) , KVpncConfig::error );
 
650
                        pppdcap.pppdOk=false;
 
651
                }
 
652
                else
 
653
                {
 
654
                        pppdcap.pppdOk=true;
 
655
                        while ( TestPppdProcess->isRunning() )
 
656
                                GlobalConfig->appPointer->processEvents();
 
657
 
 
658
 
 
659
                        if (pppdcap.pppdHasRequireMppeSupport)
 
660
                        {
 
661
                                if ( GlobalConfig->KvpncDebugLevel > 0 )
 
662
                                        GlobalConfig->appendLogEntry ( "pppdHasRequireMppeSupport: true", GlobalConfig->debug );
 
663
                                pppdcap.RequireMppeOption="require-mppe";
 
664
                                pppdcap.Require128BitMppeOption="require-mppe-128";
 
665
                                pppdcap.RefuseMppeOption="nomppe";
 
666
                                pppdcap.Refuse40BitMppeOption="nomppe-40";
 
667
                                pppdcap.Refuse128BitMppeOption="nomppe-128";
 
668
                        }
 
669
                        else
 
670
                                GlobalConfig->appendLogEntry ( "pppdHasRequireMppeSupport: false", GlobalConfig->debug );
 
671
 
 
672
                        disconnect ( TestPppdProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readPppdtestProcessOutput() ) );
 
673
                        disconnect ( TestPppdProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readPppdtestProcessOutput() ) );
 
674
                }
 
675
 
 
676
                delete TestPppdProcess;
 
677
                testPppdRequireMppe=false;
 
678
                testPppdMppeRequired=true;
 
679
 
 
680
 
 
681
                TestPppdProcess = new Q3Process ( this );
 
682
                TestPppdProcess->addArgument ( GlobalConfig->pathToPppd );
 
683
                TestPppdProcess->addArgument ( "/dev/null" );
 
684
                TestPppdProcess->addArgument ( "mppe");
 
685
                TestPppdProcess->addArgument ( "required" );
 
686
 
 
687
                TestPppdProcess->setCommunication ( Q3Process::Stdin | Q3Process::Stdout | Q3Process::Stderr | Q3Process::DupStderr );
 
688
                TestPppdProcess->closeStdin ();
 
689
 
 
690
                connect ( TestPppdProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readPppdtestProcessOutput() ) );
 
691
//              connect ( TestPppdProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readPppdtestProcessOutput() ) );
 
692
                
 
693
                if ( !TestPppdProcess->start ( env ) )
 
694
                {
 
695
                        GlobalConfig->appendLogEntry ( i18n ( "unable to start proc (%1)!" , QString( i18n ( "Test mppe required support of pppd" )) ), KVpncConfig::error );
 
696
                        pppdcap.pppdOk=false;
 
697
                }
 
698
                else
 
699
                {
 
700
                        pppdcap.pppdOk=true;
 
701
                        while ( TestPppdProcess->isRunning() )
 
702
                                GlobalConfig->appPointer->processEvents();
 
703
 
 
704
                        if (pppdcap.pppdHasMppeRequiredSupport)
 
705
                        {
 
706
                                if ( GlobalConfig->KvpncDebugLevel > 0 )
 
707
                                                GlobalConfig->appendLogEntry ( "PppdMppeRequired: true", GlobalConfig->debug );
 
708
 
 
709
                                pppdcap.MppeOptionsInALine = true;
 
710
 
 
711
                                pppdcap.RequireMppeOption="mppe required";
 
712
                                pppdcap.Require128BitMppeOption="";
 
713
                                pppdcap.RefuseMppeOption="nomppe";
 
714
                                pppdcap.Refuse40BitMppeOption=",no40";
 
715
                                pppdcap.Refuse128BitMppeOption=",no128";
 
716
                                pppdcap.RequireStatefulOption="";
 
717
                                pppdcap.RequireStatelessOption=",stateless";
 
718
 
 
719
                        }
 
720
                        else
 
721
                                GlobalConfig->appendLogEntry ( "PppdMppeRequired: false", GlobalConfig->debug );
 
722
                        
 
723
 
 
724
                        disconnect ( TestPppdProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readPppdtestProcessOutput() ) );
 
725
                        disconnect ( TestPppdProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readPppdtestProcessOutput() ) );
 
726
                }
 
727
 
 
728
                
 
729
                delete TestPppdProcess;
 
730
                testPppdMppeRequired=false;
 
731
 
 
732
 
 
733
 
 
734
 
 
735
                if (pppdcap.pppdHasRequireMppeSupport || pppdcap.pppdHasMppeRequiredSupport)
 
736
                {
 
737
                        pppdcap.pppdHasMppeSupport = true;
 
738
                        if ( GlobalConfig->KvpncDebugLevel > 0 )
 
739
                                GlobalConfig->appendLogEntry ( i18n ( " %1 has MPPE support." , QString( GlobalConfig->pathToPppd )), GlobalConfig->debug );
 
740
                }
 
741
                else
 
742
                {
 
743
                        if ( GlobalConfig->KvpncDebugLevel > 0 )
 
744
                                GlobalConfig->appendLogEntry ( i18n ( " %1 has no MPPE support." , QString(GlobalConfig->pathToPppd )), GlobalConfig->debug );
 
745
 
 
746
                }
 
747
 
 
748
 
 
749
                /* defaultroute test */
 
750
                //unrecognized option 'replacedefaultroute'
 
751
                // test defaultroute support of pppd
 
752
                testPppdReplacedefaultroute = false;
 
753
                TestPppdProcess = new Q3Process ( this );
 
754
                TestPppdProcess->addArgument ( GlobalConfig->pathToPppd );
 
755
                TestPppdProcess->addArgument ( "replacedefaultroute" );
 
756
                TestPppdProcess->setCommunication ( Q3Process::Stdin | Q3Process::Stdout | Q3Process::Stderr | Q3Process::DupStderr );
 
757
                TestPppdProcess->closeStdin ();
 
758
 
 
759
                connect ( TestPppdProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readPppdtestProcessOutput() ) );
 
760
//              connect ( TestPppdProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readPppdtestProcessOutput() ) );
 
761
 
 
762
 
 
763
                if ( !TestPppdProcess->start ( env ) )
 
764
                {
 
765
                        GlobalConfig->appendLogEntry ( i18n ( "unable to start proc (%1)!" , QString( i18n ( "Test support of replacedefaultroute pppd" ) )) , GlobalConfig->error );
 
766
                        pppdcap.pppdOk=false;
 
767
                }
 
768
                else
 
769
                {
 
770
                        while ( TestPppdProcess->isRunning() )
 
771
                                GlobalConfig->appPointer->processEvents();
 
772
 
 
773
                        disconnect ( TestPppdProcess, SIGNAL ( readyReadStdout() ), this, SLOT ( readPppdtestProcessOutput() ) );
 
774
                        disconnect ( TestPppdProcess, SIGNAL ( readyReadStderr() ), this, SLOT ( readPppdtestProcessOutput() ) );
 
775
 
 
776
                        if ( pppdcap.pppdHasReplacedefaultrouteSupport )
 
777
                        {
 
778
                                if ( GlobalConfig->KvpncDebugLevel > 1 )
 
779
                                        GlobalConfig->appendLogEntry ( i18n ( "Test support of replacedefaultroute pppd: %1" , QString( i18n ( "succeded" ) )) , GlobalConfig->debug );
 
780
                        }
 
781
                        else
 
782
                        {
 
783
                                if ( GlobalConfig->KvpncDebugLevel > 1 )
 
784
                                        GlobalConfig->appendLogEntry ( i18n ( "Test support of replacedefaultroute pppd: %1" , QString( i18n ( "failed" ) )) , GlobalConfig->debug );
 
785
                        }
 
786
                }
 
787
 
 
788
 
 
789
        return pppdcap;
 
790
}
 
791
 
405
792
QStringList Utils::getOpenvpnDigests()
406
793
{
407
794
        OpenvpnDigests.clear();
409
796
        OpenvpnDigestCount=0;
410
797
        OpenvpnDigestString="";
411
798
 
412
 
        ToolInfo *OpenvpnInfo = getToolInfo( config, "openvpn" );
 
799
        ToolInfo *OpenvpnInfo = getToolInfo(  "openvpn" );
413
800
        QString pathToOpenvpn = OpenvpnInfo->PathToExec;
414
801
 
415
802
        if ( pathToOpenvpn.isEmpty() )
416
803
                return OpenvpnDigests;
417
804
 
418
 
        OpenvpnDigestProcess = new QProcess( this );
 
805
        OpenvpnDigestProcess = new Q3Process( this );
419
806
        OpenvpnDigestProcess->addArgument( pathToOpenvpn );
420
807
        OpenvpnDigestProcess->addArgument( "--show-digests" );
421
808
 
422
 
        connect( OpenvpnDigestProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutRetriveOpenvpnDigests() ) );
423
 
        connect( OpenvpnDigestProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrRetriveOpenvpnDigests() ) );
 
809
        connect( OpenvpnDigestProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutRetrieveOpenvpnDigests() ) );
 
810
        connect( OpenvpnDigestProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrRetrieveOpenvpnDigests() ) );
424
811
 
425
812
        if ( !OpenvpnDigestProcess->start( env ) ) {
426
 
                kdError() << "Unable to fetch openvpn digests!" << endl;
427
 
                return false;
 
813
                kError() << "Unable to fetch openvpn digests!" << endl;
 
814
                return OpenvpnDigests;
428
815
        } else {
429
816
                while ( OpenvpnDigestProcess->isRunning() )
430
 
                        config->appPointer->processEvents();
 
817
                        GlobalConfig->appPointer->processEvents();
431
818
 
432
 
                disconnect( OpenvpnDigestProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutRetriveOpenvpnDigests() ) );
433
 
                disconnect( OpenvpnDigestProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrRetriveOpenvpnDigests() ) );
 
819
                disconnect( OpenvpnDigestProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutRetrieveOpenvpnDigests() ) );
 
820
                disconnect( OpenvpnDigestProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrRetrieveOpenvpnDigests() ) );
434
821
 
435
822
                OpenvpnDigests = QStringList().split("#",OpenvpnDigestString);
436
823
 
441
828
        return OpenvpnDigests;
442
829
}
443
830
 
444
 
QStringList Utils::getKernelCrypto()
 
831
Utils::IpsecAlgos Utils::getKernelCrypto()
445
832
{
446
 
        KernelCrypto.clear();
 
833
        IpsecAlgos salgos;
 
834
        salgos.IpsecIkeEncryptionAlgorithms.clear();
 
835
        salgos.IpsecIkeHashAlgorithms.clear();
 
836
        salgos.IpsecIkeDhGroups.clear();
 
837
        salgos.IpsecEspEncryptionAlgorithms.clear();
 
838
        salgos.IpsecEspAuthenticationAlgorithms.clear();
 
839
        salgos.IpsecCompressionAlgorithms.clear();
 
840
        QString IpsecAlgoNameCurrent="";
 
841
        QString IpsecAlgoTypeCurrent="";
447
842
        QFile cryptoprocfile( "/proc/crypto" );
448
843
 
449
 
        if ( cryptoprocfile.open( IO_ReadOnly ) ) {
 
844
        if ( cryptoprocfile.open( IO_ReadOnly ) )
 
845
        {
450
846
                QTextStream stream( &cryptoprocfile );
451
847
                QString line;
452
 
                if (config->KvpncDebugLevel > 2)
453
 
//              std::cout << "Kernel crypto list: " << std::endl;
 
848
                if (GlobalConfig->KvpncDebugLevel > 2)
 
849
                        std::cout << "Kernel crypto list: " << std::endl;
454
850
                while ( !stream.atEnd() ) {
455
851
                        line = stream.readLine();
456
852
                        if (line.find("name") > -1 )
457
853
                        {
458
 
                                QString crypto = line.section(':',1,1).stripWhiteSpace();
459
 
                                KernelCrypto.append(crypto);
460
 
//                              std::cout << "crypto: " << crypto.ascii() << std::endl;
 
854
                                IpsecAlgoNameCurrent = line.section(':',1,1).stripWhiteSpace();
 
855
//                              std::cout << "crypto name: " << IpsecAlgoNameCurrent.ascii() << std::endl;
 
856
                        }
 
857
                        if (line.find("type") >-1)
 
858
                        {
 
859
                                IpsecAlgoTypeCurrent=line.section(':',1,1).stripWhiteSpace();
 
860
//                              std::cout << "crypto type: " << IpsecAlgoTypeCurrent.ascii() << std::endl;
 
861
 
 
862
                                if (IpsecAlgoTypeCurrent == "blkcipher" || IpsecAlgoTypeCurrent == "cipher")
 
863
                                {
 
864
                                        std::cout << "adding cipher/blkcipher algo " << qPrintable(IpsecAlgoNameCurrent) << std::endl;
 
865
                                        salgos.IpsecEspEncryptionAlgorithms.append(IpsecAlgoNameCurrent);
 
866
                                }
 
867
                                if (IpsecAlgoTypeCurrent == "digest")
 
868
                                {
 
869
                                        std::cout  << "adding digest algo " << qPrintable(IpsecAlgoNameCurrent) << std::endl;
 
870
                                        salgos.IpsecEspAuthenticationAlgorithms.append(IpsecAlgoNameCurrent);
 
871
                                }
 
872
                                if (IpsecAlgoTypeCurrent == "hash")
 
873
                                {
 
874
                                        std::cout  << "adding hash algo " << qPrintable(IpsecAlgoNameCurrent) << std::endl;
 
875
                                        salgos.IpsecIkeHashAlgorithms.append(IpsecAlgoNameCurrent);
 
876
                                }
 
877
                                if (IpsecAlgoTypeCurrent == "compression")
 
878
                                {
 
879
                                        std::cout  << "adding compression algo " << qPrintable(IpsecAlgoNameCurrent) << std::endl;
 
880
                                        salgos.IpsecCompressionAlgorithms.append(IpsecAlgoNameCurrent);
 
881
                                }
 
882
 
461
883
                        }
462
884
                }
463
885
                cryptoprocfile.close();
464
 
        } else {
465
 
        }
466
 
        return KernelCrypto;
 
886
                salgos.IpsecIkeEncryptionAlgorithms.sort();
 
887
                salgos.IpsecIkeHashAlgorithms.sort();
 
888
                salgos.IpsecIkeDhGroups.sort();
 
889
                salgos.IpsecEspEncryptionAlgorithms.sort();
 
890
                salgos.IpsecEspAuthenticationAlgorithms.sort();
 
891
                salgos.IpsecCompressionAlgorithms.sort();
 
892
        }
 
893
        else
 
894
        {
 
895
                GlobalConfig->appendLogEntry(i18n("%1 cant be opened!", QString("/proc/crypto")),GlobalConfig->error);
 
896
        }
 
897
        return salgos;
467
898
}
468
899
 
469
900
QString Utils::getNameAndPidOfProgramListen( int port )
474
905
        ListenPort = port;
475
906
        retrieveNameAndPidOfProgramListen = false;
476
907
 
477
 
        NameAndPidOfProgramListenProcess = new QProcess( this );
478
 
        NameAndPidOfProgramListenProcess->addArgument( config->pathToNetstat );
 
908
        NameAndPidOfProgramListenProcess = new Q3Process( this );
 
909
        NameAndPidOfProgramListenProcess->addArgument( GlobalConfig->pathToNetstat );
479
910
        NameAndPidOfProgramListenProcess->addArgument( "-ntupl" );
480
911
 
481
912
        connect( NameAndPidOfProgramListenProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutGetNameAndPidOfProgramListen() ) );
482
913
        connect( NameAndPidOfProgramListenProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrGetNameAndPidOfProgramListen() ) );
483
914
 
484
915
        if ( !NameAndPidOfProgramListenProcess->start( env ) ) {
485
 
                kdError() << "netstat fails!" << endl;
 
916
                kError() << "netstat fails!" << endl;
486
917
                return false;
487
918
        } else {
488
919
                while ( NameAndPidOfProgramListenProcess->isRunning() )
489
 
                        config->appPointer->processEvents();
490
 
 
491
 
 
492
 
                disconnect( NameAndPidOfProgramListenProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutRetriveOpenvpnCiphers() ) );
493
 
                disconnect( NameAndPidOfProgramListenProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrRetriveOpenvpnCiphers() ) );
 
920
                        GlobalConfig->appPointer->processEvents();
 
921
 
 
922
 
 
923
                disconnect( NameAndPidOfProgramListenProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutRetrieveOpenvpnCiphers() ) );
 
924
                disconnect( NameAndPidOfProgramListenProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrRetrieveOpenvpnCiphers() ) );
494
925
 
495
926
        }
496
927
        return NameAndPidOfProgramListen;
501
932
        if (cert.isEmpty())
502
933
                return "";
503
934
 
504
 
        GetEmailAddressOfCertProcess = new QProcess ( this );
505
 
        GetEmailAddressOfCertProcess->setCommunication( QProcess::Stdin | QProcess::Stdout | QProcess::Stderr | QProcess::DupStderr );
506
 
        GetEmailAddressOfCertProcess->addArgument( config->pathToOpenssl );
 
935
        GetEmailAddressOfCertProcess = new Q3Process ( this );
 
936
        GetEmailAddressOfCertProcess->setCommunication( Q3Process::Stdin | Q3Process::Stdout | Q3Process::Stderr | Q3Process::DupStderr );
 
937
        GetEmailAddressOfCertProcess->addArgument( GlobalConfig->pathToOpenssl );
507
938
        GetEmailAddressOfCertProcess->addArgument( "x509");
508
939
        GetEmailAddressOfCertProcess->addArgument( "-noout");
509
940
        GetEmailAddressOfCertProcess->addArgument( "-in");
513
944
        connect( GetEmailAddressOfCertProcess, SIGNAL( readyReadStdout() ), this, SLOT( readOutGetEmailAddressOfCert() ) );
514
945
 
515
946
        if ( !GetEmailAddressOfCertProcess->start( env ) ) {
516
 
                kdError() << "GetEmailAddressOfCertProcess" << endl;
 
947
                kError() << "GetEmailAddressOfCertProcess" << endl;
517
948
                return false;
518
949
        } else {
519
950
                while ( GetEmailAddressOfCertProcess->isRunning() )
520
 
                        config->appPointer->processEvents();
 
951
                        GlobalConfig->appPointer->processEvents();
521
952
                disconnect( GetEmailAddressOfCertProcess, SIGNAL( readyReadStdout() ), this, SLOT( readOutGetEmailAddressOfCert() ) );
522
953
        }
523
954
 
528
959
{
529
960
        SmartcardSlots.clear();
530
961
 
531
 
        ToolInfo *Pkcs11ToolInfo = getToolInfo( config, "pkcs11-tool" );
 
962
        ToolInfo *Pkcs11ToolInfo = getToolInfo(  "pkcs11-tool" );
532
963
        Pkcs11ToolInfo->collectToolInfo();
533
964
//      if (Pkcs11ToolInfo == 0)
534
965
//              return SmartcardSlots;
538
969
        if ( pathToPkcs11Tool.isEmpty() )
539
970
                return SmartcardSlots;
540
971
 
541
 
        GetSmartcardSlotsProcess = new QProcess( this );
542
 
        GetSmartcardSlotsProcess->setCommunication( QProcess::Stdin | QProcess::Stdout | QProcess::Stderr | QProcess::DupStderr );
 
972
        GetSmartcardSlotsProcess = new Q3Process( this );
 
973
        GetSmartcardSlotsProcess->setCommunication( Q3Process::Stdin | Q3Process::Stdout | Q3Process::Stderr | Q3Process::DupStderr );
543
974
        GetSmartcardSlotsProcess->addArgument( pathToPkcs11Tool);       
544
975
        if (!ProviderLib.isEmpty())
545
976
        {
551
982
        connect( GetSmartcardSlotsProcess, SIGNAL( readyReadStdout() ), this, SLOT( readOutGetSmartcardSlots() ) );
552
983
        
553
984
        if ( !GetSmartcardSlotsProcess->start( env ) ) {
554
 
                kdError() << "Unable to fetch smartcard slots via pkcs11-tool!" << endl;
555
 
                return false;
 
985
                kError() << "Unable to fetch smartcard slots via pkcs11-tool!" << endl;
 
986
                return SmartcardSlots;
556
987
        } else {
557
988
                while ( GetSmartcardSlotsProcess->isRunning() )
558
989
//                      usleep(500);
559
 
                        config->appPointer->processEvents();
 
990
                        GlobalConfig->appPointer->processEvents();
560
991
 
561
992
                disconnect( GetSmartcardSlotsProcess, SIGNAL( readyReadStdout() ), this, SLOT( readOutGetSmartcardSlots() ) );
562
993
 
574
1005
        else
575
1006
                this->IdType = "id";
576
1007
 
577
 
        ToolInfo *Pkcs11ToolInfo = getToolInfo( config, "pkcs11-tool" );
 
1008
        ToolInfo *Pkcs11ToolInfo = getToolInfo(  "pkcs11-tool" );
578
1009
        Pkcs11ToolInfo->collectToolInfo();
579
1010
//      if (Pkcs11ToolInfo == 0)
580
1011
//              return SmartcardSlots;
584
1015
        if ( pathToPkcs11Tool.isEmpty() )
585
1016
                return SmartcardSlots;
586
1017
 
587
 
        GetSmartcardCertsFromSlotProcess = new QProcess( this );
588
 
        GetSmartcardCertsFromSlotProcess->setCommunication( QProcess::Stdin | QProcess::Stdout | QProcess::Stderr | QProcess::DupStderr );
 
1018
        GetSmartcardCertsFromSlotProcess = new Q3Process( this );
 
1019
        GetSmartcardCertsFromSlotProcess->setCommunication( Q3Process::Stdin | Q3Process::Stdout | Q3Process::Stderr | Q3Process::DupStderr );
589
1020
        GetSmartcardCertsFromSlotProcess->addArgument( pathToPkcs11Tool);       
590
1021
        
591
1022
        if (!ProviderLib.isEmpty())
605
1036
        connect( GetSmartcardCertsFromSlotProcess, SIGNAL( readyReadStdout() ), this, SLOT( readOutGetSmartcardCertsFromSlot() ) );
606
1037
        
607
1038
        if ( !GetSmartcardCertsFromSlotProcess->start( env ) ) {
608
 
                kdError() << "Unable to fetch smartcard slots via pkcs11-tool!" << endl;
609
 
                return false;
 
1039
                kError() << "Unable to fetch smartcard slots via pkcs11-tool!" << endl;
 
1040
                return SmartcardSlots;
610
1041
        } else {
611
1042
 
612
1043
                while ( GetSmartcardCertsFromSlotProcess->isRunning() )
613
1044
//                      usleep(500);
614
 
                        config->appPointer->processEvents();
 
1045
                        GlobalConfig->appPointer->processEvents();
615
1046
 
616
1047
                disconnect( GetSmartcardCertsFromSlotProcess, SIGNAL( readyReadStdout() ), this, SLOT( readOutGetSmartcardCertsFromSlot() ) );
617
1048
 
626
1057
        if (type != "user" && type != "ca" && type != "enrollment")
627
1058
                type="user";
628
1059
 
629
 
        if (config->KvpncDebugLevel > 2)
630
 
                config->appendLogEntry("getCertsFromCiscoCertStore: "+i18n("type: %1").arg(type),config->debug );
 
1060
        if (GlobalConfig->KvpncDebugLevel > 2)
 
1061
                GlobalConfig->appendLogEntry("getCertsFromCiscoCertStore: "+i18n("type: %1", type),GlobalConfig->debug );
631
1062
 
632
1063
        CertsFromCiscoCertStore.clear();
633
1064
        CertsFromCiscoCertPos=0;
634
1065
        
635
 
        if ( config->pathToCiscoCertMgr.isEmpty() )
 
1066
        if ( GlobalConfig->pathToCiscoCertMgr.isEmpty() )
636
1067
                return CertsFromCiscoCertStore;
637
1068
 
638
 
        GetCertsFromCiscoCertStoreProcess = new QProcess( this );
639
 
        GetCertsFromCiscoCertStoreProcess->setCommunication( QProcess::Stdin | QProcess::Stdout | QProcess::Stderr | QProcess::DupStderr );
640
 
        GetCertsFromCiscoCertStoreProcess->addArgument( config->pathToCiscoCertMgr );
 
1069
        GetCertsFromCiscoCertStoreProcess = new Q3Process( this );
 
1070
        GetCertsFromCiscoCertStoreProcess->setCommunication( Q3Process::Stdin | Q3Process::Stdout | Q3Process::Stderr | Q3Process::DupStderr );
 
1071
        GetCertsFromCiscoCertStoreProcess->addArgument( GlobalConfig->pathToCiscoCertMgr );
641
1072
 
642
1073
        if (type == "user")
643
1074
                GetCertsFromCiscoCertStoreProcess->addArgument( "-U");
654
1085
        connect( GetCertsFromCiscoCertStoreProcess, SIGNAL( readyReadStdout() ), this, SLOT( readOutGetCertsFromCiscoCertStoreSlot() ) );
655
1086
        
656
1087
        if ( !GetCertsFromCiscoCertStoreProcess->start( env ) ) {
657
 
                kdError() << "Unable to fetch certificates via cisco_cert_mgr!" << endl;
658
 
                return false;
 
1088
                kError() << "Unable to fetch certificates via cisco_cert_mgr!" << endl;
 
1089
                return CertsFromCiscoCertStore;
659
1090
        } else {
660
1091
 
661
1092
                while ( GetCertsFromCiscoCertStoreProcess->isRunning() )
662
1093
//                      usleep(500);
663
 
                        config->appPointer->processEvents();
 
1094
                        GlobalConfig->appPointer->processEvents();
664
1095
 
665
1096
                disconnect( GetCertsFromCiscoCertStoreProcess, SIGNAL( readyReadStdout() ), this, SLOT( readOutGetCertsFromCiscoCertStoreSlot() ) );
666
1097
 
679
1110
 
680
1111
        //openssl rsa -noout -in client.key -passin pass:aaa
681
1112
        
682
 
        ToolInfo *OpensslToolInfo = getToolInfo( config, "openssl" );
 
1113
        ToolInfo *OpensslToolInfo = getToolInfo(  "openssl" );
683
1114
        OpensslToolInfo->collectToolInfo();
684
1115
 
685
1116
        QString pathToOpenssl = OpensslToolInfo->PathToExec;
687
1118
        if ( pathToOpenssl.isEmpty() )
688
1119
                return needsPassphrase;
689
1120
 
690
 
        NeedsPassphraseProcess = new QProcess( this );
691
 
        NeedsPassphraseProcess->setCommunication( QProcess::Stdin | QProcess::Stdout | QProcess::Stderr | QProcess::DupStderr );
 
1121
        NeedsPassphraseProcess = new Q3Process( this );
 
1122
        NeedsPassphraseProcess->setCommunication( Q3Process::Stdin | Q3Process::Stdout | Q3Process::Stderr | Q3Process::DupStderr );
692
1123
        NeedsPassphraseProcess->addArgument( pathToOpenssl);
693
1124
        NeedsPassphraseProcess->addArgument("rsa");
694
1125
        NeedsPassphraseProcess->addArgument("-noout");
701
1132
        connect( NeedsPassphraseProcess, SIGNAL( readyReadStdout() ), this, SLOT( readOutNeedsPassphrase() ) );
702
1133
        
703
1134
        if ( !NeedsPassphraseProcess->start( env ) ) {
704
 
                kdError() << "Unable to start openssl!" << endl;
 
1135
                kError() << "Unable to start openssl!" << endl;
705
1136
                return false;
706
1137
        } else {
707
1138
                while ( NeedsPassphraseProcess->isRunning() )
708
1139
//                      usleep(500);
709
 
                        config->appPointer->processEvents();
 
1140
                        GlobalConfig->appPointer->processEvents();
710
1141
 
711
1142
                disconnect( NeedsPassphraseProcess, SIGNAL( readyReadStdout() ), this, SLOT( readOutNeedsPassphrase() ) );
712
1143
 
715
1146
        return needsPassphrase;
716
1147
}
717
1148
 
 
1149
QString Utils::getHostname()
 
1150
{
 
1151
        Hostname="linux.local";
 
1152
 
 
1153
        GetHostnameProcess = new Q3Process( this );
 
1154
        GetHostnameProcess->addArgument( "hostname" );
 
1155
 
 
1156
        connect( GetHostnameProcess, SIGNAL( readyReadStdout() ), this, SLOT( readStdOutGetHostname() ) );
 
1157
        connect( GetHostnameProcess, SIGNAL( readyReadStderr() ), this, SLOT( readStdErrGetHostname() ) );
 
1158
        if ( !GetHostnameProcess->start( env ) ) {
 
1159
                kdError() << "Unable to start getHostname process!" << endl;
 
1160
                return false;
 
1161
        }
 
1162
        else {
 
1163
                while ( GetHostnameProcess->isRunning() )
 
1164
                {
 
1165
                        usleep(200);
 
1166
                }
 
1167
                return Hostname;
 
1168
        }
 
1169
        
 
1170
        
 
1171
}
 
1172
 
718
1173
/* === Slots === */
719
1174
void Utils::readStdOutCreateTunDev() {
720
1175
        QString msg = QString( createProcess->readStderr() );
721
 
        kdDebug() << "readStdOutCreateTunDev(): " << msg << endl;
 
1176
        kDebug() << "readStdOutCreateTunDev(): " << msg << endl;
722
1177
}
723
1178
 
724
1179
void Utils::readStdErrCreateTunDev()
725
1180
{
726
1181
        QString msg = QString( createProcess->readStderr() );
727
 
        kdError() << "readStdErrCreateTunDev" << msg << endl;
 
1182
        kError() << "readStdErrCreateTunDev" << msg << endl;
728
1183
 
729
1184
}
730
1185
 
731
1186
void Utils::readStdOutLoadKernelModule()
732
1187
{
733
1188
        QString msg = QString( ModprobeProcess->readStdout() );
734
 
        kdDebug() << "readStdErrreadStdOutLoadKernelModule" << msg << endl;
 
1189
        kDebug() << "readStdErrreadStdOutLoadKernelModule" << msg << endl;
735
1190
}
736
1191
 
737
1192
void Utils::readStdErrLoadKernelModule()
738
1193
{
739
1194
        QString msg = QString( ModprobeProcess->readStderr() );
740
 
        //      kdDebug() << "readStdErrreadStderrLoadKernelModule" << msg << endl;
 
1195
        //      kDebug() << "readStdErrreadStderrLoadKernelModule" << msg << endl;
741
1196
 
742
1197
        /* FATAL: Module <Name> not found. */
743
 
        if ( msg.find( "not found", 0, FALSE ) > -1 ) {
744
 
                modprobeSuccess = false;
745
 
        }
746
 
 
747
 
        if ( msg.find( "could not find module", 0 , FALSE ) > -1 ) {
748
 
                modprobeSuccess = false;
749
 
        }
750
 
 
751
 
        if ( msg.find( "not permitted", 0 , FALSE ) > -1 ) {
 
1198
        if ( msg.indexOf( "not found", 0, Qt::CaseInsensitive ) > -1 ) {
 
1199
                modprobeSuccess = false;
 
1200
        }
 
1201
 
 
1202
        if ( msg.indexOf( "could not find module", 0 , Qt::CaseInsensitive ) > -1 ) {
 
1203
                modprobeSuccess = false;
 
1204
        }
 
1205
 
 
1206
        if ( msg.indexOf( "not permitted", 0 , Qt::CaseInsensitive ) > -1 ) {
752
1207
                modprobeSuccess = false;
753
1208
        }
754
1209
}
761
1216
{
762
1217
}
763
1218
 
764
 
void Utils::readStdOutRetriveOpenvpnCiphers()
 
1219
void Utils::readStdOutRetrieveOpenvpnCiphers()
765
1220
{
766
1221
        while ( OpenvpnCiphersProcess->canReadLineStdout() ) {
767
1222
                QString msg = QString( OpenvpnCiphersProcess->readLineStdout() );
768
1223
                if ( msg.contains( "default key" ) ) {
769
 
                        //std::cout << msg.ascii() << std::endl;
 
1224
                        //std::cout << qPrintable(msg) << std::endl;
770
1225
                        OpenvpnCiphers.append( msg.section( ' ', 0, 0 ) );
771
1226
                }
772
1227
        }
773
1228
}
774
1229
 
775
 
void Utils::readStdErrRetriveOpenvpnCiphers()
 
1230
void Utils::readStdErrRetrieveOpenvpnCiphers()
776
1231
{
777
1232
        while ( OpenvpnCiphersProcess->canReadLineStderr() ) {
778
1233
                QString msg = QString( OpenvpnCiphersProcess->readLineStderr() );
780
1235
        }
781
1236
}
782
1237
 
783
 
void Utils::readStdOutRetriveOpenvpnDigests()
 
1238
void Utils::readStdOutRetrieveIpsecAlgos()
 
1239
{
 
1240
        while ( IpsecAlgosProcess->canReadLineStdout() ) {
 
1241
                QString msg = QString( IpsecAlgosProcess->readLineStdout() );
 
1242
                bool newIpsecAlgoFound=false;
 
1243
//              std::cout << "[ipsec algos raw] "<< msg.ascii() << std::endl;
 
1244
                if (msg.find ( "000 algorithm", 0, -1 ) > -1)
 
1245
                {
 
1246
                        std::cout << "[ipsec algos line] "<< msg.ascii() << std::endl;
 
1247
                        if (msg.find ( "000 algorithm ESP", 0, -1 ) > -1)
 
1248
                        {
 
1249
 
 
1250
                                        QString Algo = msg.stripWhiteSpace().section(":",1,1).section(",",1,1).section("=",1,1);
 
1251
                                        QString MinKeySize = msg.stripWhiteSpace().section(":",1,1).section(",",3,3).section("=",1,1);
 
1252
                                        QString MaxKeySize = msg.stripWhiteSpace().section(":",1,1).section(",",4,4).section("=",1,1);
 
1253
                                        std::cout << "IKE encryption algo found: \"" << qPrintable(Algo) << "\", Min: " << qPrintable(MinKeySize) << ", Max: " << qPrintable(MaxKeySize) << std::endl;
 
1254
//                                      QStringList AlgoOptList = QStringList::split("-",AlgoOpt);
 
1255
//                                      for (QStringList::Iterator it = AlgoOptList.begin(); it != AlgoOptList.end(); ++it)
 
1256
//                                      {
 
1257
//                                              std::cout << "IKE encryption algo subtypes found: \"" << qPrintable(Algo) << "-" << *it << "\"" << std::endl;
 
1258
//                                      }
 
1259
                                }
 
1260
 
 
1261
                }
 
1262
        }
 
1263
}
 
1264
 
 
1265
void Utils::readStdErrRetrieveIpsecAlgos()
 
1266
{
 
1267
        while ( IpsecAlgosProcess->canReadLineStderr() ) {
 
1268
                QString msg = QString( IpsecAlgosProcess->readLineStderr() );
 
1269
                std::cout << "[ipsec algos raw err] "<< msg.ascii() << std::endl;
 
1270
        }
 
1271
}
 
1272
 
 
1273
void Utils::readPppdtestProcessOutput()
 
1274
{
 
1275
        QString msg = "";
 
1276
        msg += QString ( TestPppdProcess->readStdout() );
 
1277
//      msg += QString ( TestPppdProcess->readStderr() );
 
1278
 
 
1279
//      if ( msg == "" )
 
1280
//              return ;
 
1281
 
 
1282
 
 
1283
 
 
1284
        /* mppe test */
 
1285
        if (testPppdRequireMppe)
 
1286
        {
 
1287
                if (GlobalConfig->KvpncDebugLevel > 2)
 
1288
                        GlobalConfig->appendLogEntry("Testing require-mppe",GlobalConfig->debug);
 
1289
 
 
1290
                if (GlobalConfig->KvpncDebugLevel > 4)
 
1291
                        GlobalConfig->appendLogEntry("[test pppd raw]: "+msg,GlobalConfig->debug);
 
1292
 
 
1293
                if ( msg.contains ( "unrecognized option 'require-mppe'" ) )
 
1294
                {
 
1295
                        pppdcap.oldPppdStyle = true;
 
1296
                        pppdcap.pppdHasMppeSupport = false;
 
1297
                        pppdcap.pppdHasRequireMppeSupport=false;
 
1298
 
 
1299
                        if ( GlobalConfig->KvpncDebugLevel > 4 )
 
1300
                                GlobalConfig->appendLogEntry ( i18n ( "%1 has  no MPPE support using \"require mppe\"." , QString( GlobalConfig->pathToPppd )), GlobalConfig->debug );
 
1301
                }
 
1302
                else
 
1303
                {
 
1304
                        if ( msg.contains ( "The remote system is required to authenticate itself" ) )
 
1305
                        {
 
1306
                                // old style found
 
1307
                                pppdcap.oldPppdStyle = false;
 
1308
                                pppdcap.pppdHasMppeSupport = true;
 
1309
                                pppdcap.pppdHasRequireMppeSupport=true;
 
1310
 
 
1311
                                if ( GlobalConfig->KvpncDebugLevel > 0 )
 
1312
                                        GlobalConfig->appendLogEntry ( i18n ( "%1 has MPPE support and uses require mppe." , QString( GlobalConfig->pathToPppd )), GlobalConfig->debug );
 
1313
                        }
 
1314
                }
 
1315
        }
 
1316
 
 
1317
        if ( testPppdMppeRequired)
 
1318
        {
 
1319
                if (GlobalConfig->KvpncDebugLevel > 2)
 
1320
                        GlobalConfig->appendLogEntry("Testing mppe-required",GlobalConfig->debug);
 
1321
 
 
1322
                if (GlobalConfig->KvpncDebugLevel > 4)
 
1323
                        GlobalConfig->appendLogEntry("[test pppd raw]: "+msg,GlobalConfig->debug);
 
1324
 
 
1325
                // try old style
 
1326
                if ( msg.contains ( "unrecognized option 'mppe'" ) )
 
1327
                {
 
1328
                        // no mppe support :(
 
1329
                        pppdcap.oldPppdStyle = false;
 
1330
                        pppdcap.pppdHasMppeSupport = false;
 
1331
                        pppdcap.pppdHasMppeRequiredSupport=false;
 
1332
                        if ( GlobalConfig->KvpncDebugLevel > 4 )
 
1333
                                GlobalConfig->appendLogEntry ( i18n ( "%1 has  no MPPE support using \"mppe-required\"." , QString( GlobalConfig->pathToPppd )), GlobalConfig->debug );
 
1334
                }
 
1335
                else
 
1336
                {
 
1337
                        if ( msg.contains ( "The remote system is required to authenticate itself" ) )
 
1338
                        {
 
1339
                                // old style found
 
1340
                                pppdcap.oldPppdStyle = true;
 
1341
                                pppdcap.pppdHasMppeSupport = true;
 
1342
                                pppdcap.pppdHasMppeRequiredSupport=true;
 
1343
 
 
1344
                                if ( GlobalConfig->KvpncDebugLevel > 0 )
 
1345
                                        GlobalConfig->appendLogEntry ( i18n ( "%1 has MPPE support and uses mppe-required." , QString( GlobalConfig->pathToPppd )), GlobalConfig->debug );
 
1346
                        }
 
1347
                }
 
1348
        }
 
1349
 
 
1350
 
 
1351
        /* default route test */
 
1352
        if ( testPppdReplacedefaultroute )
 
1353
        {
 
1354
 
 
1355
                if (GlobalConfig->KvpncDebugLevel > 1)
 
1356
                        GlobalConfig->appendLogEntry("[test pppd raw]: "+msg,GlobalConfig->debug);
 
1357
 
 
1358
                if ( msg.contains ( "unrecognized option 'replacedefaultroute'" )   )
 
1359
                {
 
1360
                        pppdcap.pppdHasReplacedefaultrouteSupport = false;
 
1361
 
 
1362
                if (GlobalConfig->KvpncDebugLevel > 1)
 
1363
                        GlobalConfig->appendLogEntry(i18n("Testing %1: %2", QString("replacedefaultroute"), QString("failed")),GlobalConfig->debug);
 
1364
                }
 
1365
                else
 
1366
                {
 
1367
                        pppdcap.pppdHasReplacedefaultrouteSupport = true;
 
1368
                if (GlobalConfig->KvpncDebugLevel > 1)
 
1369
                        GlobalConfig->appendLogEntry(i18n("Testing %1: %2", QString("replacedefaultroute"),i18n("succeded")),GlobalConfig->debug);
 
1370
                }
 
1371
        }
 
1372
 
 
1373
 
 
1374
}
 
1375
 
 
1376
void Utils::readStdOutRetrieveOpenvpnDigests()
784
1377
{
785
1378
        while ( OpenvpnDigestProcess->canReadLineStdout() ) {
786
1379
                QString msg = QString( OpenvpnDigestProcess->readLineStdout() );
787
1380
                OpenvpnDigestCount+=1;
788
1381
                if ( OpenvpnDigestCount > 5 ) {
789
 
//                      std::cout << msg.simplifyWhiteSpace().ascii() << std::endl;
 
1382
//                      std::cout << qPrintable(msg.simplified()) << std::endl;
790
1383
                        OpenvpnDigestString += msg+"#";
791
1384
                }
792
1385
        }
793
1386
}
794
1387
 
795
 
void Utils::readStdErrRetriveOpenvpnDigests()
 
1388
void Utils::readStdErrRetrieveOpenvpnDigests()
796
1389
{
797
1390
        while ( OpenvpnDigestProcess->canReadLineStderr() ) {
798
1391
                QString msg = QString( OpenvpnDigestProcess->readLineStderr() );
804
1397
{
805
1398
        while ( NameAndPidOfProgramListenProcess->canReadLineStdout() ) {
806
1399
                QString msg = QString( NameAndPidOfProgramListenProcess->readLineStdout() );
807
 
                if ( msg.contains( "/" ) && msg.contains( QString().setNum( ListenPort ) ) && msg.simplifyWhiteSpace().section( ' ', 3, 3 ).section(':',1,1) == QString().setNum( ListenPort )  ) {
808
 
                        std::cout << msg.ascii() << std::endl;
809
 
                        NameAndPidOfProgramListen = ( msg.simplifyWhiteSpace().section( ' ', 5, 5 ) );
 
1400
                if ( msg.contains( "/" ) && msg.contains( QString().setNum( ListenPort ) ) && msg.simplified().section( ' ', 3, 3 ).section(':',1,1) == QString().setNum( ListenPort )  ) {
 
1401
                        std::cout << qPrintable(msg) << std::endl;
 
1402
                        NameAndPidOfProgramListen = ( msg.simplified().section( ' ', 5, 5 ) );
810
1403
                        if (NameAndPidOfProgramListen.contains( "LISTEN"))
811
 
                                NameAndPidOfProgramListen = ( msg.simplifyWhiteSpace().section( ' ', 6, 6 ) );
 
1404
                                NameAndPidOfProgramListen = ( msg.simplified().section( ' ', 6, 6 ) );
812
1405
                        break;
813
1406
                }
814
1407
        }
827
1420
        while ( GetEmailAddressOfCertProcess->canReadLineStdout() ) {
828
1421
                QString msg = QString( GetEmailAddressOfCertProcess->readLineStdout() );
829
1422
                if ( msg.contains( "emailAddress" ) ) {
830
 
                        std::cout << "msg: " << msg.ascii() << std::endl;
 
1423
                        std::cout << "msg: " << qPrintable(msg) << std::endl;
831
1424
                        QStringList fields = QStringList::split( '/', msg);
832
1425
                        for ( QStringList::iterator field = fields.begin();  field != fields.end();++field )
833
1426
                        {
834
1427
                                if (QString (*field).contains("emailAddress"))
835
1428
                                {
836
 
                                        if (config->KvpncDebugLevel > 2)
837
 
                                                std::cout << "field: " << QString(*field).ascii() << std::endl;
 
1429
                                        if (GlobalConfig->KvpncDebugLevel > 2)
 
1430
                                                std::cout << "field: " << qPrintable(QString(*field)) << std::endl;
838
1431
                                        // subject= /C=de/L=WR/O=crissi/CN=Christoph Thielecke/emailAddress=crissi99@gxm.de
839
1432
                                        // crissi99@gxm.de
840
1433
                                        EmailAddressOfCert = QString(*field).section('=',1,1);
852
1445
                QString msg = QString( GetSmartcardSlotsProcess->readLineStdout() );
853
1446
                
854
1447
                if ( msg.contains( "Slot" ) && !msg.contains("empty") )
855
 
                if ( msg.find( "Slot", 0, FALSE ) > -1 && msg.find( "empty", 0, FALSE ) == -1  )
 
1448
                if ( !msg.contains( "Slot", Qt::CaseInsensitive ) > -1 && msg.indexOf( "empty",  Qt::CaseInsensitive ) )
856
1449
                {
857
 
                        //std::cout << msg.ascii() << std::endl;
858
 
//                      KMessageBox::information( 0, i18n( "msg: %1" ).arg( msg.stripWhiteSpace() ), QString("foo") );
 
1450
                        //std::cout << qPrintable(msg) << std::endl;
 
1451
//                      KMessageBox::information( 0, i18n( "msg: %1" , QString(msg.trimmed() )), QString("foo") );
859
1452
                        // we put in this format: <id>:<name>
860
 
                        QString id = msg.stripWhiteSpace().section( ' ', 1, 1 );
861
 
                        QString name = msg.stripWhiteSpace().remove(QString("Slot "+id)).stripWhiteSpace();
 
1453
                        QString id = msg.trimmed().section( ' ', 1, 1 );
 
1454
                        QString name = msg.trimmed().remove(QString("Slot "+id)).trimmed();
862
1455
                        QString slot = id+" : "+name;
863
1456
                        SmartcardSlots.append( slot );
864
1457
                }
873
1466
//                      KMessageBox::sorry( 0, QString("msg: "+msg), QString("foo1"),0 );
874
1467
                        Pkcs11CertFound=true;
875
1468
                }
876
 
//              KMessageBox::information( 0, i18n( "msg: %1" ).arg( msg ), QString("foo") );
 
1469
//              KMessageBox::information( 0, i18n( "msg: %1" , QString( msg )), QString("foo") );
877
1470
                if (IdType == "id")
878
1471
                {
879
1472
                        if ( msg.contains( "ID:" ) && Pkcs11CertFound==true ) {
880
 
                                //std::cout << msg.ascii() << std::endl;
 
1473
                                //std::cout << qPrintable(msg) << std::endl;
881
1474
                                QString msg2 = msg.section( ':', 1, 1 );
882
 
                                msg2 = msg2.stripWhiteSpace();
 
1475
                                msg2 = msg2.trimmed();
883
1476
//                              KMessageBox::sorry( 0, QString("id: "+msg), QString("foo"),0 );
884
1477
                                SmartcardCertsFromSlot.append( msg2 );
885
1478
                                Pkcs11CertFound=false;
888
1481
                else if (IdType == "label")
889
1482
                {
890
1483
                        if ( msg.contains( "label:" ) && Pkcs11CertFound==true ) {
891
 
                                //std::cout << msg.ascii() << std::endl;
 
1484
                                //std::cout << qPrintable(msg) << std::endl;
892
1485
                                QString msg2 = msg.section( ':', 1, 1 );
893
 
                                msg2 = msg2.stripWhiteSpace();
 
1486
                                msg2 = msg2.trimmed();
894
1487
//                              KMessageBox::sorry( 0, QString("label: "+msg2), QString("foo"),0 );
895
1488
                                SmartcardCertsFromSlot.append( msg2 );
896
1489
                                Pkcs11CertFound=false;
899
1492
                else if (IdType == "subject")
900
1493
                {
901
1494
                        if ( msg.contains( "Subject:" ) && Pkcs11CertFound==true ) {
902
 
                                //std::cout << msg.ascii() << std::endl;
 
1495
                                //std::cout << qPrintable(msg) << std::endl;
903
1496
                                QString msg2 = msg.section( ':', 1, 1 );
904
 
                                msg2 = msg2.stripWhiteSpace();
 
1497
                                msg2 = msg2.trimmed();
905
1498
//                              KMessageBox::sorry( 0, QString("subject: "+msg), QString("foo"),0 );
906
1499
                                SmartcardCertsFromSlot.append( msg2 );
907
1500
                                Pkcs11CertFound=false;
929
1522
// 
930
1523
//       0               crissi 
931
1524
 
932
 
                if (config->KvpncDebugLevel > 2)
933
 
                        std::cout << "readOutGetCertsFromCiscoCertStoreSlot: " << msg << std::endl;
 
1525
                if (GlobalConfig->KvpncDebugLevel > 2)
 
1526
                        std::cout << "readOutGetCertsFromCiscoCertStoreSlot: " << qPrintable(msg) << std::endl;
934
1527
 
935
 
                if (msg.find("Cert #",0,FALSE) > -1)
 
1528
                if (msg.indexOf("Cert #",0,Qt::CaseInsensitive) > -1)
936
1529
                        CertsFromCiscoCertPos=1;
937
1530
                if (CertsFromCiscoCertPos==1 || CertsFromCiscoCertPos ==2 | CertsFromCiscoCertPos ==3)
938
1531
                {
950
1543
                                        if (!msg.at(idx).isSpace())
951
1544
                                                break;
952
1545
 
953
 
                                if (config->KvpncDebugLevel > 2)
 
1546
                                if (GlobalConfig->KvpncDebugLevel > 2)
954
1547
                                        std::cout << "readOutGetCertsFromCiscoCertStoreSlot: idx " << idx << std::endl;
955
1548
 
956
1549
                                for (idx2=idx+1;idx2<(int)msg.length();idx2++)
957
1550
                                        if (!msg.at(idx2).isSpace())
958
1551
                                                break;
959
 
                                if (config->KvpncDebugLevel > 2)
 
1552
                                if (GlobalConfig->KvpncDebugLevel > 2)
960
1553
                                        std::cout << "readOutGetCertsFromCiscoCertStoreSlot: idx2 " << idx2 << std::endl;
961
1554
                                QString common_name = msg.right(msg.length()-idx2);
962
1555
                                if (common_name.length() > 0)
963
1556
                                {
964
 
                                        if (config->KvpncDebugLevel > 2)
965
 
                                                std::cout << "readOutGetCertsFromCiscoCertStoreSlot => cert " << common_name << std::endl;
 
1557
                                        if (GlobalConfig->KvpncDebugLevel > 2)
 
1558
                                                std::cout << "readOutGetCertsFromCiscoCertStoreSlot => cert " << qPrintable(common_name) << std::endl;
966
1559
                                        CertsFromCiscoCertStore.append( common_name );
967
1560
                                }
968
1561
                        }
982
1575
 
983
1576
}
984
1577
 
 
1578
void Utils::readStdOutGetHostname()
 
1579
{
 
1580
        while ( GetHostnameProcess->canReadLineStdout() ) {
 
1581
                QString msg = QString( GetHostnameProcess->readLineStdout() ).simplifyWhiteSpace().section(' ',0,0);
 
1582
//              KMessageBox::sorry( 0, QString("msg: "+msg), QString("foo1"),0 );
 
1583
                if (!msg.isEmpty())
 
1584
                        Hostname=msg;
 
1585
        }
 
1586
}
985
1587
 
 
1588
void Utils::readStdErrGetHostname()
 
1589
{
 
1590
        while ( GetHostnameProcess->canReadLineStderr() ) {
 
1591
                QString msg = QString( GetHostnameProcess->readLineStderr() );
 
1592
                KMessageBox::error( 0, QString(msg), QString("getHostname()"),0 );
 
1593
        }
 
1594
}
986
1595
 
987
1596
#include "utils.moc"
 
1597