mirror of https://github.com/nymea/nymea.git
Merge PR #537: Fix additional interface command line parameter
commit
2098203f73
|
|
@ -521,16 +521,11 @@ QHash<QString, JsonHandler *> JsonRPCServerImplementation::handlers() const
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Register a new \l{TransportInterface} to the JSON server. If the given interface is already registered, just the authenticationRequired flag will be updated. */
|
/*! Register a new \l{TransportInterface} to the JSON server. If the given interface is already registered, just the authenticationRequired flag will be updated. */
|
||||||
void JsonRPCServerImplementation::registerTransportInterface(TransportInterface *interface, bool authenticationRequired)
|
void JsonRPCServerImplementation::registerTransportInterface(TransportInterface *interface)
|
||||||
{
|
{
|
||||||
if (!m_interfaces.contains(interface)) {
|
connect(interface, &TransportInterface::clientConnected, this, &JsonRPCServerImplementation::clientConnected);
|
||||||
connect(interface, &TransportInterface::clientConnected, this, &JsonRPCServerImplementation::clientConnected);
|
connect(interface, &TransportInterface::clientDisconnected, this, &JsonRPCServerImplementation::clientDisconnected);
|
||||||
connect(interface, &TransportInterface::clientDisconnected, this, &JsonRPCServerImplementation::clientDisconnected);
|
connect(interface, &TransportInterface::dataAvailable, this, &JsonRPCServerImplementation::processData);
|
||||||
connect(interface, &TransportInterface::dataAvailable, this, &JsonRPCServerImplementation::processData);
|
|
||||||
m_interfaces.insert(interface, authenticationRequired);
|
|
||||||
} else {
|
|
||||||
m_interfaces[interface] = authenticationRequired;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonRPCServerImplementation::unregisterTransportInterface(TransportInterface *interface)
|
void JsonRPCServerImplementation::unregisterTransportInterface(TransportInterface *interface)
|
||||||
|
|
@ -542,7 +537,6 @@ void JsonRPCServerImplementation::unregisterTransportInterface(TransportInterfac
|
||||||
interface->terminateClientConnection(clientId);
|
interface->terminateClientConnection(clientId);
|
||||||
clientDisconnected(clientId);
|
clientDisconnected(clientId);
|
||||||
}
|
}
|
||||||
m_interfaces.take(interface);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JsonRPCServerImplementation::registerExperienceHandler(JsonHandler *handler, int majorVersion, int minorVersion)
|
bool JsonRPCServerImplementation::registerExperienceHandler(JsonHandler *handler, int majorVersion, int minorVersion)
|
||||||
|
|
@ -678,7 +672,7 @@ void JsonRPCServerImplementation::processJsonPacket(TransportInterface *interfac
|
||||||
QString method = commandList.last();
|
QString method = commandList.last();
|
||||||
|
|
||||||
// check if authentication is required for this transport
|
// check if authentication is required for this transport
|
||||||
if (m_interfaces.value(interface)) {
|
if (interface->configuration().authenticationEnabled) {
|
||||||
QByteArray token = message.value("token").toByteArray();
|
QByteArray token = message.value("token").toByteArray();
|
||||||
QStringList authExemptMethodsNoUser = {"JSONRPC.Introspect", "JSONRPC.Hello", "JSONRPC.RequestPushButtonAuth", "JSONRPC.CreateUser"};
|
QStringList authExemptMethodsNoUser = {"JSONRPC.Introspect", "JSONRPC.Hello", "JSONRPC.RequestPushButtonAuth", "JSONRPC.CreateUser"};
|
||||||
QStringList authExemptMethodsWithUser = {"JSONRPC.Introspect", "JSONRPC.Hello", "JSONRPC.Authenticate", "JSONRPC.RequestPushButtonAuth"};
|
QStringList authExemptMethodsWithUser = {"JSONRPC.Introspect", "JSONRPC.Hello", "JSONRPC.Authenticate", "JSONRPC.RequestPushButtonAuth"};
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ signals:
|
||||||
|
|
||||||
// Server API
|
// Server API
|
||||||
public:
|
public:
|
||||||
void registerTransportInterface(TransportInterface *interface, bool authenticationRequired);
|
void registerTransportInterface(TransportInterface *interface);
|
||||||
void unregisterTransportInterface(TransportInterface *interface);
|
void unregisterTransportInterface(TransportInterface *interface);
|
||||||
|
|
||||||
bool registerHandler(JsonHandler *handler) override;
|
bool registerHandler(JsonHandler *handler) override;
|
||||||
|
|
@ -111,7 +111,6 @@ private slots:
|
||||||
private:
|
private:
|
||||||
QVariantMap m_api;
|
QVariantMap m_api;
|
||||||
QHash<JsonHandler*, QString> m_experiences;
|
QHash<JsonHandler*, QString> m_experiences;
|
||||||
QMap<TransportInterface*, bool> m_interfaces; // Interface, authenticationRequired
|
|
||||||
QHash<QString, JsonHandler *> m_handlers;
|
QHash<QString, JsonHandler *> m_handlers;
|
||||||
QHash<JsonReply *, TransportInterface *> m_asyncReplies;
|
QHash<JsonReply *, TransportInterface *> m_asyncReplies;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,7 @@ void NymeaCore::init(const QStringList &additionalInterfaces) {
|
||||||
m_thingManager->registerStaticPlugin(cloudNotifications);
|
m_thingManager->registerStaticPlugin(cloudNotifications);
|
||||||
|
|
||||||
CloudTransport *cloudTransport = m_cloudManager->createTransportInterface();
|
CloudTransport *cloudTransport = m_cloudManager->createTransportInterface();
|
||||||
m_serverManager->jsonServer()->registerTransportInterface(cloudTransport, false);
|
m_serverManager->jsonServer()->registerTransportInterface(cloudTransport);
|
||||||
|
|
||||||
connect(m_configuration, &NymeaConfiguration::serverNameChanged, m_serverManager, &ServerManager::setServerName);
|
connect(m_configuration, &NymeaConfiguration::serverNameChanged, m_serverManager, &ServerManager::setServerName);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ ServerManager::ServerManager(Platform *platform, NymeaConfiguration *configurati
|
||||||
|
|
||||||
// Transports
|
// Transports
|
||||||
MockTcpServer *tcpServer = new MockTcpServer(this);
|
MockTcpServer *tcpServer = new MockTcpServer(this);
|
||||||
m_jsonServer->registerTransportInterface(tcpServer, true);
|
m_jsonServer->registerTransportInterface(tcpServer);
|
||||||
tcpServer->startServer();
|
tcpServer->startServer();
|
||||||
|
|
||||||
foreach (const QString &interfaceString, additionalInterfaces) {
|
foreach (const QString &interfaceString, additionalInterfaces) {
|
||||||
|
|
@ -125,15 +125,20 @@ ServerManager::ServerManager(Platform *platform, NymeaConfiguration *configurati
|
||||||
config.port = additionalInterface.port();
|
config.port = additionalInterface.port();
|
||||||
TransportInterface *server = nullptr;
|
TransportInterface *server = nullptr;
|
||||||
QString serverType, serviceType;
|
QString serverType, serviceType;
|
||||||
|
qCInfo(dcServerManager) << "Enabling additional interface" << additionalInterface;
|
||||||
if (additionalInterface.scheme().startsWith("nymea")) {
|
if (additionalInterface.scheme().startsWith("nymea")) {
|
||||||
config.sslEnabled = additionalInterface.scheme().startsWith("nymeas");
|
config.sslEnabled = additionalInterface.scheme().startsWith("nymeas");
|
||||||
|
config.authenticationEnabled = false;
|
||||||
server = new TcpServer(config, m_sslConfiguration, this);
|
server = new TcpServer(config, m_sslConfiguration, this);
|
||||||
|
m_jsonServer->registerTransportInterface(server);
|
||||||
m_tcpServers.insert(config.id, qobject_cast<TcpServer*>(server));
|
m_tcpServers.insert(config.id, qobject_cast<TcpServer*>(server));
|
||||||
serverType = "tcp";
|
serverType = "tcp";
|
||||||
serviceType = "_jsonrpc._tcp";
|
serviceType = "_jsonrpc._tcp";
|
||||||
} else if (additionalInterface.scheme().startsWith("ws")) {
|
} else if (additionalInterface.scheme().startsWith("ws")) {
|
||||||
config.sslEnabled = additionalInterface.scheme().startsWith("wss");
|
config.sslEnabled = additionalInterface.scheme().startsWith("wss");
|
||||||
|
config.authenticationEnabled = false;
|
||||||
server = new WebSocketServer(config, m_sslConfiguration, this);
|
server = new WebSocketServer(config, m_sslConfiguration, this);
|
||||||
|
m_jsonServer->registerTransportInterface(server);
|
||||||
m_webSocketServers.insert(config.id, qobject_cast<WebSocketServer*>(server));
|
m_webSocketServers.insert(config.id, qobject_cast<WebSocketServer*>(server));
|
||||||
serverType = "ws";
|
serverType = "ws";
|
||||||
serviceType = "_ws._tcp";
|
serviceType = "_ws._tcp";
|
||||||
|
|
@ -145,7 +150,7 @@ ServerManager::ServerManager(Platform *platform, NymeaConfiguration *configurati
|
||||||
|
|
||||||
foreach (const ServerConfiguration &config, configuration->tcpServerConfigurations()) {
|
foreach (const ServerConfiguration &config, configuration->tcpServerConfigurations()) {
|
||||||
TcpServer *tcpServer = new TcpServer(config, m_sslConfiguration, this);
|
TcpServer *tcpServer = new TcpServer(config, m_sslConfiguration, this);
|
||||||
m_jsonServer->registerTransportInterface(tcpServer, config.authenticationEnabled);
|
m_jsonServer->registerTransportInterface(tcpServer);
|
||||||
m_tcpServers.insert(config.id, tcpServer);
|
m_tcpServers.insert(config.id, tcpServer);
|
||||||
if (tcpServer->startServer()) {
|
if (tcpServer->startServer()) {
|
||||||
registerZeroConfService(config, "tcp", "_jsonrpc._tcp");
|
registerZeroConfService(config, "tcp", "_jsonrpc._tcp");
|
||||||
|
|
@ -154,7 +159,7 @@ ServerManager::ServerManager(Platform *platform, NymeaConfiguration *configurati
|
||||||
|
|
||||||
foreach (const ServerConfiguration &config, configuration->webSocketServerConfigurations()) {
|
foreach (const ServerConfiguration &config, configuration->webSocketServerConfigurations()) {
|
||||||
WebSocketServer *webSocketServer = new WebSocketServer(config, m_sslConfiguration, this);
|
WebSocketServer *webSocketServer = new WebSocketServer(config, m_sslConfiguration, this);
|
||||||
m_jsonServer->registerTransportInterface(webSocketServer, config.authenticationEnabled);
|
m_jsonServer->registerTransportInterface(webSocketServer);
|
||||||
m_webSocketServers.insert(config.id, webSocketServer);
|
m_webSocketServers.insert(config.id, webSocketServer);
|
||||||
if (webSocketServer->startServer()) {
|
if (webSocketServer->startServer()) {
|
||||||
registerZeroConfService(config, "ws", "_ws._tcp");
|
registerZeroConfService(config, "ws", "_ws._tcp");
|
||||||
|
|
@ -162,7 +167,7 @@ ServerManager::ServerManager(Platform *platform, NymeaConfiguration *configurati
|
||||||
}
|
}
|
||||||
|
|
||||||
m_bluetoothServer = new BluetoothServer(this);
|
m_bluetoothServer = new BluetoothServer(this);
|
||||||
m_jsonServer->registerTransportInterface(m_bluetoothServer, true);
|
m_jsonServer->registerTransportInterface(m_bluetoothServer);
|
||||||
if (configuration->bluetoothServerEnabled()) {
|
if (configuration->bluetoothServerEnabled()) {
|
||||||
m_bluetoothServer->startServer();
|
m_bluetoothServer->startServer();
|
||||||
}
|
}
|
||||||
|
|
@ -173,8 +178,7 @@ ServerManager::ServerManager(Platform *platform, NymeaConfiguration *configurati
|
||||||
m_tunnelProxyServers.insert(config.id, tunnelProxyServer);
|
m_tunnelProxyServers.insert(config.id, tunnelProxyServer);
|
||||||
connect(tunnelProxyServer, &TunnelProxyServer::runningChanged, this, [this, tunnelProxyServer](bool running){
|
connect(tunnelProxyServer, &TunnelProxyServer::runningChanged, this, [this, tunnelProxyServer](bool running){
|
||||||
if (running) {
|
if (running) {
|
||||||
// Note: enable authentication in any case, we don't want to expose unprotected access trough the internet
|
m_jsonServer->registerTransportInterface(tunnelProxyServer);
|
||||||
m_jsonServer->registerTransportInterface(tunnelProxyServer, true);
|
|
||||||
} else {
|
} else {
|
||||||
m_jsonServer->unregisterTransportInterface(tunnelProxyServer);
|
m_jsonServer->unregisterTransportInterface(tunnelProxyServer);
|
||||||
}
|
}
|
||||||
|
|
@ -254,7 +258,7 @@ void ServerManager::tcpServerConfigurationChanged(const QString &id)
|
||||||
server = new TcpServer(config, m_sslConfiguration, this);
|
server = new TcpServer(config, m_sslConfiguration, this);
|
||||||
m_tcpServers.insert(config.id, server);
|
m_tcpServers.insert(config.id, server);
|
||||||
}
|
}
|
||||||
m_jsonServer->registerTransportInterface(server, config.authenticationEnabled);
|
m_jsonServer->registerTransportInterface(server);
|
||||||
if (server->startServer()) {
|
if (server->startServer()) {
|
||||||
registerZeroConfService(config, "tcp", "_jsonrpc._tcp");
|
registerZeroConfService(config, "tcp", "_jsonrpc._tcp");
|
||||||
}
|
}
|
||||||
|
|
@ -287,7 +291,7 @@ void ServerManager::webSocketServerConfigurationChanged(const QString &id)
|
||||||
server = new WebSocketServer(config, m_sslConfiguration, this);
|
server = new WebSocketServer(config, m_sslConfiguration, this);
|
||||||
m_webSocketServers.insert(server->configuration().id, server);
|
m_webSocketServers.insert(server->configuration().id, server);
|
||||||
}
|
}
|
||||||
m_jsonServer->registerTransportInterface(server, config.authenticationEnabled);
|
m_jsonServer->registerTransportInterface(server);
|
||||||
if (server->startServer()) {
|
if (server->startServer()) {
|
||||||
registerZeroConfService(config, "ws", "_ws._tcp");
|
registerZeroConfService(config, "ws", "_ws._tcp");
|
||||||
}
|
}
|
||||||
|
|
@ -380,8 +384,7 @@ void ServerManager::tunnelProxyServerConfigurationChanged(const QString &id)
|
||||||
m_tunnelProxyServers.insert(server->configuration().id, server);
|
m_tunnelProxyServers.insert(server->configuration().id, server);
|
||||||
connect(server, &TunnelProxyServer::runningChanged, this, [this, server](bool running){
|
connect(server, &TunnelProxyServer::runningChanged, this, [this, server](bool running){
|
||||||
if (running) {
|
if (running) {
|
||||||
// Note: enable authentication in any case, we don't want to expose unprotected access trough the internet
|
m_jsonServer->registerTransportInterface(server);
|
||||||
m_jsonServer->registerTransportInterface(server, true);
|
|
||||||
} else {
|
} else {
|
||||||
m_jsonServer->unregisterTransportInterface(server);
|
m_jsonServer->unregisterTransportInterface(server);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ int main(int argc, char *argv[])
|
||||||
QCommandLineOption debugOption(QStringList() << "d" << "debug-category", debugDescription, "[No]DebugCategory[Warnings]");
|
QCommandLineOption debugOption(QStringList() << "d" << "debug-category", debugDescription, "[No]DebugCategory[Warnings]");
|
||||||
parser.addOption(debugOption);
|
parser.addOption(debugOption);
|
||||||
|
|
||||||
QCommandLineOption interfacesOption({"i", "interface"}, QCoreApplication::translate("nymea", "Additional interfaces to listen on. In nymea URI format (e.g. nymeas://127.0.0.2:7777)."));
|
QCommandLineOption interfacesOption({"i", "interface"}, QCoreApplication::translate("nymea", "Additional interfaces to listen on. In nymea URI format (e.g. nymeas://127.0.0.2:7777). Note that such interfaces will not require any authentication as they are intended to be used for automated testing only."), "interfaceString");
|
||||||
parser.addOption(interfacesOption);
|
parser.addOption(interfacesOption);
|
||||||
|
|
||||||
parser.process(application);
|
parser.process(application);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue