summaryrefslogtreecommitdiffstats
path: root/tdenetworkmanager/vpn-plugins/pptp/src/tdenetman-pptp.cpp
blob: d3fca421dedf610d1017919e39d16af200fe1f21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/***************************************************************************
 *
 * tdenetman-pptp.cpp - A NetworkManager frontend for TDE
 *
 * Copyright (C) 2006 Novell, Inc.
 *
 * Author: Helmut Schaa <hschaa@suse.de>, <Helmut.Schaa@gmx.de>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 **************************************************************************/

#include <tdelocale.h>
#include <tqmessagebox.h>
#include <tqbutton.h>
#include <kcombobox.h>
#include <klineedit.h>
#include <kurlrequester.h>
#include <tqobjectlist.h>
#include <tqobject.h>
#include <tqcheckbox.h>
#include <kpassdlg.h>
#include <kgenericfactory.h>
#include <tqlabel.h>

#include "tdenetman-pptp.h"

typedef KGenericFactory<PPTPPlugin> PPTPPluginFactory;
K_EXPORT_COMPONENT_FACTORY(tdenetman_pptp, PPTPPluginFactory("tdenetman_pptp"));


PPTPPlugin::PPTPPlugin(TQObject* parent, const char* name, const TQStringList& args)
	: VPNPlugin(parent, name, args)
{
	TDELocale* loc = TDEGlobal::locale();
	loc->insertCatalogue("NetworkManager-pptp");
}

PPTPPlugin::~PPTPPlugin()
{

}

VPNConfigWidget* PPTPPlugin::CreateConfigWidget(TQWidget* parent)
{
	return new PPTPConfig(parent);
}

VPNAuthenticationWidget* PPTPPlugin::CreateAuthenticationWidget(TQWidget* parent)
{
	return new PPTPAuthentication(parent);
}


PPTPConfig::PPTPConfig(TQWidget* parent)
	: VPNConfigWidget(parent)
{
	TQVBoxLayout* layout = new TQVBoxLayout(this, 1, 1);
	_pptpWidget = new PPTPConfigWidget(this);
	layout->addWidget(_pptpWidget);

	connect(_pptpWidget->chkIPAdresses, TQT_SIGNAL(toggled(bool)), _pptpWidget->routes, TQT_SLOT(setEnabled(bool)));

	this->languageChange();
}

PPTPConfig::~PPTPConfig()
{

}

void PPTPConfig::languageChange()
{

}

void PPTPConfig::setVPNData(TDENetworkSingleRouteConfigurationList& routes, TDENetworkSettingsMap& properties, TDENetworkSettingsMap& secrets) {
	m_vpnProperties = properties;
	m_vpnSecrets = secrets;

	// fill up our inputfields (only textfields atm)
	for(TQMap<TQString, TQString>::ConstIterator it = properties.begin(); it != properties.end(); ++it)
	{
		TQString entry = it.key();
		TQString value = it.data();

		if (entry == "gateway")
		{
			_pptpWidget->gateway->setText(value);
		}
		else if (entry == "refuse-eap")
		{
			_pptpWidget->chk_refuseeap->setChecked(value == "yes" || value == "true");
		}
		else if (entry == "refuse-pap")
		{
			_pptpWidget->chk_refusepap->setChecked(value == "yes" || value == "true");
		}
		else if (entry == "refuse-chap")
		{
			_pptpWidget->chk_refusechap->setChecked(value == "yes" || value == "true");
		}
		else if (entry == "refuse-mschap")
		{
			_pptpWidget->chk_refusemschap->setChecked(value == "yes" || value == "true");
		}
		else if (entry == "refuse-mschapv2")
		{
			_pptpWidget->chk_refusemschapv2->setChecked(value == "yes" || value == "true");
		}
		else if (entry == "require-mppe")
		{
			_pptpWidget->chk_requiremppe->setChecked(value == "yes" || value == "true");
		}
		else if (entry == "require-mppe-40")
		{
			_pptpWidget->chk_requiremppe40->setChecked(value == "yes" || value == "true");
		}
		else if (entry == "require-mppe-128")
		{
			_pptpWidget->chk_requiremppe128->setChecked(value == "yes" || value == "true");
		}
		else if (entry == "mppe-stateful")
		{
			_pptpWidget->chk_mppestateful->setChecked(value == "yes" || value == "true");
		}
		else if (entry == "nodeflate")
		{
			_pptpWidget->chk_nodeflate->setChecked(value == "yes" || value == "true");
		}
	}

	// set routes
	if (!routes.empty())
	{
		_pptpWidget->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()));
		}
		_pptpWidget->routes->setText(routesText.join(" "));
	}
}

