From 60bf9a139fd8cc0948bcf11d4fbcfab5cd9e0641 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Mon, 10 Sep 2012 17:08:29 -0500 Subject: Reactivate openvpn plugin --- tdenetworkmanager/src/tdenetman-pluginmanager.cpp | 45 +- tdenetworkmanager/src/tdenetman-vpnservice.cpp | 8 +- tdenetworkmanager/vpn-plugins/CMakeLists.txt | 2 +- tdenetworkmanager/vpn-plugins/openvpn/AUTHORS | 1 + .../vpn-plugins/openvpn/CMakeLists.txt | 14 + .../openvpn/knetworkmanager_openvpn.desktop | 25 - .../vpn-plugins/openvpn/src/CMakeLists.txt | 43 ++ .../openvpn/src/knetworkmanager-openvpn.cpp | 566 ------------------- .../openvpn/src/knetworkmanager-openvpn.h | 110 ---- .../vpn-plugins/openvpn/src/tdenetman-openvpn.cpp | 603 +++++++++++++++++++++ .../vpn-plugins/openvpn/src/tdenetman-openvpn.h | 114 ++++ .../vpn-plugins/openvpn/tdenetman_openvpn.desktop | 25 + 12 files changed, 824 insertions(+), 732 deletions(-) create mode 100644 tdenetworkmanager/vpn-plugins/openvpn/CMakeLists.txt delete mode 100644 tdenetworkmanager/vpn-plugins/openvpn/knetworkmanager_openvpn.desktop create mode 100644 tdenetworkmanager/vpn-plugins/openvpn/src/CMakeLists.txt delete mode 100644 tdenetworkmanager/vpn-plugins/openvpn/src/knetworkmanager-openvpn.cpp delete mode 100644 tdenetworkmanager/vpn-plugins/openvpn/src/knetworkmanager-openvpn.h create mode 100644 tdenetworkmanager/vpn-plugins/openvpn/src/tdenetman-openvpn.cpp create mode 100644 tdenetworkmanager/vpn-plugins/openvpn/src/tdenetman-openvpn.h create mode 100644 tdenetworkmanager/vpn-plugins/openvpn/tdenetman_openvpn.desktop diff --git a/tdenetworkmanager/src/tdenetman-pluginmanager.cpp b/tdenetworkmanager/src/tdenetman-pluginmanager.cpp index a5dfce9..0dad6ad 100644 --- a/tdenetworkmanager/src/tdenetman-pluginmanager.cpp +++ b/tdenetworkmanager/src/tdenetman-pluginmanager.cpp @@ -33,8 +33,9 @@ PluginManager* PluginManager::_instance; PluginManager* PluginManager::getInstance() { - if (_instance) + if (_instance) { return _instance; + } return new PluginManager(TQT_TQOBJECT(TDENetworkManager::getInstance()), "pluginmanager"); } @@ -45,22 +46,21 @@ PluginManager::PluginManager(TQObject* parent, const char* name) this->_plugins = KPluginInfo::fromServices( KTrader::self()->query( TQString::fromLatin1( "TDENetworkManager/Plugin" ))); // a bit debug output - for(TQValueList::ConstIterator it = _plugins.begin(); it != _plugins.end(); ++it) + for(TQValueList::ConstIterator it = _plugins.begin(); it != _plugins.end(); ++it) { kdDebug() << k_funcinfo << TQString("Found Plugin '%1'").arg((*it)->pluginName()) << endl; + } } PluginManager::~PluginManager() { // delete all loaded plugins - while(!_loadedPlugins.empty()) - { + while(!_loadedPlugins.empty()) { PluginMap::Iterator it = _loadedPlugins.begin(); _loadedPlugins.remove(it); } // delete all available plugininfos - while(!_plugins.empty()) - { + while(!_plugins.empty()) { TQValueList::Iterator it = _plugins.begin(); delete *it; _plugins.remove(it); @@ -71,11 +71,12 @@ TQStringList PluginManager::getPluginList(const TQString& serviceType, const TQS { TQStringList ret; // find a suitable plugin - for(TQValueList::ConstIterator it = _plugins.begin(); it != _plugins.end(); ++it) - { - if ((*it)->service()->serviceTypes().contains(serviceType) > 0) - if ((*it)->property(property).toString().contains(value)) + for(TQValueList::ConstIterator it = _plugins.begin(); it != _plugins.end(); ++it) { + if ((*it)->service()->serviceTypes().contains(serviceType) > 0) { + if ((*it)->property(property).toString().contains(value)) { ret.append( (*it)->pluginName() ); + } + } } return ret; } @@ -83,12 +84,10 @@ TQStringList PluginManager::getPluginList(const TQString& serviceType, const TQS Plugin* PluginManager::getPlugin(const TQString& pluginID) { KPluginInfo* info = infoForPluginID(pluginID); - if (_loadedPlugins.contains(info)) - { + if (_loadedPlugins.contains(info)) { return _loadedPlugins[info]; } - else - { + else { return loadPlugin(pluginID); } return NULL; @@ -101,8 +100,7 @@ const KPluginInfo* PluginManager::getPluginInfo(const TQString& pluginID) const KPluginInfo* PluginManager::getPluginInfo(const Plugin* plugin) { - for(PluginMap::ConstIterator it = _loadedPlugins.begin(); it != _loadedPlugins.end(); ++it) - { + for(PluginMap::ConstIterator it = _loadedPlugins.begin(); it != _loadedPlugins.end(); ++it) { if (it.data() == plugin) return it.key(); } @@ -112,8 +110,7 @@ const KPluginInfo* PluginManager::getPluginInfo(const Plugin* plugin) void PluginManager::loadAllPlugins() { // iterate over all plugins - for(TQValueList::ConstIterator it = _plugins.begin(); it != _plugins.end(); ++it) - { + for(TQValueList::ConstIterator it = _plugins.begin(); it != _plugins.end(); ++it) { // load Plugin loadPlugin((*it)->pluginName()); } @@ -129,13 +126,11 @@ Plugin* PluginManager::loadPlugin(const TQString& pluginID) TQString::fromLatin1( "[X-TDE-PluginInfo-Name]=='%1'" ).arg( pluginID ), this, 0, TQStringList(), &error ); // plugin loaded? - if (plugin) - { + if (plugin) { kdDebug() << k_funcinfo << TQString(i18n("successfully loaded plugin '%1'")).arg(info->pluginName()) << endl; _loadedPlugins.insert(info, plugin); } - else - { + else { // error switch( error ) { @@ -172,10 +167,10 @@ Plugin* PluginManager::loadPlugin(const TQString& pluginID) KPluginInfo * PluginManager::infoForPluginID( const TQString& pluginID ) const { TQValueList::ConstIterator it; - for ( it = this->_plugins.begin(); it != this->_plugins.end(); ++it ) - { - if ( ( *it )->pluginName() == pluginID ) + for ( it = this->_plugins.begin(); it != this->_plugins.end(); ++it ) { + if ( ( *it )->pluginName() == pluginID ) { return *it; + } } return 0L; diff --git a/tdenetworkmanager/src/tdenetman-vpnservice.cpp b/tdenetworkmanager/src/tdenetman-vpnservice.cpp index b2643cf..d97cf82 100644 --- a/tdenetworkmanager/src/tdenetman-vpnservice.cpp +++ b/tdenetworkmanager/src/tdenetman-vpnservice.cpp @@ -54,12 +54,10 @@ VPNService::VPNService(const TQString& serviceName, const TQString& service, TQO // query if a plugin for this vpn service is available PluginManager* plugMan = PluginManager::getInstance(); - if (plugMan) - { + if (plugMan) { TQStringList list = plugMan->getPluginList("TDENetworkManager/VPNPlugin", "X-NetworkManager-Services", serviceName); - if (list.size() > 0) - { - // get the first VPN Plugin handling our VPNService + if (list.size() > 0) { + // get the first VPN Plugin handling our VPNService VPNPlugin* vpnPlugin = dynamic_cast( plugMan->getPlugin(list.first()) ); if (vpnPlugin) { diff --git a/tdenetworkmanager/vpn-plugins/CMakeLists.txt b/tdenetworkmanager/vpn-plugins/CMakeLists.txt index 6e10d60..2643aad 100644 --- a/tdenetworkmanager/vpn-plugins/CMakeLists.txt +++ b/tdenetworkmanager/vpn-plugins/CMakeLists.txt @@ -9,7 +9,7 @@ # ################################################# -# add_subdirectory( openvpn ) +add_subdirectory( openvpn ) add_subdirectory( pptp ) # add_subdirectory( strongswan ) add_subdirectory( vpnc ) diff --git a/tdenetworkmanager/vpn-plugins/openvpn/AUTHORS b/tdenetworkmanager/vpn-plugins/openvpn/AUTHORS index f4340ea..d61cb52 100644 --- a/tdenetworkmanager/vpn-plugins/openvpn/AUTHORS +++ b/tdenetworkmanager/vpn-plugins/openvpn/AUTHORS @@ -1,2 +1,3 @@ +Timothy Pearson Helmut Schaa , Thomas Kallenberg diff --git a/tdenetworkmanager/vpn-plugins/openvpn/CMakeLists.txt b/tdenetworkmanager/vpn-plugins/openvpn/CMakeLists.txt new file mode 100644 index 0000000..2646dbb --- /dev/null +++ b/tdenetworkmanager/vpn-plugins/openvpn/CMakeLists.txt @@ -0,0 +1,14 @@ +################################################# +# +# (C) 2012 Timothy Pearson +# kb9vqf (AT) pearsoncomputing.net +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +add_subdirectory( src ) + +install( FILES tdenetman_openvpn.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) diff --git a/tdenetworkmanager/vpn-plugins/openvpn/knetworkmanager_openvpn.desktop b/tdenetworkmanager/vpn-plugins/openvpn/knetworkmanager_openvpn.desktop deleted file mode 100644 index 2f8d837..0000000 --- a/tdenetworkmanager/vpn-plugins/openvpn/knetworkmanager_openvpn.desktop +++ /dev/null @@ -1,25 +0,0 @@ -[Desktop Entry] -Encoding=UTF-8 -Type=Service -Icon= -ServiceTypes=TDENetworkManager/VPNPlugin -X-TDE-Library=knetworkmanager_openvpn -X-NetworkManager-Services=openvpn -X-TDE-PluginInfo-Author=Helmut Schaa -X-TDE-PluginInfo-Email=hschaa@suse.de -X-TDE-PluginInfo-Name=knetworkmanager_openvpn -X-TDE-PluginInfo-Version=0.1 -X-TDE-PluginInfo-Website= -X-TDE-PluginInfo-Category=VPNService -X-TDE-PluginInfo-Depends= -X-TDE-PluginInfo-License=GPL -X-TDE-PluginInfo-EnabledByDefault=false -Name=OpenVPN -Name[bn]=ওপেন-ভিপিএন -Name[ca]=VPN oberta -Name[xx]=xxOpenVPNxx -Comment=OpenVPN -Comment[bn]=ওপেন-ভিপিএন -Comment[ca]=VPN oberta -Comment[xx]=xxOpenVPNxx - diff --git a/tdenetworkmanager/vpn-plugins/openvpn/src/CMakeLists.txt b/tdenetworkmanager/vpn-plugins/openvpn/src/CMakeLists.txt new file mode 100644 index 0000000..a565251 --- /dev/null +++ b/tdenetworkmanager/vpn-plugins/openvpn/src/CMakeLists.txt @@ -0,0 +1,43 @@ +################################################# +# +# (C) 2012 Timothy Pearson +# kb9vqf (AT) pearsoncomputing.net +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +add_definitions( -UQT_NO_ASCII_CAST ) + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR} + ${CMAKE_SOURCE_DIR}/tdenetworkmanager/src/settings + ${CMAKE_SOURCE_DIR}/tdenetworkmanager/src/configwidgets + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} + ${DBUS_TQT_INCLUDE_DIRS} + ${NM_UTIL_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + +##### tdenetman_openvpn (module) ################ + +set( target tdenetman_openvpn ) + +set( ${target}_SRCS + tdenetman-openvpn.cpp + openvpnprop.ui + openvpnauth.ui +) + +tde_add_kpart( ${target} AUTOMOC + SOURCES ${${target}_SRCS} + LINK tdeinit_kded-shared tdeinit_tdenetworkmanager-shared + DESTINATION ${PLUGIN_INSTALL_DIR} +) diff --git a/tdenetworkmanager/vpn-plugins/openvpn/src/knetworkmanager-openvpn.cpp b/tdenetworkmanager/vpn-plugins/openvpn/src/knetworkmanager-openvpn.cpp deleted file mode 100644 index ad27368..0000000 --- a/tdenetworkmanager/vpn-plugins/openvpn/src/knetworkmanager-openvpn.cpp +++ /dev/null @@ -1,566 +0,0 @@ -/*************************************************************************** - * - * knetworkmanager-openvpn.cpp - A NetworkManager frontend for TDE - * - * Copyright (C) 2006 Novell, Inc. - * - * Author: Helmut Schaa , - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - **************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "knetworkmanager-openvpn.h" - -typedef KGenericFactory OpenVPNPluginFactory; -K_EXPORT_COMPONENT_FACTORY( knetworkmanager_openvpn, OpenVPNPluginFactory("knetworkmanager_openvpn")); - -/************************************ -* OpenVPNPlugin -************************************/ -OpenVPNPlugin::OpenVPNPlugin(TQObject* parent, const char* name, const TQStringList& args) - : VPNPlugin(parent, name, args) -{ - -} - -OpenVPNPlugin::~OpenVPNPlugin() -{ - -} - -VPNConfigWidget* OpenVPNPlugin::CreateConfigWidget(TQWidget* parent) -{ - return new OpenVPNConfig(parent); -} - -VPNAuthenticationWidget* OpenVPNPlugin::CreateAuthenticationWidget(TQWidget* parent) -{ - return new OpenVPNAuthentication(parent); -} - -/************************************ -* OpenVPNConnectionType -************************************/ -OpenVPNConnectionType::CONNECTIONTYPE OpenVPNConnectionType::mapString2ConnectionType(int prop) -{ - if (prop == 0) - return X509; - else if (prop == 1) - return SHARED_KEY; - else if (prop == 2) - return PASSWORD; - else if (prop == 3) - return X509USERPASS; - return UNKNOWN; -} - -int OpenVPNConnectionType::mapConnectionType2String(CONNECTIONTYPE connType) -{ - switch(connType) - { - case X509: - return 0; - case SHARED_KEY: - return 1; - case PASSWORD: - return 2; - case X509USERPASS: - return 3; - default: - return -1; - } - return -1; -} - -/************************************ -* OpenVPNConfig -************************************/ - -OpenVPNConfig::OpenVPNConfig(TQWidget* parent) - : VPNConfigWidget(parent) -{ - TQVBoxLayout* layout = new TQVBoxLayout(this, 1, 1); - _openvpnWidget = new OpenVPNConfigWidget(this); - layout->addWidget(_openvpnWidget); - - connect(_openvpnWidget->chkUseCipher, TQT_SIGNAL(toggled(bool)), _openvpnWidget->cboCipher, TQT_SLOT(setEnabled(bool))); - connect(_openvpnWidget->chkUseTLS, TQT_SIGNAL(toggled(bool)), _openvpnWidget->cboDirection, TQT_SLOT(setEnabled(bool))); - connect(_openvpnWidget->chkUseTLS, TQT_SIGNAL(toggled(bool)), _openvpnWidget->editTLSAuth, TQT_SLOT(setEnabled(bool))); - connect(_openvpnWidget->chkIPAdresses, TQT_SIGNAL(toggled(bool)), _openvpnWidget->routes, TQT_SLOT(setEnabled(bool))); - - // add all Cipher modes to the Combobox - getCipherModes(); - - // switch to the right configuration interface when selecting the connection type - connect(_openvpnWidget->cboConnectionType, TQT_SIGNAL( activated(int)), _openvpnWidget->widgetStack, TQT_SLOT(raiseWidget(int))); - this->languageChange(); -} - -OpenVPNConfig::~OpenVPNConfig() -{ - -} - -void OpenVPNConfig::languageChange() -{ - _openvpnWidget->cboConnectionType->insertItem(i18n("X.509 Certificates"), OpenVPNConnectionType::X509 ); - _openvpnWidget->cboConnectionType->insertItem(i18n("Pre-shared key") , OpenVPNConnectionType::SHARED_KEY ); - _openvpnWidget->cboConnectionType->insertItem(i18n("Password Authentication") , OpenVPNConnectionType::PASSWORD ); - _openvpnWidget->cboConnectionType->insertItem(i18n("X.509 with Password Authentication") , OpenVPNConnectionType::X509USERPASS ); - - _openvpnWidget->cboDirection->insertItem(i18n("none")); - _openvpnWidget->cboDirection->insertItem(i18n("0")); - _openvpnWidget->cboDirection->insertItem(i18n("1")); -} - -TQString OpenVPNConfig::findOpenVPNBinary() -{ - static const char *openvpn_binary_paths[] = - { - "/usr/sbin/openvpn", - "/sbin/openvpn", - NULL - }; - - const char **openvpn_binary = openvpn_binary_paths; - - while (*openvpn_binary != NULL) { - if ( TQFileInfo(*openvpn_binary).exists()) - break; - openvpn_binary++; - } - - return *openvpn_binary; -} - - -void OpenVPNConfig::receiveCipherData(KProcess*, char* buffer, int len) -{ - // add possible cipher modes to the combobox - TQStringList cipherModes = TQStringList::split("\n", TQString::fromLatin1(buffer, len), false ); - for (TQStringList::ConstIterator it = cipherModes.begin(); it != cipherModes.end(); ++it) - { - _openvpnWidget->cboCipher->insertItem((*it)); - } -} - -void OpenVPNConfig::getCipherModes() -{ - // get all possible cipher modes - TQString openvpn = findOpenVPNBinary(); - if (!openvpn.isNull()) - { - KProcess* cipherHelper = new KProcess(); - cipherHelper->setUseShell(true, "/bin/sh"); - *cipherHelper << TQString::fromLatin1("%1 --show-ciphers | awk '/^[A-Z][A-Z0-9]+-/ { print $1 }'").arg(openvpn); - connect (cipherHelper, TQT_SIGNAL(receivedStdout(KProcess*, char*, int)), this, TQT_SLOT(receiveCipherData(KProcess*, char*, int))); - kdDebug() << "starting openvpn to get cipher modes" << endl; - if (!cipherHelper->start(KProcess::Block, KProcess::Stdout)) - kdDebug() << "error starting openvpn" << endl; - } - -} - -void OpenVPNConfig::setVPNData(const TQStringList& routes, const TQMap& properties) -{ - // fill up our inputfields - for(TQMap::ConstIterator it = properties.begin(); it != properties.end(); ++it) - { - TQString entry = it.key(); - TQString value = it.data(); - - if (entry == "connection-type") - { - OpenVPNConnectionType::CONNECTIONTYPE type = OpenVPNConnectionType::mapString2ConnectionType(value.toInt()); - _openvpnWidget->cboConnectionType->setCurrentItem(type); - _openvpnWidget->widgetStack->raiseWidget(type); - } - else if (entry == "remote") - { - _openvpnWidget->gateway->setText(value); - } - else if (entry == "port") - { - if (value.toInt() > 0) - { - _openvpnWidget->port->setText(value); - _openvpnWidget->chkDefaultPort->setChecked(false); - } - else - { - _openvpnWidget->chkDefaultPort->setChecked(true); - } - } - else if (entry == "proto" || entry == "proto-tcp") - { - _openvpnWidget->chkUseTCP->setChecked( value == "yes"); - } - else if (entry == "ca") - { - _openvpnWidget->editCA->setURL(value); - } - else if (entry == "cert") - { - _openvpnWidget->editCert->setURL(value); - } - else if (entry == "key") - { - _openvpnWidget->editKey->setURL(value); - } - else if (entry == "cipher") - { - _openvpnWidget->chkUseCipher->setChecked(true); - _openvpnWidget->cboCipher->setCurrentItem(value); - } - else if (entry == "comp-lzo") - { - _openvpnWidget->chkUseLZO->setChecked(value == "true"); - } - else if (entry == "shared-key" || entry == "static-key") - { - _openvpnWidget->editSharedKey->setURL(value); - } - else if (entry == "username") - { - _openvpnWidget->editUsername->setText(value); - } - else if (entry == "local-ip") - { - _openvpnWidget->editLocalIP->setText(value); - } - else if (entry == "remote-ip") - { - _openvpnWidget->editRemoteIP->setText(value); - } - else if (entry == "dev" || entry == "tap-dev") { - _openvpnWidget->chkUseTAP->setChecked(value == "true"); - } - else if (entry == "ta") - { - _openvpnWidget->chkUseTLS->setChecked(true); - _openvpnWidget->editTLSAuth->setURL(value); - } - else if (entry == "ta-dir") - { - _openvpnWidget->cboDirection->setCurrentItem(value); - } - else - { - kdDebug() << TQString("OpenVPN: Property '%1' not handled").arg(entry) << endl; - } - } - - // set routes - if (!routes.empty()) - { - _openvpnWidget->chkIPAdresses->setChecked(true); - _openvpnWidget->routes->setText(routes.join(" ")); - } -} - -TQMapOpenVPNConfig::getVPNProperties() -{ - // build a StingList of properties - TQMap strlist; - - strlist.insert("connection-type", TQString::number(OpenVPNConnectionType::mapConnectionType2String((OpenVPNConnectionType::CONNECTIONTYPE)_openvpnWidget->cboConnectionType->currentItem()))); - strlist.insert("remote", TQString(_openvpnWidget->gateway->text())); - - // port is not necessary - if (!_openvpnWidget->port->text().isEmpty() && !_openvpnWidget->chkDefaultPort->isChecked()) - strlist.insert("port", _openvpnWidget->port->text()); - - strlist.insert("ca", TQString(_openvpnWidget->editCA->url())); - strlist.insert("cert",TQString(_openvpnWidget->editCert->url() )); - strlist.insert("key", TQString(_openvpnWidget->editKey->url())); - - if (_openvpnWidget->chkUseCipher->isChecked()) - strlist.insert("cipher", TQString(_openvpnWidget->cboCipher->currentText())); - - if (_openvpnWidget->chkUseLZO->isChecked()) - strlist.insert("comp-lzo", TQString("true")); - else - strlist.insert("comp-lzo", TQString("false")); - - strlist.insert("static-key", TQString(_openvpnWidget->editSharedKey->url())); - strlist.insert("username", TQString(_openvpnWidget->editUsername->text())); - strlist.insert("local-ip", TQString(_openvpnWidget->editLocalIP->text())); - strlist.insert("remote-ip", TQString(_openvpnWidget->editRemoteIP->text())); - - if (_openvpnWidget->chkUseTAP->isChecked()) { - strlist.insert("tap-dev", "true"); - strlist.insert("proto-tcp", "true"); - } else { - strlist.insert("tap-dev", "false"); - strlist.insert("proto-tcp", "false"); - } - - if (_openvpnWidget->chkUseTLS->isChecked()) - strlist.insert("ta", TQString(_openvpnWidget->editTLSAuth->url())); - - strlist.insert("ta-dir", TQString(_openvpnWidget->cboDirection->currentText())); - - return strlist; -} - -TQStringList OpenVPNConfig::getVPNRoutes() -{ - TQStringList strlist; - if(_openvpnWidget->chkIPAdresses->isChecked()) - { - strlist = TQStringList::split(" ", _openvpnWidget->routes->text()); - } - return strlist; -} - -bool OpenVPNConfig::hasChanged() -{ - return true; -} - -bool OpenVPNConfig::isValid(TQStringList& err_msg) -{ - bool retval = true; - - // check gateway - if (_openvpnWidget->gateway->text().isEmpty()) - { - err_msg.append(i18n("You have to specify a gateway")); - retval = false; - } - - bool ok = false; - _openvpnWidget->port->text().toULong(&ok); - if (!ok && !_openvpnWidget->port->text().isEmpty() ) - { - err_msg.append(i18n("The port number has to be numeric")); - retval = false; - } - - switch(_openvpnWidget->cboConnectionType->currentItem()) - { - case OpenVPNConnectionType::X509: - // check if ca file is correct - if (_openvpnWidget->editCA->url().isEmpty()) - { - retval = false; - err_msg.append(i18n("no CA file provided")); - } - else if (!TQFileInfo(_openvpnWidget->editCA->url()).isFile()) - { - retval = false; - err_msg.append(i18n("CA file not valid")); - } - - // check if cert file is correct - if (_openvpnWidget->editCert->url().isEmpty()) - { - retval = false; - err_msg.append(i18n("no CERT file provided")); - } - else if (!TQFileInfo(_openvpnWidget->editCert->url()).isFile()) - { - retval = false; - err_msg.append(i18n("CERT file not valid")); - } - - // check if key file is correct - if (_openvpnWidget->editKey->url().isEmpty()) - { - retval = false; - err_msg.append(i18n("no Key file provided")); - } - else if (!TQFileInfo(_openvpnWidget->editKey->url()).isFile()) - { - retval = false; - err_msg.append(i18n("Key file not valid")); - } - - break; - - - case OpenVPNConnectionType::SHARED_KEY: - // check if a shared key is selected - if (_openvpnWidget->editSharedKey->url().isEmpty()) - { - retval = false; - err_msg.append(i18n("Please provide a valid shared key")); - } - // check if the shared key file exists - else if (!TQFileInfo(_openvpnWidget->editSharedKey->url()).exists()) - { - retval = false; - err_msg.append(i18n("Please provide a valid shared key")); - } - - // check if local ip is valid - if (!TQHostAddress().setAddress(_openvpnWidget->editLocalIP->text())) - { - retval = false; - err_msg.append(i18n("local IP is invalid")); - } - // check if remote ip is valid - if (!TQHostAddress().setAddress(_openvpnWidget->editRemoteIP->text())) - { - retval = false; - err_msg.append(i18n("remote IP is invalid")); - } - - break; - case OpenVPNConnectionType::PASSWORD: - // check if username is suplied - if (_openvpnWidget->editUsername->text().isEmpty()) - { - retval = false; - err_msg.append(i18n("no username provided")); - } - - // check if ca file is correct - if (_openvpnWidget->editCA->url().isEmpty()) - { - retval = false; - err_msg.append(i18n("no CA file provided")); - } - else if (!TQFileInfo(_openvpnWidget->editCA->url()).isFile()) - { - retval = false; - err_msg.append(i18n("CA file not valid")); - } - - break; - - - case OpenVPNConnectionType::X509USERPASS: - // check if username is suplied - if (_openvpnWidget->editUsername->text().isEmpty()) - { - retval = false; - err_msg.append(i18n("no username provided")); - } - - // check if ca file is correct - if (_openvpnWidget->editCA->url().isEmpty()) - { - retval = false; - err_msg.append(i18n("no CA file provided")); - } - else if (!TQFileInfo(_openvpnWidget->editCA->url()).isFile()) - { - retval = false; - err_msg.append(i18n("CA file not valid")); - } - - // check if cert file is correct - if (_openvpnWidget->editCert->url().isEmpty()) - { - retval = false; - err_msg.append(i18n("no CERT file provided")); - } - else if (!TQFileInfo(_openvpnWidget->editCert->url()).isFile()) - { - retval = false; - err_msg.append(i18n("CERT file not valid")); - } - - // check if key file is correct - if (_openvpnWidget->editKey->url().isEmpty()) - { - retval = false; - err_msg.append(i18n("no Key file provided")); - } - else if (!TQFileInfo(_openvpnWidget->editKey->url()).isFile()) - { - retval = false; - err_msg.append(i18n("Key file not valid")); - } - break; - } - - - return retval; -} - -/************************************ -* OpenVPNAuthentication -************************************/ - -OpenVPNAuthentication::OpenVPNAuthentication(TQWidget* parent, char* name) - : VPNAuthenticationWidget(parent, name) -{ - TQVBoxLayout* layout = new TQVBoxLayout(this, 1, 1); - _openvpnAuth = new OpenVPNAuthenticationWidget(this); - layout->addWidget(_openvpnAuth); -} - -OpenVPNAuthentication::~OpenVPNAuthentication() -{ - -} - -void OpenVPNAuthentication::setVPNData(const TQStringList& /*routes*/, const TQMap& properties) -{ - // find the connection type property - for(TQMap::ConstIterator it = properties.begin(); it != properties.end(); ++it) - { - if (it.key() == "connection-type") - { - _connectionType = OpenVPNConnectionType::mapString2ConnectionType(it.data().toInt()); - break; - } - } -} - -TQMap OpenVPNAuthentication::getPasswords() -{ - TQMap pwds; - if ((_connectionType == OpenVPNConnectionType::PASSWORD) || (_connectionType == OpenVPNConnectionType::X509USERPASS)) - pwds.insert("password", TQString(_openvpnAuth->editUserPassword->password())); - else - pwds.insert("no-secret", TQString("true")); - - return pwds; -} - -void OpenVPNAuthentication::setPasswords(TQString name, TQString value) { - if (name == TQString("password")) { - _openvpnAuth->editUserPassword->erase(); - _openvpnAuth->editUserPassword->insert(value); - } -} - -bool OpenVPNAuthentication::needsUserInteraction() -{ - if ((_connectionType == OpenVPNConnectionType::PASSWORD) || (_connectionType == OpenVPNConnectionType::X509USERPASS)) - return true; - return false; -} - diff --git a/tdenetworkmanager/vpn-plugins/openvpn/src/knetworkmanager-openvpn.h b/tdenetworkmanager/vpn-plugins/openvpn/src/knetworkmanager-openvpn.h deleted file mode 100644 index 02c328f..0000000 --- a/tdenetworkmanager/vpn-plugins/openvpn/src/knetworkmanager-openvpn.h +++ /dev/null @@ -1,110 +0,0 @@ -/*************************************************************************** - * - * knetworkmanager-openvpn.h - A NetworkManager frontend for TDE - * - * Copyright (C) 2006 Novell, Inc. - * - * Author: Helmut Schaa , - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - **************************************************************************/ - -#ifndef KNETWORKMANAGER_OPENVPN_H -#define KNETWORKMANAGER_OPENVPN_H - -#include -#include -#include -#include -#include - -#include "knetworkmanager-vpnplugin.h" -#include "openvpnprop.h" -#include "openvpnauth.h" - -class OpenVPNPlugin : public VPNPlugin -{ - Q_OBJECT - - public: - OpenVPNPlugin(TQObject*, const char*, const TQStringList&); - ~OpenVPNPlugin(); - - VPNConfigWidget* CreateConfigWidget(TQWidget* parent=0); - VPNAuthenticationWidget* CreateAuthenticationWidget(TQWidget* parent=0); -}; - -class OpenVPNConnectionType -{ - public: - enum CONNECTIONTYPE - { - UNKNOWN = -1 - , X509 = 0 - , SHARED_KEY - , PASSWORD - , X509USERPASS - }; - - static CONNECTIONTYPE mapString2ConnectionType(int string); - static int mapConnectionType2String(CONNECTIONTYPE connectionType); -}; - -class OpenVPNConfig : public VPNConfigWidget -{ - Q_OBJECT - - public: - void setVPNData(const TQStringList& routes, const TQMap& properties); - TQMap getVPNProperties(); - TQStringList getVPNRoutes(); - bool hasChanged(); - bool isValid(TQStringList& ); - - OpenVPNConfig(TQWidget* parent); - ~OpenVPNConfig(); - - public slots: - void receiveCipherData(KProcess*, char*, int); - - private: - OpenVPNConfigWidget* _openvpnWidget; - - void getCipherModes(); - TQString findOpenVPNBinary(); - - protected slots: - void languageChange(); -}; - -class OpenVPNAuthentication : public VPNAuthenticationWidget -{ - Q_OBJECT - - public: - OpenVPNAuthentication(TQWidget* parent = NULL, char* name = NULL); - ~OpenVPNAuthentication(); - void setVPNData(const TQStringList&, const TQMap&); - TQMap getPasswords(); - void setPasswords(TQString name, TQString value); - bool needsUserInteraction(); - - private: - OpenVPNAuthenticationWidget* _openvpnAuth; - OpenVPNConnectionType::CONNECTIONTYPE _connectionType; -}; - -#endif /* KNETWORKMANAGER_OPENVPN_H */ diff --git a/tdenetworkmanager/vpn-plugins/openvpn/src/tdenetman-openvpn.cpp b/tdenetworkmanager/vpn-plugins/openvpn/src/tdenetman-openvpn.cpp new file mode 100644 index 0000000..7cee87a --- /dev/null +++ b/tdenetworkmanager/vpn-plugins/openvpn/src/tdenetman-openvpn.cpp @@ -0,0 +1,603 @@ +/*************************************************************************** + * + * knetworkmanager-openvpn.cpp - A NetworkManager frontend for TDE + * + * Copyright (C) 2006 Novell, Inc. + * + * Author: Helmut Schaa , + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + **************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "tdenetman-openvpn.h" + +typedef KGenericFactory OpenVPNPluginFactory; +K_EXPORT_COMPONENT_FACTORY( tdenetman_openvpn, OpenVPNPluginFactory("tdenetman_openvpn")); + +/************************************ +* OpenVPNPlugin +************************************/ +OpenVPNPlugin::OpenVPNPlugin(TQObject* parent, const char* name, const TQStringList& args) + : VPNPlugin(parent, name, args) +{ + +} + +OpenVPNPlugin::~OpenVPNPlugin() +{ + +} + +VPNConfigWidget* OpenVPNPlugin::CreateConfigWidget(TQWidget* parent) +{ + return new OpenVPNConfig(parent); +} + +VPNAuthenticationWidget* OpenVPNPlugin::CreateAuthenticationWidget(TQWidget* parent) +{ + return new OpenVPNAuthentication(parent); +} + +/************************************ +* OpenVPNConnectionType +************************************/ +OpenVPNConnectionType::CONNECTIONTYPE OpenVPNConnectionType::mapString2ConnectionType(int prop) +{ + if (prop == 0) + return X509; + else if (prop == 1) + return SHARED_KEY; + else if (prop == 2) + return PASSWORD; + else if (prop == 3) + return X509USERPASS; + return UNKNOWN; +} + +int OpenVPNConnectionType::mapConnectionType2String(CONNECTIONTYPE connType) +{ + switch(connType) + { + case X509: + return 0; + case SHARED_KEY: + return 1; + case PASSWORD: + return 2; + case X509USERPASS: + return 3; + default: + return -1; + } + return -1; +} + +/************************************ +* OpenVPNConfig +************************************/ + +OpenVPNConfig::OpenVPNConfig(TQWidget* parent) + : VPNConfigWidget(parent) +{ + TQVBoxLayout* layout = new TQVBoxLayout(this, 1, 1); + _openvpnWidget = new OpenVPNConfigWidget(this); + layout->addWidget(_openvpnWidget); + + connect(_openvpnWidget->chkUseCipher, TQT_SIGNAL(toggled(bool)), _openvpnWidget->cboCipher, TQT_SLOT(setEnabled(bool))); + connect(_openvpnWidget->chkUseTLS, TQT_SIGNAL(toggled(bool)), _openvpnWidget->cboDirection, TQT_SLOT(setEnabled(bool))); + connect(_openvpnWidget->chkUseTLS, TQT_SIGNAL(toggled(bool)), _openvpnWidget->editTLSAuth, TQT_SLOT(setEnabled(bool))); + connect(_openvpnWidget->chkIPAdresses, TQT_SIGNAL(toggled(bool)), _openvpnWidget->routes, TQT_SLOT(setEnabled(bool))); + + // add all Cipher modes to the Combobox + getCipherModes(); + + // switch to the right configuration interface when selecting the connection type + connect(_openvpnWidget->cboConnectionType, TQT_SIGNAL( activated(int)), _openvpnWidget->widgetStack, TQT_SLOT(raiseWidget(int))); + this->languageChange(); +} + +OpenVPNConfig::~OpenVPNConfig() +{ + +} + +void OpenVPNConfig::languageChange() +{ + _openvpnWidget->cboConnectionType->insertItem(i18n("X.509 Certificates"), OpenVPNConnectionType::X509 ); + _openvpnWidget->cboConnectionType->insertItem(i18n("Pre-shared key") , OpenVPNConnectionType::SHARED_KEY ); + _openvpnWidget->cboConnectionType->insertItem(i18n("Password Authentication") , OpenVPNConnectionType::PASSWORD ); + _openvpnWidget->cboConnectionType->insertItem(i18n("X.509 with Password Authentication") , OpenVPNConnectionType::X509USERPASS ); + + _openvpnWidget->cboDirection->insertItem(i18n("none")); + _openvpnWidget->cboDirection->insertItem(i18n("0")); + _openvpnWidget->cboDirection->insertItem(i18n("1")); +} + +TQString OpenVPNConfig::findOpenVPNBinary() +{ + static const char *openvpn_binary_paths[] = + { + "/usr/sbin/openvpn", + "/sbin/openvpn", + NULL + }; + + const char **openvpn_binary = openvpn_binary_paths; + + while (*openvpn_binary != NULL) { + if ( TQFileInfo(*openvpn_binary).exists()) + break; + openvpn_binary++; + } + + return *openvpn_binary; +} + + +void OpenVPNConfig::receiveCipherData(KProcess*, char* buffer, int len) +{ + // add possible cipher modes to the combobox + TQStringList cipherModes = TQStringList::split("\n", TQString::fromLatin1(buffer, len), false ); + for (TQStringList::ConstIterator it = cipherModes.begin(); it != cipherModes.end(); ++it) + { + _openvpnWidget->cboCipher->insertItem((*it)); + } +} + +void OpenVPNConfig::getCipherModes() +{ + // get all possible cipher modes + TQString openvpn = findOpenVPNBinary(); + if (!openvpn.isNull()) { + KProcess* cipherHelper = new KProcess(); + cipherHelper->setUseShell(true, "/bin/sh"); + *cipherHelper << TQString::fromLatin1("%1 --show-ciphers | awk '/^[A-Z][A-Z0-9]+-/ { print $1 }'").arg(openvpn); + connect (cipherHelper, TQT_SIGNAL(receivedStdout(KProcess*, char*, int)), this, TQT_SLOT(receiveCipherData(KProcess*, char*, int))); + kdDebug() << "starting openvpn to get cipher modes" << endl; + if (!cipherHelper->start(KProcess::Block, KProcess::Stdout)) { + kdDebug() << "error starting openvpn" << endl; + } + } +} + +void OpenVPNConfig::setVPNData(TDENetworkSingleRouteConfigurationList& routes, TDENetworkSettingsMap& properties, TDENetworkSettingsMap& secrets) +{ + m_vpnProperties = properties; + m_vpnSecrets = secrets; + + // fill up our inputfields + for(TQMap::ConstIterator it = properties.begin(); it != properties.end(); ++it) + { + TQString entry = it.key(); + TQString value = it.data(); + + if (entry == "connection-type") + { + OpenVPNConnectionType::CONNECTIONTYPE type = OpenVPNConnectionType::mapString2ConnectionType(value.toInt()); + _openvpnWidget->cboConnectionType->setCurrentItem(type); + _openvpnWidget->widgetStack->raiseWidget(type); + } + else if (entry == "remote") + { + _openvpnWidget->gateway->setText(value); + } + else if (entry == "port") + { + if (value.toInt() > 0) + { + _openvpnWidget->port->setText(value); + _openvpnWidget->chkDefaultPort->setChecked(false); + } + else + { + _openvpnWidget->chkDefaultPort->setChecked(true); + } + } + else if (entry == "proto" || entry == "proto-tcp") + { + _openvpnWidget->chkUseTCP->setChecked( value == "yes"); + } + else if (entry == "ca") + { + _openvpnWidget->editCA->setURL(value); + } + else if (entry == "cert") + { + _openvpnWidget->editCert->setURL(value); + } + else if (entry == "key") + { + _openvpnWidget->editKey->setURL(value); + } + else if (entry == "cipher") + { + _openvpnWidget->chkUseCipher->setChecked(true); + _openvpnWidget->cboCipher->setCurrentItem(value); + } + else if (entry == "comp-lzo") + { + _openvpnWidget->chkUseLZO->setChecked(value == "true"); + } + else if (entry == "shared-key" || entry == "static-key") + { + _openvpnWidget->editSharedKey->setURL(value); + } + else if (entry == "username") + { + _openvpnWidget->editUsername->setText(value); + } + else if (entry == "local-ip") + { + _openvpnWidget->editLocalIP->setText(value); + } + else if (entry == "remote-ip") + { + _openvpnWidget->editRemoteIP->setText(value); + } + else if (entry == "dev" || entry == "tap-dev") { + _openvpnWidget->chkUseTAP->setChecked(value == "true"); + } + else if (entry == "ta") + { + _openvpnWidget->chkUseTLS->setChecked(true); + _openvpnWidget->editTLSAuth->setURL(value); + } + else if (entry == "ta-dir") + { + _openvpnWidget->cboDirection->setCurrentItem(value); + } + else + { + kdDebug() << TQString("OpenVPN: Property '%1' not handled").arg(entry) << endl; + } + } + + // set routes + if (!routes.empty()) + { + _openvpnWidget->chkIPAdresses->setChecked(true); + TQStringList routesText; + for (TDENetworkSingleRouteConfigurationList::Iterator it = routes.begin(); it != routes.end(); ++it) { + routesText.append(TQString("%1/%2").arg((*it).ipAddress.toString()).arg((*it).networkMask.toCIDRMask())); + } + _openvpnWidget->routes->setText(routesText.join(" ")); + } +} + +TDENetworkSettingsMap OpenVPNConfig::getVPNProperties() +{ + // Build a list of properties + m_vpnProperties.insert("connection-type", TQString::number(OpenVPNConnectionType::mapConnectionType2String((OpenVPNConnectionType::CONNECTIONTYPE)_openvpnWidget->cboConnectionType->currentItem()))); + m_vpnProperties.insert("remote", TQString(_openvpnWidget->gateway->text())); + + // port is not necessary + if (!_openvpnWidget->port->text().isEmpty() && !_openvpnWidget->chkDefaultPort->isChecked()) { + m_vpnProperties.insert("port", _openvpnWidget->port->text()); + } + else { + m_vpnProperties.remove("port"); + } + + m_vpnProperties.insert("ca", TQString(_openvpnWidget->editCA->url())); + m_vpnProperties.insert("cert",TQString(_openvpnWidget->editCert->url() )); + m_vpnProperties.insert("key", TQString(_openvpnWidget->editKey->url())); + + if (_openvpnWidget->chkUseCipher->isChecked()) { + m_vpnProperties.insert("cipher", TQString(_openvpnWidget->cboCipher->currentText())); + } + else { + m_vpnProperties.remove("cipher"); + } + + if (_openvpnWidget->chkUseLZO->isChecked()) { + m_vpnProperties.insert("comp-lzo", TQString("true")); + } + else { + m_vpnProperties.insert("comp-lzo", TQString("false")); + } + + m_vpnProperties.insert("static-key", TQString(_openvpnWidget->editSharedKey->url())); + m_vpnProperties.insert("username", TQString(_openvpnWidget->editUsername->text())); + m_vpnProperties.insert("local-ip", TQString(_openvpnWidget->editLocalIP->text())); + m_vpnProperties.insert("remote-ip", TQString(_openvpnWidget->editRemoteIP->text())); + + if (_openvpnWidget->chkUseTAP->isChecked()) { + m_vpnProperties.insert("tap-dev", "true"); + m_vpnProperties.insert("proto-tcp", "true"); + } + else { + m_vpnProperties.insert("tap-dev", "false"); + m_vpnProperties.insert("proto-tcp", "false"); + } + + if (_openvpnWidget->chkUseTLS->isChecked()) { + m_vpnProperties.insert("ta", TQString(_openvpnWidget->editTLSAuth->url())); + } + else { + m_vpnProperties.remove("ta"); + } + + m_vpnProperties.insert("ta-dir", TQString(_openvpnWidget->cboDirection->currentText())); + + return m_vpnProperties; +} + +TDENetworkSettingsMap OpenVPNConfig::getVPNSecrets() { + // Build a list of secrets + // FIXME + + return m_vpnSecrets; +} + +TDENetworkSingleRouteConfigurationList OpenVPNConfig::getVPNRoutes() +{ + TDENetworkSingleRouteConfigurationList ret; + TQStringList strlist; + if(_openvpnWidget->chkIPAdresses->isChecked()) { + strlist = TQStringList::split(" ", _openvpnWidget->routes->text()); + } + + for (TQStringList::Iterator it = strlist.begin(); it != strlist.end(); ++it) { + TQStringList pieces = TQStringList::split("/", (*it)); + TDENetworkSingleRouteConfiguration routeconfig; + routeconfig.ipAddress.setAddress(pieces[0]); + if (pieces.count() > 1) { + routeconfig.networkMask.fromCIDRMask(pieces[1].toUInt()); + } + ret.append(routeconfig); + } + + return ret; +} + +bool OpenVPNConfig::hasChanged() +{ + return true; +} + +bool OpenVPNConfig::isValid(TQStringList& err_msg) +{ + bool retval = true; + + // check gateway + if (_openvpnWidget->gateway->text().isEmpty()) + { + err_msg.append(i18n("You have to specify a gateway")); + retval = false; + } + + bool ok = false; + _openvpnWidget->port->text().toULong(&ok); + if (!ok && !_openvpnWidget->port->text().isEmpty() ) + { + err_msg.append(i18n("The port number has to be numeric")); + retval = false; + } + + switch(_openvpnWidget->cboConnectionType->currentItem()) + { + case OpenVPNConnectionType::X509: + // check if ca file is correct + if (_openvpnWidget->editCA->url().isEmpty()) + { + retval = false; + err_msg.append(i18n("no CA file provided")); + } + else if (!TQFileInfo(_openvpnWidget->editCA->url()).isFile()) + { + retval = false; + err_msg.append(i18n("CA file not valid")); + } + + // check if cert file is correct + if (_openvpnWidget->editCert->url().isEmpty()) + { + retval = false; + err_msg.append(i18n("no CERT file provided")); + } + else if (!TQFileInfo(_openvpnWidget->editCert->url()).isFile()) + { + retval = false; + err_msg.append(i18n("CERT file not valid")); + } + + // check if key file is correct + if (_openvpnWidget->editKey->url().isEmpty()) + { + retval = false; + err_msg.append(i18n("no Key file provided")); + } + else if (!TQFileInfo(_openvpnWidget->editKey->url()).isFile()) + { + retval = false; + err_msg.append(i18n("Key file not valid")); + } + + break; + + + case OpenVPNConnectionType::SHARED_KEY: + // check if a shared key is selected + if (_openvpnWidget->editSharedKey->url().isEmpty()) + { + retval = false; + err_msg.append(i18n("Please provide a valid shared key")); + } + // check if the shared key file exists + else if (!TQFileInfo(_openvpnWidget->editSharedKey->url()).exists()) + { + retval = false; + err_msg.append(i18n("Please provide a valid shared key")); + } + + // check if local ip is valid + if (!TQHostAddress().setAddress(_openvpnWidget->editLocalIP->text())) + { + retval = false; + err_msg.append(i18n("local IP is invalid")); + } + // check if remote ip is valid + if (!TQHostAddress().setAddress(_openvpnWidget->editRemoteIP->text())) + { + retval = false; + err_msg.append(i18n("remote IP is invalid")); + } + + break; + case OpenVPNConnectionType::PASSWORD: + // check if username is suplied + if (_openvpnWidget->editUsername->text().isEmpty()) + { + retval = false; + err_msg.append(i18n("no username provided")); + } + + // check if ca file is correct + if (_openvpnWidget->editCA->url().isEmpty()) + { + retval = false; + err_msg.append(i18n("no CA file provided")); + } + else if (!TQFileInfo(_openvpnWidget->editCA->url()).isFile()) + { + retval = false; + err_msg.append(i18n("CA file not valid")); + } + + break; + + + case OpenVPNConnectionType::X509USERPASS: + // check if username is suplied + if (_openvpnWidget->editUsername->text().isEmpty()) + { + retval = false; + err_msg.append(i18n("no username provided")); + } + + // check if ca file is correct + if (_openvpnWidget->editCA->url().isEmpty()) + { + retval = false; + err_msg.append(i18n("no CA file provided")); + } + else if (!TQFileInfo(_openvpnWidget->editCA->url()).isFile()) + { + retval = false; + err_msg.append(i18n("CA file not valid")); + } + + // check if cert file is correct + if (_openvpnWidget->editCert->url().isEmpty()) + { + retval = false; + err_msg.append(i18n("no CERT file provided")); + } + else if (!TQFileInfo(_openvpnWidget->editCert->url()).isFile()) + { + retval = false; + err_msg.append(i18n("CERT file not valid")); + } + + // check if key file is correct + if (_openvpnWidget->editKey->url().isEmpty()) + { + retval = false; + err_msg.append(i18n("no Key file provided")); + } + else if (!TQFileInfo(_openvpnWidget->editKey->url()).isFile()) + { + retval = false; + err_msg.append(i18n("Key file not valid")); + } + break; + } + + + return retval; +} + +/************************************ +* OpenVPNAuthentication +************************************/ + +OpenVPNAuthentication::OpenVPNAuthentication(TQWidget* parent, char* name) + : VPNAuthenticationWidget(parent, name) +{ + TQVBoxLayout* layout = new TQVBoxLayout(this, 1, 1); + _openvpnAuth = new OpenVPNAuthenticationWidget(this); + layout->addWidget(_openvpnAuth); +} + +OpenVPNAuthentication::~OpenVPNAuthentication() +{ + +} + +void OpenVPNAuthentication::setVPNData(TDENetworkSingleRouteConfigurationList& /*routes*/, TDENetworkSettingsMap& properties, TDENetworkSettingsMap& secrets) +{ + // find the connection type property + for(TQMap::ConstIterator it = properties.begin(); it != properties.end(); ++it) + { + if (it.key() == "connection-type") + { + _connectionType = OpenVPNConnectionType::mapString2ConnectionType(it.data().toInt()); + break; + } + } +} + +TDENetworkSettingsMap OpenVPNAuthentication::getPasswords() +{ + TQMap pwds; + if ((_connectionType == OpenVPNConnectionType::PASSWORD) || (_connectionType == OpenVPNConnectionType::X509USERPASS)) + pwds.insert("password", TQString(_openvpnAuth->editUserPassword->password())); + else + pwds.insert("no-secret", TQString("true")); + + return pwds; +} + +void OpenVPNAuthentication::setPasswords(TDENetworkSettingsMap secrets) { + if (secrets.contains("password")) { + _openvpnAuth->editUserPassword->erase(); + _openvpnAuth->editUserPassword->insert(secrets["password"]); + } +} + +bool OpenVPNAuthentication::needsUserInteraction() +{ + if ((_connectionType == OpenVPNConnectionType::PASSWORD) || (_connectionType == OpenVPNConnectionType::X509USERPASS)) + return true; + return false; +} + +#include "tdenetman-openvpn.moc" \ No newline at end of file diff --git a/tdenetworkmanager/vpn-plugins/openvpn/src/tdenetman-openvpn.h b/tdenetworkmanager/vpn-plugins/openvpn/src/tdenetman-openvpn.h new file mode 100644 index 0000000..2f8889d --- /dev/null +++ b/tdenetworkmanager/vpn-plugins/openvpn/src/tdenetman-openvpn.h @@ -0,0 +1,114 @@ +/*************************************************************************** + * + * knetworkmanager-openvpn.h - A NetworkManager frontend for TDE + * + * Copyright (C) 2006 Novell, Inc. + * + * Author: Helmut Schaa , + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + **************************************************************************/ + +#ifndef KNETWORKMANAGER_OPENVPN_H +#define KNETWORKMANAGER_OPENVPN_H + +#include +#include +#include +#include +#include + +#include "tdenetman-vpnplugin.h" +#include "openvpnprop.h" +#include "openvpnauth.h" + +class OpenVPNPlugin : public VPNPlugin +{ + Q_OBJECT + + public: + OpenVPNPlugin(TQObject*, const char*, const TQStringList&); + ~OpenVPNPlugin(); + + VPNConfigWidget* CreateConfigWidget(TQWidget* parent=0); + VPNAuthenticationWidget* CreateAuthenticationWidget(TQWidget* parent=0); +}; + +class OpenVPNConnectionType +{ + public: + enum CONNECTIONTYPE + { + UNKNOWN = -1 + , X509 = 0 + , SHARED_KEY + , PASSWORD + , X509USERPASS + }; + + static CONNECTIONTYPE mapString2ConnectionType(int string); + static int mapConnectionType2String(CONNECTIONTYPE connectionType); +}; + +class OpenVPNConfig : public VPNConfigWidget +{ + Q_OBJECT + + public: + void setVPNData(TDENetworkSingleRouteConfigurationList& routes, TDENetworkSettingsMap& properties, TDENetworkSettingsMap& secrets); + TDENetworkSettingsMap getVPNProperties(); + TDENetworkSettingsMap getVPNSecrets(); + TDENetworkSingleRouteConfigurationList getVPNRoutes(); + bool hasChanged(); + bool isValid(TQStringList&); + + OpenVPNConfig(TQWidget* parent); + ~OpenVPNConfig(); + + public slots: + void receiveCipherData(KProcess*, char*, int); + + private: + OpenVPNConfigWidget* _openvpnWidget; + + void getCipherModes(); + TQString findOpenVPNBinary(); + + TDENetworkSettingsMap m_vpnProperties; + TDENetworkSettingsMap m_vpnSecrets; + + protected slots: + void languageChange(); +}; + +class OpenVPNAuthentication : public VPNAuthenticationWidget +{ + Q_OBJECT + + public: + OpenVPNAuthentication(TQWidget* parent = NULL, char* name = NULL); + ~OpenVPNAuthentication(); + void setVPNData(TDENetworkSingleRouteConfigurationList& routes, TDENetworkSettingsMap& properties, TDENetworkSettingsMap& secrets); + TDENetworkSettingsMap getPasswords(); + void setPasswords(TDENetworkSettingsMap secrets); + bool needsUserInteraction(); + + private: + OpenVPNAuthenticationWidget* _openvpnAuth; + OpenVPNConnectionType::CONNECTIONTYPE _connectionType; +}; + +#endif /* KNETWORKMANAGER_OPENVPN_H */ diff --git a/tdenetworkmanager/vpn-plugins/openvpn/tdenetman_openvpn.desktop b/tdenetworkmanager/vpn-plugins/openvpn/tdenetman_openvpn.desktop new file mode 100644 index 0000000..dad55c0 --- /dev/null +++ b/tdenetworkmanager/vpn-plugins/openvpn/tdenetman_openvpn.desktop @@ -0,0 +1,25 @@ +[Desktop Entry] +Encoding=UTF-8 +Type=Service +Icon= +ServiceTypes=TDENetworkManager/VPNPlugin +X-TDE-Library=tdenetman_openvpn +X-NetworkManager-Services=openvpn +X-TDE-PluginInfo-Author=Timothy Pearson +X-TDE-PluginInfo-Email=kb9vqf@pearsoncomputing.net +X-TDE-PluginInfo-Name=tdenetman_openvpn +X-TDE-PluginInfo-Version=0.1 +X-TDE-PluginInfo-Website= +X-TDE-PluginInfo-Category=VPNService +X-TDE-PluginInfo-Depends= +X-TDE-PluginInfo-License=GPL +X-TDE-PluginInfo-EnabledByDefault=false +Name=OpenVPN +Name[bn]=ওপেন-ভিপিএন +Name[ca]=VPN oberta +Name[xx]=xxOpenVPNxx +Comment=OpenVPN +Comment[bn]=ওপেন-ভিপিএন +Comment[ca]=VPN oberta +Comment[xx]=xxOpenVPNxx + -- cgit v1.2.1