Update configurations and add monitor socket
This commit is contained in:
parent
f0599d59eb
commit
481cddb869
@ -59,7 +59,7 @@ void Engine::start(ProxyConfiguration *configuration)
|
|||||||
qCDebug(dcEngine()) << "Starting proxy server";
|
qCDebug(dcEngine()) << "Starting proxy server";
|
||||||
m_proxyServer->startServer();
|
m_proxyServer->startServer();
|
||||||
|
|
||||||
m_monitorServer = new MonitorServer("/tmp/nymea-remoteproxy-monitor.socket", this);
|
m_monitorServer = new MonitorServer(configuration->monitorSocketFileName(), this);
|
||||||
m_monitorServer->startServer();
|
m_monitorServer->startServer();
|
||||||
|
|
||||||
// Set tunning true in the next event loop
|
// Set tunning true in the next event loop
|
||||||
@ -169,7 +169,9 @@ void Engine::setRunning(bool running)
|
|||||||
if (m_running == running)
|
if (m_running == running)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
qCDebug(dcEngine()) << "----------------------------------------------------------";
|
||||||
qCDebug(dcEngine()) << "Engine is" << (running ? "now running." : "not running any more.");
|
qCDebug(dcEngine()) << "Engine is" << (running ? "now running." : "not running any more.");
|
||||||
|
qCDebug(dcEngine()) << "----------------------------------------------------------";
|
||||||
m_running = running;
|
m_running = running;
|
||||||
emit runningChanged(m_running);
|
emit runningChanged(m_running);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -103,7 +103,7 @@ void MonitorServer::stopServer()
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_server->close();
|
m_server->close();
|
||||||
m_server->deleteLater();
|
delete m_server;
|
||||||
m_server = nullptr;
|
m_server = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,26 +16,32 @@ ProxyConfiguration::ProxyConfiguration(QObject *parent) :
|
|||||||
|
|
||||||
bool ProxyConfiguration::loadConfiguration(const QString &fileName)
|
bool ProxyConfiguration::loadConfiguration(const QString &fileName)
|
||||||
{
|
{
|
||||||
QFileInfo fileInfo(fileName);
|
m_fileName = fileName;
|
||||||
|
QFileInfo fileInfo(m_fileName);
|
||||||
if (!fileInfo.exists()) {
|
if (!fileInfo.exists()) {
|
||||||
qCWarning(dcApplication()) << "Configuration: Could not find configuration file" << fileName;
|
qCWarning(dcApplication()) << "Configuration: Could not find configuration file" << m_fileName;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fileInfo.isReadable()) {
|
if (!fileInfo.isReadable()) {
|
||||||
qCWarning(dcApplication()) << "Configuration: Cannot read configuration file" << fileName;
|
qCWarning(dcApplication()) << "Configuration: Cannot read configuration file" << m_fileName;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QSettings settings(fileName, QSettings::IniFormat);
|
QSettings settings(m_fileName, QSettings::IniFormat);
|
||||||
|
|
||||||
|
settings.beginGroup("ProxyServer");
|
||||||
setServerName(settings.value("name", "nymea-remoteproxy").toString());
|
setServerName(settings.value("name", "nymea-remoteproxy").toString());
|
||||||
setWriteLogFile(settings.value("writeLogs", false).toBool());
|
setWriteLogFile(settings.value("writeLogs", false).toBool());
|
||||||
setLogFileName(settings.value("logFile", "/var/log/nymea-remoteproxy.log").toString());
|
setLogFileName(settings.value("logFile", "/var/log/nymea-remoteproxy.log").toString());
|
||||||
setMonitorSocketFileName(settings.value("monitorSocket", "/tmp/nymea-remoteproxy.monitor").toString());
|
setMonitorSocketFileName(settings.value("monitorSocket", "/tmp/nymea-remoteproxy.monitor").toString());
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
|
settings.beginGroup("SSL");
|
||||||
setSslCertificateFileName(settings.value("certificate", "/etc/ssl/certs/ssl-cert-snakeoil.pem").toString());
|
setSslCertificateFileName(settings.value("certificate", "/etc/ssl/certs/ssl-cert-snakeoil.pem").toString());
|
||||||
setSslCertificateKeyFileName(settings.value("certificateKey", "/etc/ssl/private/ssl-cert-snakeoil.key").toString());
|
setSslCertificateKeyFileName(settings.value("certificateKey", "/etc/ssl/private/ssl-cert-snakeoil.key").toString());
|
||||||
setSslCertificateChainFileName(settings.value("certificateChain", "").toString());
|
setSslCertificateChainFileName(settings.value("certificateChain", "").toString());
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
settings.beginGroup("WebSocketServer");
|
settings.beginGroup("WebSocketServer");
|
||||||
setWebSocketServerHost(QHostAddress(settings.value("host", "127.0.0.1").toString()));
|
setWebSocketServerHost(QHostAddress(settings.value("host", "127.0.0.1").toString()));
|
||||||
@ -92,6 +98,11 @@ bool ProxyConfiguration::loadConfiguration(const QString &fileName)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString ProxyConfiguration::fileName() const
|
||||||
|
{
|
||||||
|
return m_fileName;
|
||||||
|
}
|
||||||
|
|
||||||
QString ProxyConfiguration::serverName() const
|
QString ProxyConfiguration::serverName() const
|
||||||
{
|
{
|
||||||
return m_serverName;
|
return m_serverName;
|
||||||
@ -210,14 +221,24 @@ void ProxyConfiguration::setTcpServerPort(quint16 port)
|
|||||||
QDebug operator<<(QDebug debug, ProxyConfiguration *configuration)
|
QDebug operator<<(QDebug debug, ProxyConfiguration *configuration)
|
||||||
{
|
{
|
||||||
debug.nospace() << endl << "========== ProxyConfiguration ==========" << endl;
|
debug.nospace() << endl << "========== ProxyConfiguration ==========" << endl;
|
||||||
debug.nospace() << "General" << endl;
|
debug.nospace() << "Configuration file:" << configuration->fileName() << endl;
|
||||||
debug.nospace() << " - name:" << configuration->serverName() << endl;
|
debug.nospace() << "RemoteProxy configuration" << endl;
|
||||||
debug.nospace() << " - write logfile:" << configuration->writeLogFile() << endl;
|
debug.nospace() << " - Server name:" << configuration->serverName() << endl;
|
||||||
debug.nospace() << " - logfile:" << configuration->logFileName() << endl;
|
debug.nospace() << " - Write logfile:" << configuration->writeLogFile() << endl;
|
||||||
debug.nospace() << " - certificate:" << configuration->sslCertificateFileName() << endl;
|
debug.nospace() << " - Logfile:" << configuration->logFileName() << endl;
|
||||||
debug.nospace() << " - certificate key:" << configuration->sslCertificateKeyFileName() << endl;
|
debug.nospace() << "SSL configuration" << endl;
|
||||||
debug.nospace() << " - certificate chain:" << configuration->sslCertificateChainFileName() << endl;
|
debug.nospace() << " - Certificate:" << configuration->sslCertificateFileName() << endl;
|
||||||
debug.nospace() << " - SSL certificate information:";
|
debug.nospace() << " - Certificate key:" << configuration->sslCertificateKeyFileName() << endl;
|
||||||
|
debug.nospace() << " - Certificate chain:" << configuration->sslCertificateChainFileName() << endl;
|
||||||
|
debug.nospace() << " - SSL certificate information:" << endl;
|
||||||
|
debug.nospace() << " Common name:" << configuration->sslConfiguration().localCertificate().subjectInfo(QSslCertificate::CommonName) << endl;
|
||||||
|
debug.nospace() << " Organisation:" << configuration->sslConfiguration().localCertificate().subjectInfo(QSslCertificate::Organization) << endl;
|
||||||
|
debug.nospace() << " Organisation unit name:" << configuration->sslConfiguration().localCertificate().subjectInfo(QSslCertificate::OrganizationalUnitName) << endl;
|
||||||
|
debug.nospace() << " Country name:" << configuration->sslConfiguration().localCertificate().subjectInfo(QSslCertificate::CountryName) << endl;
|
||||||
|
debug.nospace() << " Locality name:" << configuration->sslConfiguration().localCertificate().subjectInfo(QSslCertificate::LocalityName) << endl;
|
||||||
|
debug.nospace() << " State/Province:" << configuration->sslConfiguration().localCertificate().subjectInfo(QSslCertificate::StateOrProvinceName) << endl;
|
||||||
|
debug.nospace() << " Email address:" << configuration->sslConfiguration().localCertificate().subjectInfo(QSslCertificate::EmailAddress) << endl;
|
||||||
|
debug.nospace() << " - SSL certificate issuer information:" << endl;
|
||||||
debug.nospace() << " Common name:" << configuration->sslConfiguration().localCertificate().issuerInfo(QSslCertificate::CommonName) << endl;
|
debug.nospace() << " Common name:" << configuration->sslConfiguration().localCertificate().issuerInfo(QSslCertificate::CommonName) << endl;
|
||||||
debug.nospace() << " Organisation:" << configuration->sslConfiguration().localCertificate().issuerInfo(QSslCertificate::Organization) << endl;
|
debug.nospace() << " Organisation:" << configuration->sslConfiguration().localCertificate().issuerInfo(QSslCertificate::Organization) << endl;
|
||||||
debug.nospace() << " Organisation unit name:" << configuration->sslConfiguration().localCertificate().issuerInfo(QSslCertificate::OrganizationalUnitName) << endl;
|
debug.nospace() << " Organisation unit name:" << configuration->sslConfiguration().localCertificate().issuerInfo(QSslCertificate::OrganizationalUnitName) << endl;
|
||||||
@ -225,14 +246,13 @@ QDebug operator<<(QDebug debug, ProxyConfiguration *configuration)
|
|||||||
debug.nospace() << " Locality name:" << configuration->sslConfiguration().localCertificate().issuerInfo(QSslCertificate::LocalityName) << endl;
|
debug.nospace() << " Locality name:" << configuration->sslConfiguration().localCertificate().issuerInfo(QSslCertificate::LocalityName) << endl;
|
||||||
debug.nospace() << " State/Province:" << configuration->sslConfiguration().localCertificate().issuerInfo(QSslCertificate::StateOrProvinceName) << endl;
|
debug.nospace() << " State/Province:" << configuration->sslConfiguration().localCertificate().issuerInfo(QSslCertificate::StateOrProvinceName) << endl;
|
||||||
debug.nospace() << " Email address:" << configuration->sslConfiguration().localCertificate().issuerInfo(QSslCertificate::EmailAddress) << endl;
|
debug.nospace() << " Email address:" << configuration->sslConfiguration().localCertificate().issuerInfo(QSslCertificate::EmailAddress) << endl;
|
||||||
debug.nospace() << "WebSocketServer" << endl;
|
debug.nospace() << "WebSocketServer configuration" << endl;
|
||||||
debug.nospace() << " - host:" << configuration->webSocketServerHost().toString() << endl;
|
debug.nospace() << " - Host:" << configuration->webSocketServerHost().toString() << endl;
|
||||||
debug.nospace() << " - port:" << configuration->webSocketServerPort() << endl;
|
debug.nospace() << " - Port:" << configuration->webSocketServerPort() << endl;
|
||||||
debug.nospace() << "TcpServer" << endl;
|
debug.nospace() << "TcpServer" << endl;
|
||||||
debug.nospace() << " - host:" << configuration->tcpServerHost().toString() << endl;
|
debug.nospace() << " - Host:" << configuration->tcpServerHost().toString() << endl;
|
||||||
debug.nospace() << " - port:" << configuration->tcpServerPort() << endl;
|
debug.nospace() << " - Port:" << configuration->tcpServerPort() << endl;
|
||||||
debug.nospace() << "========== ProxyConfiguration ==========" << endl;
|
debug.nospace() << "========== ProxyConfiguration ==========";
|
||||||
|
|
||||||
return debug;
|
return debug;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,9 @@ public:
|
|||||||
|
|
||||||
bool loadConfiguration(const QString &fileName);
|
bool loadConfiguration(const QString &fileName);
|
||||||
|
|
||||||
// General
|
QString fileName() const;
|
||||||
|
|
||||||
|
// ProxyServer
|
||||||
QString serverName() const;
|
QString serverName() const;
|
||||||
void setServerName(const QString &serverName);
|
void setServerName(const QString &serverName);
|
||||||
|
|
||||||
@ -29,6 +31,7 @@ public:
|
|||||||
QString monitorSocketFileName() const;
|
QString monitorSocketFileName() const;
|
||||||
void setMonitorSocketFileName(const QString &fileName);
|
void setMonitorSocketFileName(const QString &fileName);
|
||||||
|
|
||||||
|
// Ssl
|
||||||
QString sslCertificateFileName() const;
|
QString sslCertificateFileName() const;
|
||||||
void setSslCertificateFileName(const QString &fileName);
|
void setSslCertificateFileName(const QString &fileName);
|
||||||
|
|
||||||
@ -55,11 +58,14 @@ public:
|
|||||||
void setTcpServerPort(quint16 port);
|
void setTcpServerPort(quint16 port);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// General
|
// ProxyServer
|
||||||
|
QString m_fileName;
|
||||||
QString m_serverName;
|
QString m_serverName;
|
||||||
bool m_writeLogFile = false;
|
bool m_writeLogFile = false;
|
||||||
QString m_logFileName = "/var/log/nymea-remoteproxy.log";
|
QString m_logFileName = "/var/log/nymea-remoteproxy.log";
|
||||||
QString m_monitorSocketFileName;
|
QString m_monitorSocketFileName;
|
||||||
|
|
||||||
|
// Ssl
|
||||||
QString m_sslCertificateFileName = "/etc/ssl/certs/ssl-cert-snakeoil.pem";
|
QString m_sslCertificateFileName = "/etc/ssl/certs/ssl-cert-snakeoil.pem";
|
||||||
QString m_sslCertificateKeyFileName = "/etc/ssl/private/ssl-cert-snakeoil.key";
|
QString m_sslCertificateKeyFileName = "/etc/ssl/private/ssl-cert-snakeoil.key";
|
||||||
QString m_sslCertificateChainFileName;
|
QString m_sslCertificateChainFileName;
|
||||||
|
|||||||
@ -27,7 +27,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
QCommandLineOption tokenOption(QStringList() << "s" << "socket", "The AWS token for authentication.", "socket");
|
QCommandLineOption tokenOption(QStringList() << "s" << "socket", "The AWS token for authentication. Default /tmp/", "socket");
|
||||||
parser.addOption(tokenOption);
|
parser.addOption(tokenOption);
|
||||||
|
|
||||||
parser.process(application);
|
parser.process(application);
|
||||||
|
|||||||
@ -1,7 +1,10 @@
|
|||||||
|
[ProxyServer]
|
||||||
name=nymea-remoteproxy
|
name=nymea-remoteproxy
|
||||||
writeLogs=false
|
writeLogs=false
|
||||||
logFile=/var/log/nymea-remoteproxy.log
|
logFile=/var/log/nymea-remoteproxy.log
|
||||||
monitorSocket=/tmp/nymea-remoteproxy.monitor
|
monitorSocket=/tmp/nymea-remoteproxy-monitor.sock
|
||||||
|
|
||||||
|
[SSL]
|
||||||
certificate=/etc/ssl/certs/ssl-cert-snakeoil.pem
|
certificate=/etc/ssl/certs/ssl-cert-snakeoil.pem
|
||||||
certificateKey=/etc/ssl/private/ssl-cert-snakeoil.key
|
certificateKey=/etc/ssl/private/ssl-cert-snakeoil.key
|
||||||
certificateChain=
|
certificateChain=
|
||||||
|
|||||||
@ -1,8 +1,13 @@
|
|||||||
|
[ProxyServer]
|
||||||
name=test-nymea-remoteproxy
|
name=test-nymea-remoteproxy
|
||||||
writeLogs=false
|
writeLogs=false
|
||||||
logFile=/var/log/nymea-remoteproxy.log
|
logFile=/var/log/nymea-remoteproxy.log
|
||||||
|
monitorSocket=/tmp/nymea-remoteproxy-test.sock
|
||||||
|
|
||||||
|
[SSL]
|
||||||
certificate=:/test-certificate.crt
|
certificate=:/test-certificate.crt
|
||||||
certificateKey=:/test-certificate.key
|
certificateKey=:/test-certificate.key
|
||||||
|
certificateChain=
|
||||||
|
|
||||||
[WebSocketServer]
|
[WebSocketServer]
|
||||||
host=127.0.0.1
|
host=127.0.0.1
|
||||||
|
|||||||
@ -55,12 +55,16 @@ void RemoteProxyOfflineTests::dummyAuthenticator()
|
|||||||
void RemoteProxyOfflineTests::monitorServer()
|
void RemoteProxyOfflineTests::monitorServer()
|
||||||
{
|
{
|
||||||
startServer();
|
startServer();
|
||||||
QVERIFY(Engine::instance()->monitorServer()->running());
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
stopServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteProxyOfflineTests::webserverConnectionBlocked()
|
void RemoteProxyOfflineTests::webserverConnectionBlocked()
|
||||||
{
|
{
|
||||||
|
cleanUpEngine();
|
||||||
|
|
||||||
// Create a dummy server which blocks the port
|
// Create a dummy server which blocks the port
|
||||||
QWebSocketServer dummyServer("dummy-server", QWebSocketServer::NonSecureMode);
|
QWebSocketServer dummyServer("dummy-server", QWebSocketServer::NonSecureMode);
|
||||||
dummyServer.listen(QHostAddress::LocalHost, 1212);
|
dummyServer.listen(QHostAddress::LocalHost, 1212);
|
||||||
@ -70,7 +74,7 @@ void RemoteProxyOfflineTests::webserverConnectionBlocked()
|
|||||||
Engine::instance()->setAuthenticator(m_authenticator);
|
Engine::instance()->setAuthenticator(m_authenticator);
|
||||||
Engine::instance()->start(m_configuration);
|
Engine::instance()->start(m_configuration);
|
||||||
runningSpy.wait();
|
runningSpy.wait();
|
||||||
|
qDebug() << runningSpy.count();
|
||||||
QVERIFY(runningSpy.count() == 1);
|
QVERIFY(runningSpy.count() == 1);
|
||||||
|
|
||||||
// Make sure the server is not running
|
// Make sure the server is not running
|
||||||
|
|||||||
Reference in New Issue
Block a user