//.........这里部分代码省略.........
break;
case 1:
data.insert(NM_VPNC_KEY_XAUTH_PASSWORD"-flags", QString::number(NetworkManager::Setting::AgentOwned));
break;
case 2:
data.insert(NM_VPNC_KEY_XAUTH_PASSWORD"-flags", QString::number(NetworkManager::Setting::NotRequired));
break;
}
// group password
if (!decrPlugin->readStringKeyValue(cg,"GroupPwd").isEmpty()) {
secretData.insert(NM_VPNC_KEY_SECRET, decrPlugin->readStringKeyValue(cg,"GroupPwd"));
data.insert(NM_VPNC_KEY_SECRET"-flags", QString::number(NetworkManager::Setting::AgentOwned));
} else if (!decrPlugin->readStringKeyValue(cg,"enc_GroupPwd").isEmpty() && !ciscoDecryptBinary.isEmpty()) {
//Decrypt the password and insert into map
decrPlugin->ciscoDecrypt->setProgram(ciscoDecryptBinary);
decrPlugin->ciscoDecrypt->start();
decrPlugin->ciscoDecrypt->waitForStarted();
decrPlugin->ciscoDecrypt->write(decrPlugin->readStringKeyValue(cg,"enc_GroupPwd").toUtf8());
if (decrPlugin->ciscoDecrypt->waitForFinished()) {
secretData.insert(NM_VPNC_KEY_SECRET, decrPlugin->decryptedPasswd);
data.insert(NM_VPNC_KEY_SECRET"-flags", QString::number(NetworkManager::Setting::AgentOwned));
}
}
// Auth Type
if (!cg.readEntry("AuthType").isEmpty() && cg.readEntry("AuthType").toInt() == 5) {
data.insert(NM_VPNC_KEY_AUTHMODE, QLatin1String("hybrid"));
}
// Optional settings
// username
if (!decrPlugin->readStringKeyValue(cg,"Username").isEmpty()) {
data.insert(NM_VPNC_KEY_XAUTH_USER, decrPlugin->readStringKeyValue(cg,"Username"));
}
// domain
if (!decrPlugin->readStringKeyValue(cg,"NTDomain").isEmpty()) {
data.insert(NM_VPNC_KEY_DOMAIN, decrPlugin->readStringKeyValue(cg,"NTDomain"));
}
// encryption
if (!cg.readEntry("SingleDES").isEmpty() && cg.readEntry("SingleDES").toInt() != 0) {
data.insert(NM_VPNC_KEY_SINGLE_DES, QLatin1String("yes"));
}
/* Disable all NAT Traversal if explicit EnableNat=0 exists, otherwise
* default to NAT-T which is newer and standardized. If EnableNat=1, then
* use Cisco-UDP like always; but if the key "X-NM-Use-NAT-T" is set, then
* use NAT-T. If the key "X-NM-Force-NAT-T" is set then force NAT-T always
* on. See vpnc documentation for more information on what the different
* NAT modes are.
*/
// enable NAT
if (cg.readEntry("EnableNat").toInt() == 1) {
data.insert(NM_VPNC_KEY_NAT_TRAVERSAL_MODE, QLatin1String(NM_VPNC_NATT_MODE_CISCO));
// NAT traversal
if (!cg.readEntry("X-NM-Use-NAT-T").isEmpty()) {
if (cg.readEntry("X-NM-Use-NAT-T").toInt() == 1) {
data.insert(NM_VPNC_KEY_NAT_TRAVERSAL_MODE, QLatin1String(NM_VPNC_NATT_MODE_NATT));
}
if (cg.readEntry("X-NM-Force-NAT-T").toInt() == 1) {
data.insert(NM_VPNC_KEY_NAT_TRAVERSAL_MODE, QLatin1String(NM_VPNC_NATT_MODE_NATT_ALWAYS));
}
}
} else {
data.insert(NM_VPNC_KEY_NAT_TRAVERSAL_MODE, QLatin1String(NM_VPNC_NATT_MODE_NONE));
}
// dead peer detection
data.insert(NM_VPNC_KEY_DPD_IDLE_TIMEOUT, cg.readEntry("PeerTimeout"));
// UseLegacyIKEPort=0 uses dynamic source IKE port instead of 500.
if (cg.readEntry("UseLegacyIKEPort").isEmpty() || cg.readEntry("UseLegacyIKEPort").toInt() != 0) {
data.insert(NM_VPNC_KEY_LOCAL_PORT, QString::number(NM_VPNC_LOCAL_PORT_DEFAULT));
}
// DH Group
data.insert(NM_VPNC_KEY_DHGROUP, decrPlugin->readStringKeyValue(cg,"DHGroup"));
// Tunneling Mode - not supported by vpnc
if (cg.readEntry("TunnelingMode").toInt() == 1) {
KMessageBox::error(0, i18n("The VPN settings file '%1' specifies that VPN traffic should be tunneled through TCP which is currently not supported in the vpnc software.\n\nThe connection can still be created, with TCP tunneling disabled, however it may not work as expected.", fileName), i18n("Not supported"), KMessageBox::Notify);
}
// EnableLocalLAN and X-NM-Routes are to be added to IPv4Setting
if (!cg.readEntry("EnableLocalLAN").isEmpty()) {
ipv4Data.insert("never-default", cg.readEntry("EnableLocalLAN"));
}
if (!decrPlugin->readStringKeyValue(cg,"X-NM-Routes").isEmpty()) {
QList<NetworkManager::IpRoute> list;
Q_FOREACH (const QString &route, decrPlugin->readStringKeyValue(cg,"X-NM-Routes").split(' ')) {
NetworkManager::IpRoute ipRoute;
ipRoute.setIp(QHostAddress(route.split('/').first()));
ipRoute.setPrefixLength(route.split('/').at(1).toInt());
list << ipRoute;
}
QList<QList<uint> > dbusRoutes;
Q_FOREACH (const NetworkManager::IpRoute &route, list) {
QList<uint> dbusRoute;
dbusRoute << htonl(route.ip().toIPv4Address())
<< route.prefixLength()
<< htonl(route.nextHop().toIPv4Address())
<< route.metric();
dbusRoutes << dbusRoute;
}
ipv4Data.insert("routes", QVariant::fromValue(dbusRoutes));
}
开发者ID:KDE,项目名称:plasma-nm,代码行数:101,代码来源:vpnc.cpp
示例8: values
Response::ResponseCode ServerSocketInterface::cmdBanFromServer(const Command_BanFromServer &cmd, ResponseContainer & /*rc*/)
{
if (!sqlInterface->checkSql())
return Response::RespInternalError;
QString userName = QString::fromStdString(cmd.user_name());
QString address = QString::fromStdString(cmd.address());
QString trustedSources = settingsCache->value("server/trusted_sources","127.0.0.1,::1").toString();
int minutes = cmd.minutes();
if (trustedSources.contains(address,Qt::CaseInsensitive))
address = "";
QSqlQuery *query = sqlInterface->prepareQuery("insert into {prefix}_bans (user_name, ip_address, id_admin, time_from, minutes, reason, visible_reason, clientid) values(:user_name, :ip_address, :id_admin, NOW(), :minutes, :reason, :visible_reason, :client_id)");
query->bindValue(":user_name", userName);
query->bindValue(":ip_address", address);
query->bindValue(":id_admin", userInfo->id());
query->bindValue(":minutes", minutes);
query->bindValue(":reason", QString::fromStdString(cmd.reason()));
query->bindValue(":visible_reason", QString::fromStdString(cmd.visible_reason()));
query->bindValue(":client_id", QString::fromStdString(cmd.clientid()));
sqlInterface->execSqlQuery(query);
servatrice->clientsLock.lockForRead();
QList<ServerSocketInterface *> userList = servatrice->getUsersWithAddressAsList(QHostAddress(address));
if (!userName.isEmpty()) {
ServerSocketInterface *user = static_cast<ServerSocketInterface *>(server->getUsers().value(userName));
userList.append(user);
}
if (userName.isEmpty() && address.isEmpty()) {
QSqlQuery *query = sqlInterface->prepareQuery("select name from {prefix}_users where clientid = :client_id");
query->bindValue(":client_id", QString::fromStdString(cmd.clientid()));
sqlInterface->execSqlQuery(query);
if (!sqlInterface->execSqlQuery(query)){
qDebug("ClientID username ban lookup failed: SQL Error");
} else {
while (query->next()) {
userName = query->value(0).toString();
ServerSocketInterface *user = static_cast<ServerSocketInterface *>(server->getUsers().value(userName));
if (user && !userList.contains(user))
userList.append(user);
}
}
}
if (!userList.isEmpty()) {
Event_ConnectionClosed event;
event.set_reason(Event_ConnectionClosed::BANNED);
if (cmd.has_visible_reason())
event.set_reason_str(cmd.visible_reason());
if (minutes)
event.set_end_time(QDateTime::currentDateTime().addSecs(60 * minutes).toTime_t());
for (int i = 0; i < userList.size(); ++i) {
SessionEvent *se = userList[i]->prepareSessionEvent(event);
userList[i]->sendProtocolItem(*se);
delete se;
QMetaObject::invokeMethod(userList[i], "prepareDestroy", Qt::QueuedConnection);
}
}
servatrice->clientsLock.unlock();
return Response::RespOk;
}
Client::Client(QWidget *parent) : QDialog(parent)
{
hostLabel = new QLabel(tr("&Server name:"));
portLabel = new QLabel(tr("S&erver port:"));
// find out which IP to connect to
QString ipAddress;
QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
// use the first non-localhost IPv4 address
for (int i = 0; i < ipAddressesList.size(); ++i) {
if (ipAddressesList.at(i) != QHostAddress::LocalHost &&
ipAddressesList.at(i).toIPv4Address()) {
ipAddress = ipAddressesList.at(i).toString();
break;
}
}
// if we did not find one, use IPv4 localhost
if (ipAddress.isEmpty())
ipAddress = QHostAddress(QHostAddress::LocalHost).toString();
hostLineEdit = new QLineEdit(ipAddress);
portLineEdit = new QLineEdit;
portLineEdit->setValidator(new QIntValidator(1, 65535, this));
hostLabel->setBuddy(hostLineEdit);
portLabel->setBuddy(portLineEdit);
statusLabel = new QLabel(tr("This examples requires that you run the "
"Secure Fortune Server example as well."));
getFortuneButton = new QPushButton(tr("Get Fortune"));
getFortuneButton->setDefault(true);
getFortuneButton->setEnabled(false);
quitButton = new QPushButton(tr("Quit"));
buttonBox = new QDialogButtonBox;
buttonBox->addButton(getFortuneButton, QDialogButtonBox::ActionRole);
buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
secureSocket = new QSslSocket(this);
// special slot to handle errors with the certificates
// in particular the fact that they are self-signed
connect(secureSocket, SIGNAL(sslErrors(QList<QSslError>)), this,
SLOT(handleSSLError(QList<QSslError>)));
connect(hostLineEdit, SIGNAL(textChanged(QString)),
this, SLOT(enableGetFortuneButton()));
connect(portLineEdit, SIGNAL(textChanged(QString)),
this, SLOT(enableGetFortuneButton()));
connect(getFortuneButton, SIGNAL(clicked()),
this, SLOT(requestNewFortune()));
connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
connect(secureSocket, SIGNAL(readyRead()), this, SLOT(readFortune()));
connect(secureSocket, SIGNAL(error(QAbstractSocket::SocketError)),
this, SLOT(displayError(QAbstractSocket::SocketError)));
QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(hostLabel, 0, 0);
mainLayout->addWidget(hostLineEdit, 0, 1);
mainLayout->addWidget(portLabel, 1, 0);
mainLayout->addWidget(portLineEdit, 1, 1);
mainLayout->addWidget(statusLabel, 2, 0, 1, 2);
mainLayout->addWidget(buttonBox, 3, 0, 1, 2);
setLayout(mainLayout);
setWindowTitle(tr("Secure Fortune Client"));
portLineEdit->setFocus();
}
请发表评论