X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fcore.cpp;h=11563fd5f59ec423e505b99854538b716fb40890;hp=a59d8972ffe0dfc1d47088840564d093dfc119d0;hb=c0d6dc0dec628f2e143e37ecc95cec45e636f8a5;hpb=c1cf157116de7fc3da96203aa6f03c38c7ebb650 diff --git a/src/core/core.cpp b/src/core/core.cpp index a59d8972..11563fd5 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2018 by the Quassel Project * + * Copyright (C) 2005-2020 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -28,7 +28,6 @@ #include "coresession.h" #include "coresettings.h" #include "internalpeer.h" -#include "logmessage.h" #include "network.h" #include "postgresqlstorage.h" #include "quassel.h" @@ -185,10 +184,12 @@ void Core::init() throw ExitException{EXIT_FAILURE, tr("Cannot write quasselcore configuration; probably a permission problem.")}; } - quInfo() << "Core is currently not configured! Please connect with a Quassel Client for basic setup."; + qInfo() << "Core is currently not configured! Please connect with a Quassel Client for basic setup."; } } - else { + + // This checks separately because config-from-environment might have only configured the core just now + if (_configured) { if (Quassel::isOptionSet("add-user")) { bool success = createUser(); throw ExitException{success ? EXIT_SUCCESS : EXIT_FAILURE}; @@ -212,6 +213,12 @@ void Core::init() _identServer = new IdentServer(this); } + if (Quassel::isOptionSet("metrics-daemon")) { + _metricsServer = new MetricsServer(this); + _server.setMetricsServer(_metricsServer); + _v6server.setMetricsServer(_metricsServer); + } + Quassel::registerReloadHandler([]() { // Currently, only reloading SSL certificates and the sysident cache is supported if (Core::instance()) { @@ -257,7 +264,7 @@ void Core::initAsync() void Core::shutdown() { - quInfo() << "Core shutting down..."; + qInfo() << "Core shutting down..."; saveState(); @@ -281,7 +288,7 @@ void Core::onSessionShutdown(SessionThread* session) { _sessions.take(_sessions.key(session))->deleteLater(); if (_sessions.isEmpty()) { - quInfo() << "Core shutdown complete!"; + qInfo() << "Core shutdown complete!"; emit shutdownComplete(); } } @@ -293,7 +300,7 @@ void Core::saveState() if (_storage) { QVariantList activeSessions; for (auto&& user : instance()->_sessions.keys()) - activeSessions << QVariant::fromValue(user); + activeSessions << QVariant::fromValue(user); _storage->setCoreState(activeSessions); } } @@ -301,11 +308,11 @@ void Core::saveState() void Core::restoreState() { if (!_configured) { - quWarning() << qPrintable(tr("Cannot restore a state for an unconfigured core!")); + qWarning() << qPrintable(tr("Cannot restore a state for an unconfigured core!")); return; } if (_sessions.count()) { - quWarning() << qPrintable(tr("Calling restoreState() even though active sessions exist!")); + qWarning() << qPrintable(tr("Calling restoreState() even though active sessions exist!")); return; } @@ -313,7 +320,7 @@ void Core::restoreState() /* We don't check, since we are at the first version since switching to Git uint statever = s.coreState().toMap()["CoreStateVersion"].toUInt(); if(statever < 1) { - quWarning() << qPrintable(tr("Core state too old, ignoring...")); + qWarning() << qPrintable(tr("Core state too old, ignoring...")); return; } */ @@ -322,7 +329,7 @@ void Core::restoreState() QVariantList activeSessions = instance()->_storage->getCoreState(activeSessionsFallback); if (activeSessions.count() > 0) { - quInfo() << "Restoring previous core state..."; + qInfo() << "Restoring previous core state..."; for (auto&& v : activeSessions) { UserId user = v.value(); sessionForUser(user, true); @@ -360,7 +367,7 @@ QString Core::setupCore(const QString& adminUser, return tr("Could not setup storage!"); } - quInfo() << "Selected authenticator:" << authenticator; + qInfo() << "Selected authenticator:" << authenticator; if (!(_configured = initAuthenticator(authenticator, authSetupData, {}, false, true))) { return tr("Could not setup authenticator!"); } @@ -376,7 +383,7 @@ QString Core::setupCore(const QString& adminUser, } saveAuthenticatorSettings(authenticator, authSetupData); - quInfo() << qPrintable(tr("Creating admin user...")); + qInfo() << qPrintable(tr("Creating admin user...")); _storage->addUser(adminUser, adminPassword); cacheSysIdent(); startListening(); // TODO check when we need this @@ -430,7 +437,7 @@ bool Core::initStorage( const QString& backend, const QVariantMap& settings, const QProcessEnvironment& environment, bool loadFromEnvironment, bool setup) { if (backend.isEmpty()) { - quWarning() << "No storage backend selected!"; + qWarning() << "No storage backend selected!"; return false; } @@ -525,7 +532,7 @@ bool Core::initAuthenticator( const QString& backend, const QVariantMap& settings, const QProcessEnvironment& environment, bool loadFromEnvironment, bool setup) { if (backend.isEmpty()) { - quWarning() << "No authenticator selected!"; + qWarning() << "No authenticator selected!"; return false; } @@ -565,28 +572,15 @@ bool Core::initAuthenticator( bool Core::sslSupported() { -#ifdef HAVE_SSL - auto* sslServer = qobject_cast(&instance()->_server); - return sslServer && sslServer->isCertValid(); -#else - return false; -#endif + return instance()->_server.isCertValid() && instance()->_v6server.isCertValid(); } bool Core::reloadCerts() { -#ifdef HAVE_SSL - auto* sslServerv4 = qobject_cast(&_server); - bool retv4 = sslServerv4->reloadCerts(); - - auto* sslServerv6 = qobject_cast(&_v6server); - bool retv6 = sslServerv6->reloadCerts(); + bool retv4 = _server.reloadCerts(); + bool retv6 = _v6server.reloadCerts(); return retv4 && retv6; -#else - // SSL not supported, don't mark configuration reload as failed - return true; -#endif } void Core::cacheSysIdent() @@ -636,29 +630,27 @@ bool Core::startListening() switch (addr.protocol()) { case QAbstractSocket::IPv6Protocol: if (_v6server.listen(addr, port)) { - quInfo() << qPrintable(tr("Listening for GUI clients on IPv6 %1 port %2 using protocol version %3") - .arg(addr.toString()) - .arg(_v6server.serverPort()) - .arg(Quassel::buildInfo().protocolVersion)); + qInfo() << qPrintable(tr("Listening for GUI clients on IPv6 %1 port %2 using protocol version %3") + .arg(addr.toString()) + .arg(_v6server.serverPort()) + .arg(Quassel::buildInfo().protocolVersion)); success = true; } else - quWarning() << qPrintable( - tr("Could not open IPv6 interface %1:%2: %3").arg(addr.toString()).arg(port).arg(_v6server.errorString())); + qWarning() << qPrintable(tr("Could not open IPv6 interface %1:%2: %3").arg(addr.toString()).arg(port).arg(_v6server.errorString())); break; case QAbstractSocket::IPv4Protocol: if (_server.listen(addr, port)) { - quInfo() << qPrintable(tr("Listening for GUI clients on IPv4 %1 port %2 using protocol version %3") - .arg(addr.toString()) - .arg(_server.serverPort()) - .arg(Quassel::buildInfo().protocolVersion)); + qInfo() << qPrintable(tr("Listening for GUI clients on IPv4 %1 port %2 using protocol version %3") + .arg(addr.toString()) + .arg(_server.serverPort()) + .arg(Quassel::buildInfo().protocolVersion)); success = true; } else { // if v6 succeeded on Any, the port will be already in use - don't display the error then if (!success || _server.serverError() != QAbstractSocket::AddressInUseError) - quWarning() << qPrintable( - tr("Could not open IPv4 interface %1:%2: %3").arg(addr.toString()).arg(port).arg(_server.errorString())); + qWarning() << qPrintable(tr("Could not open IPv4 interface %1:%2: %3").arg(addr.toString()).arg(port).arg(_server.errorString())); } break; default: @@ -669,12 +661,16 @@ bool Core::startListening() } } if (!success) - quError() << qPrintable(tr("Could not open any network interfaces to listen on!")); + qCritical() << qPrintable(tr("Could not open any network interfaces to listen on!")); if (_identServer) { _identServer->startListening(); } + if (_metricsServer) { + _metricsServer->startListening(); + } + return success; } @@ -684,6 +680,10 @@ void Core::stopListening(const QString& reason) _identServer->stopListening(reason); } + if (_metricsServer) { + _metricsServer->stopListening(reason); + } + bool wasListening = false; if (_server.isListening()) { wasListening = true; @@ -695,18 +695,19 @@ void Core::stopListening(const QString& reason) } if (wasListening) { if (reason.isEmpty()) - quInfo() << "No longer listening for GUI clients."; + qInfo() << "No longer listening for GUI clients."; else - quInfo() << qPrintable(reason); + qInfo() << qPrintable(reason); } } void Core::incomingConnection() { - auto* server = qobject_cast(sender()); + auto* server = qobject_cast(sender()); Q_ASSERT(server); while (server->hasPendingConnections()) { - QTcpSocket* socket = server->nextPendingConnection(); + auto socket = qobject_cast(server->nextPendingConnection()); + Q_ASSERT(socket); auto* handler = new CoreAuthHandler(socket, this); _connectingClients.insert(handler); @@ -715,7 +716,7 @@ void Core::incomingConnection() connect(handler, &AuthHandler::socketError, this, &Core::socketError); connect(handler, &CoreAuthHandler::handshakeComplete, this, &Core::setupClientSession); - quInfo() << qPrintable(tr("Client connected from")) << qPrintable(socket->peerAddress().toString()); + qInfo() << qPrintable(tr("Client connected from")) << qPrintable(handler->hostAddress().toString()); if (!_configured) { stopListening(tr("Closing server for basic setup.")); @@ -729,7 +730,7 @@ void Core::clientDisconnected() auto* handler = qobject_cast(sender()); Q_ASSERT(handler); - quInfo() << qPrintable(tr("Non-authed client disconnected:")) << qPrintable(handler->socket()->peerAddress().toString()); + qInfo() << qPrintable(tr("Non-authed client disconnected:")) << qPrintable(handler->hostAddress().toString()); _connectingClients.remove(handler); handler->deleteLater(); @@ -802,13 +803,13 @@ void Core::setupInternalClientSession(QPointer clientPeer) uid = _storage->internalUser(); } else { - quWarning() << "Core::setupInternalClientSession(): You're trying to run monolithic Quassel with an unusable Backend! Go fix it!"; + qWarning() << "Core::setupInternalClientSession(): You're trying to run monolithic Quassel with an unusable Backend! Go fix it!"; emit exitRequested(EXIT_FAILURE, tr("Cannot setup storage backend.")); return; } if (!clientPeer) { - quWarning() << "Client peer went away, not starting a session"; + qWarning() << "Client peer went away, not starting a session"; return; } @@ -831,7 +832,7 @@ SessionThread* Core::sessionForUser(UserId uid, bool restore) void Core::socketError(QAbstractSocket::SocketError err, const QString& errorString) { - quWarning() << QString("Socket error %1: %2").arg(err).arg(errorString); + qWarning() << QString("Socket error %1: %2").arg(err).arg(errorString); } QVariantList Core::backendInfo() @@ -892,8 +893,8 @@ bool Core::selectBackend(const QString& backend) _registeredStorageBackends.end(), std::back_inserter(backends), [](const DeferredSharedPtr& backend) { return backend->displayName(); }); - quWarning() << qPrintable(tr("Unsupported storage backend: %1").arg(backend)); - quWarning() << qPrintable(tr("Supported backends are:")) << qPrintable(backends.join(", ")); + qWarning() << qPrintable(tr("Unsupported storage backend: %1").arg(backend)); + qWarning() << qPrintable(tr("Supported backends are:")) << qPrintable(backends.join(", ")); return false; } @@ -905,27 +906,27 @@ bool Core::selectBackend(const QString& backend) if (!saveBackendSettings(backend, settings)) { qCritical() << qPrintable(QString("Could not save backend settings, probably a permission problem.")); } - quWarning() << qPrintable(tr("Switched storage backend to: %1").arg(backend)); - quWarning() << qPrintable(tr("Backend already initialized. Skipping Migration...")); + qWarning() << qPrintable(tr("Switched storage backend to: %1").arg(backend)); + qWarning() << qPrintable(tr("Backend already initialized. Skipping Migration...")); return true; case Storage::NotAvailable: qCritical() << qPrintable(tr("Storage backend is not available: %1").arg(backend)); return false; case Storage::NeedsSetup: if (!storage->setup(settings)) { - quWarning() << qPrintable(tr("Unable to setup storage backend: %1").arg(backend)); + qWarning() << qPrintable(tr("Unable to setup storage backend: %1").arg(backend)); return false; } if (storage->init(settings) != Storage::IsReady) { - quWarning() << qPrintable(tr("Unable to initialize storage backend: %1").arg(backend)); + qWarning() << qPrintable(tr("Unable to initialize storage backend: %1").arg(backend)); return false; } if (!saveBackendSettings(backend, settings)) { qCritical() << qPrintable(QString("Could not save backend settings, probably a permission problem.")); } - quWarning() << qPrintable(tr("Switched storage backend to: %1").arg(backend)); + qWarning() << qPrintable(tr("Switched storage backend to: %1").arg(backend)); break; } @@ -945,19 +946,19 @@ bool Core::selectBackend(const QString& backend) } return true; } - quWarning() << qPrintable(tr("Unable to migrate storage backend! (No migration writer for %1)").arg(backend)); + qWarning() << qPrintable(tr("Unable to migrate storage backend! (No migration writer for %1)").arg(backend)); return false; } // inform the user why we cannot merge if (!_storage) { - quWarning() << qPrintable(tr("No currently active storage backend. Skipping migration...")); + qWarning() << qPrintable(tr("No currently active storage backend. Skipping migration...")); } else if (!reader) { - quWarning() << qPrintable(tr("Currently active storage backend does not support migration: %1").arg(_storage->displayName())); + qWarning() << qPrintable(tr("Currently active storage backend does not support migration: %1").arg(_storage->displayName())); } if (writer) { - quWarning() << qPrintable(tr("New storage backend does not support migration: %1").arg(backend)); + qWarning() << qPrintable(tr("New storage backend does not support migration: %1").arg(backend)); } // so we were unable to merge, but let's create a user \o/ @@ -979,8 +980,8 @@ bool Core::selectAuthenticator(const QString& backend) _registeredAuthenticators.end(), std::back_inserter(authenticators), [](const DeferredSharedPtr& authenticator) { return authenticator->displayName(); }); - quWarning() << qPrintable(tr("Unsupported authenticator: %1").arg(backend)); - quWarning() << qPrintable(tr("Supported authenticators are:")) << qPrintable(authenticators.join(", ")); + qWarning() << qPrintable(tr("Unsupported authenticator: %1").arg(backend)); + qWarning() << qPrintable(tr("Supported authenticators are:")) << qPrintable(authenticators.join(", ")); return false; } @@ -990,24 +991,24 @@ bool Core::selectAuthenticator(const QString& backend) switch (state) { case Authenticator::IsReady: saveAuthenticatorSettings(backend, settings); - quWarning() << qPrintable(tr("Switched authenticator to: %1").arg(backend)); + qWarning() << qPrintable(tr("Switched authenticator to: %1").arg(backend)); return true; case Authenticator::NotAvailable: qCritical() << qPrintable(tr("Authenticator is not available: %1").arg(backend)); return false; case Authenticator::NeedsSetup: if (!auther->setup(settings)) { - quWarning() << qPrintable(tr("Unable to setup authenticator: %1").arg(backend)); + qWarning() << qPrintable(tr("Unable to setup authenticator: %1").arg(backend)); return false; } if (auther->init(settings) != Authenticator::IsReady) { - quWarning() << qPrintable(tr("Unable to initialize authenticator: %1").arg(backend)); + qWarning() << qPrintable(tr("Unable to initialize authenticator: %1").arg(backend)); return false; } saveAuthenticatorSettings(backend, settings); - quWarning() << qPrintable(tr("Switched authenticator to: %1").arg(backend)); + qWarning() << qPrintable(tr("Switched authenticator to: %1").arg(backend)); } _authenticator = std::move(auther); @@ -1035,11 +1036,11 @@ bool Core::createUser() enableStdInEcho(); if (password != password2) { - quWarning() << "Passwords don't match!"; + qWarning() << "Passwords don't match!"; return false; } if (password.isEmpty()) { - quWarning() << "Password is empty!"; + qWarning() << "Password is empty!"; return false; } @@ -1048,7 +1049,7 @@ bool Core::createUser() return true; } else { - quWarning() << "Unable to add user:" << qPrintable(username); + qWarning() << "Unable to add user:" << qPrintable(username); return false; } } @@ -1082,11 +1083,11 @@ bool Core::changeUserPass(const QString& username) enableStdInEcho(); if (password != password2) { - quWarning() << "Passwords don't match!"; + qWarning() << "Passwords don't match!"; return false; } if (password.isEmpty()) { - quWarning() << "Password is empty!"; + qWarning() << "Password is empty!"; return false; } @@ -1095,7 +1096,7 @@ bool Core::changeUserPass(const QString& username) return true; } else { - quWarning() << "Failed to change password!"; + qWarning() << "Failed to change password!"; return false; } }