- reply["Configured"] = false;
- QList<QVariant> backends;
- foreach(Storage *backend, _storageBackends.values()) {
- QVariantMap v;
- v["DisplayName"] = backend->displayName();
- v["Description"] = backend->description();
- v["SetupKeys"] = backend->setupKeys();
- v["SetupDefaults"] = backend->setupDefaults();
- backends.append(v);
- }
- reply["StorageBackends"] = backends;
- reply["LoginEnabled"] = false;
- }
- else {
- reply["Configured"] = true;
- }
- clientInfo[socket] = msg; // store for future reference
- reply["MsgType"] = "ClientInitAck";
- SignalProxy::writeDataToDevice(socket, reply);
- socket->flush(); // ensure that the write cache is flushed before we switch to ssl
-
-#ifdef HAVE_SSL
- // after we told the client that we are ssl capable we switch to ssl mode
- if (supportSsl && msg["UseSsl"].toBool()) {
- qDebug() << qPrintable(tr("Starting TLS for Client:")) << qPrintable(socket->peerAddress().toString());
- connect(sslSocket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(sslErrors(const QList<QSslError> &)));
- sslSocket->startServerEncryption();
- }
-#endif
-
-#ifndef QT_NO_COMPRESS
- if (supportsCompression && msg["UseCompression"].toBool()) {
- socket->setProperty("UseCompression", true);
- qDebug() << "Using compression for Client:" << qPrintable(socket->peerAddress().toString());
- }
-#endif
- }
- else {
- // for the rest, we need an initialized connection
- if (!clientInfo.contains(socket)) {
- QVariantMap reply;
- reply["MsgType"] = "ClientLoginReject";
- reply["Error"] = tr("<b>Client not initialized!</b><br>You need to send an init message before trying to login.");
- SignalProxy::writeDataToDevice(socket, reply);
- qWarning() << qPrintable(tr("Client")) << qPrintable(socket->peerAddress().toString()) << qPrintable(tr("did not send an init message before trying to login, rejecting."));
- socket->close(); return;
- }
- if (msg["MsgType"] == "CoreSetupData") {
- QVariantMap reply;
- QString result = setupCore(msg["SetupData"].toMap());
- if (!result.isEmpty()) {
- reply["MsgType"] = "CoreSetupReject";
- reply["Error"] = result;
- }
- else {
- reply["MsgType"] = "CoreSetupAck";
- }
- SignalProxy::writeDataToDevice(socket, reply);
- }
- else if (msg["MsgType"] == "ClientLogin") {
- QVariantMap reply;
- UserId uid = _storage->validateUser(msg["User"].toString(), msg["Password"].toString());
- if (uid == 0) {
- reply["MsgType"] = "ClientLoginReject";
- reply["Error"] = tr("<b>Invalid username or password!</b><br>The username/password combination you supplied could not be found in the database.");
- SignalProxy::writeDataToDevice(socket, reply);
- return;
- }
- reply["MsgType"] = "ClientLoginAck";
- SignalProxy::writeDataToDevice(socket, reply);
- quInfo() << qPrintable(tr("Client")) << qPrintable(socket->peerAddress().toString()) << qPrintable(tr("initialized and authenticated successfully as \"%1\" (UserId: %2).").arg(msg["User"].toString()).arg(uid.toInt()));
- setupClientSession(socket, uid);