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
|
/***************************************************************************
* Copyright (C) 2004 by Christoph Thielecke *
* [email protected] *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "generateopenvpnkeydialog.h"
#include <tdemessagebox.h>
#include <tdetempfile.h>
#include <tdelocale.h>
#include <kdialogbase.h>
#include <kurlrequester.h>
#include <tqfile.h>
#include <tqurl.h>
#include <kurl.h>
#include <tqstring.h>
#include <iostream>
#include <unistd.h>
//
GenerateOpenvpnKeyDialog::GenerateOpenvpnKeyDialog(KVpncConfig *GlobalConfig,TQWidget *parent, const TQString& caption)
: KDialogBase( parent, "Import_Cisco_PCF_profile", true, caption,
KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, true )
{
this->GlobalConfig=GlobalConfig;
filename = "";
genOk = false;
main = new GenerateOpenvpnKeyDialogBase(this);
setMainWidget(main);
//main->setMinimumSize(main->sizeHint());
main->FilenameUrlrequester->setFilter( "*.key" );
}
GenerateOpenvpnKeyDialog::~GenerateOpenvpnKeyDialog()
{
// delete generateOpenvpnKeyProcess;
delete main;
}
void GenerateOpenvpnKeyDialog::accept()
{
//filename="/etc/CiscoSystemsVPNClient/Profiles/hs_harz.pcf";
filename = main->FilenameUrlrequester->url();
if ( !filename.isEmpty() )
{
canAccept();
}
else
{
GlobalConfig->appendLogEntry( i18n("GenerateOpenvpnKeyDialog: empty file name"), GlobalConfig->error);
KMessageBox::sorry( 0, i18n( "File name can not be empty!" ), i18n( "Empty File Name" ) );
}
}
void GenerateOpenvpnKeyDialog::canAccept()
{
/*
TQFile f( filename );
if ( !f.exists() )
{
KMessageBox::information( 0, i18n( "File not found." ), i18n( "No fFile" ) );
// emit progress( 100 );
return ;
}*/
generateOpenvpnKeyProcess = new TQProcess(this);
generateOpenvpnKeyProcess->addArgument(GlobalConfig->pathToOpenvpn);
generateOpenvpnKeyProcess->addArgument("--genkey");
generateOpenvpnKeyProcess->addArgument("--secret");
generateOpenvpnKeyProcess->addArgument(filename);
connect( generateOpenvpnKeyProcess, TQT_SIGNAL( readyReadStderr() ), this, TQT_SLOT( readStdErr() ) );
connect( generateOpenvpnKeyProcess, TQT_SIGNAL( readyReadStdout() ), this, TQT_SLOT( readStdErr() ) );
if ( !generateOpenvpnKeyProcess->start(env) )
{
KMessageBox::sorry( this, i18n( "Generating of %1 key failed!" ).arg( "openvpn" ) );
GlobalConfig->appendLogEntry(i18n( "\"%1\" start failed!" ).arg( "openvpn" ),GlobalConfig->error);
}
else
{
GlobalConfig->appendLogEntry( i18n("Generating of %1 key was successful.").arg("openvpn"), GlobalConfig->info);
genOk = true;
}
while (generateOpenvpnKeyProcess->isRunning())
{
sleep(1);
}
disconnect( generateOpenvpnKeyProcess, TQT_SIGNAL( readyReadStderr() ), this, TQT_SLOT( readStdErr() ) );
disconnect( generateOpenvpnKeyProcess, TQT_SIGNAL( readyReadStdout() ), this, TQT_SLOT( readStdErr() ) );
delete generateOpenvpnKeyProcess;
generateOpenvpnKeyProcess = 0L;
if (genOk)
KMessageBox::information( this, i18n( "Generating the key in \"%1\" was successful." ).arg( filename ) );
else
KMessageBox::sorry( this, i18n( "Generating the key in \"%1\" failed!" ).arg( filename ) );
//std::cout << "accept" << std::endl;
TQDialog::accept();
}
void GenerateOpenvpnKeyDialog::readStdErr()
{
// while ( generateOpenvpnKeyProcess->canReadLineStderr() ) {
// ProcessMsg_connect = generateOpenvpnKeyProcess->readLineStderr();
TQString ProcessMsg_connect = TQString( generateOpenvpnKeyProcess->readStderr() );
if (ProcessMsg_connect.isEmpty())
ProcessMsg_connect = TQString( generateOpenvpnKeyProcess->readStdout() );
if ( ProcessMsg_connect.find( "Permission denied", 0 , FALSE ) > -1 )
{
if (GlobalConfig->KvpncDebugLevel > 0 )
GlobalConfig->appendLogEntry( "[openvpn genkey err] " + ProcessMsg_connect, GlobalConfig->error );
genOk = false;
//}
}
}
|