TDENetworkSettingsMap PPTPConfig::getVPNProperties() {
	// Build a list of properties
	m_vpnProperties.insert("gateway", TQString(_pptpWidget->gateway->text()));
	m_vpnProperties.insert("refuse-eap", TQString(_pptpWidget->chk_refuseeap->isChecked() ? "yes" : "no"));
	m_vpnProperties.insert("refuse-pap", TQString(_pptpWidget->chk_refusepap->isChecked() ? "yes" : "no"));
	m_vpnProperties.insert("refuse-chap", TQString(_pptpWidget->chk_refusechap->isChecked() ? "yes" : "no"));
	m_vpnProperties.insert("refuse-mschap", TQString(_pptpWidget->chk_refusemschap->isChecked() ? "yes" : "no"));
	m_vpnProperties.insert("refuse-mschapv2", TQString(_pptpWidget->chk_refusemschapv2->isChecked() ? "yes" : "no"));
	m_vpnProperties.insert("require-mppe", TQString(_pptpWidget->chk_requiremppe->isChecked() ? "yes" : "no"));
	m_vpnProperties.insert("require-mppe-40", TQString(_pptpWidget->chk_requiremppe40->isChecked() ? "yes" : "no"));
	m_vpnProperties.insert("require-mppe-128", TQString(_pptpWidget->chk_requiremppe128->isChecked() ? "yes" : "no"));
	m_vpnProperties.insert("mppe-stateful", TQString(_pptpWidget->chk_mppestateful->isChecked() ? "yes" : "no"));
	m_vpnProperties.insert("nodeflate", TQString(_pptpWidget->chk_nodeflate->isChecked() ? "yes" : "no"));

	// Current network-manager-pptp plugin supports bluetooth-gprs,dialup and pptp.
	// We want a pptp connection.
	//m_vpnProperties.insert("ppp-connection-type", "pptp");

	return m_vpnProperties;
}

TDENetworkSettingsMap PPTPConfig::getVPNSecrets() {
	// Build a list of secrets
	// FIXME

	return m_vpnSecrets;
}

TDENetworkSingleRouteConfigurationList PPTPConfig::getVPNRoutes()
{
	TDENetworkSingleRouteConfigurationList ret;
	TQStringList strlist;
	if(_pptpWidget->chkIPAdresses->isChecked()) {
		strlist = TQStringList::split(" ", _pptpWidget->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 PPTPConfig::hasChanged()
{
	return true;
}

bool PPTPConfig::isValid(TQStringList& err_msg)
{
	bool retval = true;
	if(_pptpWidget->gateway->text() == "")
	{
		err_msg.append(i18n("At least the gateway has to be supplied."));
		retval = false;
	}
	return retval;
}

PPTPAuthentication::PPTPAuthentication(TQWidget* parent, char* name)
	: VPNAuthenticationWidget(parent, name)
{
	TQVBoxLayout* layout = new TQVBoxLayout(this, 1, 1);
	_pptpAuth = new PPTPAuthenticationWidget(this);
	layout->addWidget(_pptpAuth);
}

PPTPAuthentication::~PPTPAuthentication()
{

}

TDENetworkSettingsMap PPTPAuthentication::getPasswords()
{
	// network-manager-pptp will fail hard if "CHAP" is not the
	// first element in the username&password list.
	TDENetworkSettingsMap pwds;
	//pwds.insert("CHAP", "CHAP");
	pwds.insert("user", TQString(_pptpAuth->username->text()));
	pwds.insert("password", TQString(_pptpAuth->password->password()));
	pwds.insert("domain", TQString(_pptpAuth->domain->text()));
	return pwds;
}

void PPTPAuthentication::setPasswords(TDENetworkSettingsMap secrets) {
	if (secrets.contains("password")) {
		_pptpAuth->password->erase();
		_pptpAuth->password->insert(secrets["password"]);
	}
}

#include "tdenetman-pptp.moc"