mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
webui fix and serverinfo (#699)
* initial commit of webconfig * update example config with webconfig and fix format of file update debian postinst script for install example config * fix compiling add new web server command "serverinfo" to use in webapp to retrieve json port * change web default port to 8099
This commit is contained in:
parent
f0884ec25b
commit
eb64e7e528
@ -187,7 +187,7 @@
|
||||
{
|
||||
"enable" : true,
|
||||
"document_root" : "/usr/share/hyperion/webconfig",
|
||||
"port" : 8080
|
||||
"port" : 8099
|
||||
},
|
||||
|
||||
/// The configuration of the Json/Proto forwarder. Forward messages to multiple instances of Hyperion on same and/or other hosts
|
||||
|
@ -2,7 +2,9 @@
|
||||
#define WEBCONFIG_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <string>
|
||||
#include <utils/jsonschema/JsonFactory.h>
|
||||
|
||||
class StaticFileServing;
|
||||
|
||||
@ -10,17 +12,23 @@ class WebConfig : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit WebConfig (std::string baseUrl, quint16 port, QObject * parent = NULL);
|
||||
WebConfig (std::string baseUrl, quint16 port, quint16 jsonPort, QObject * parent = NULL);
|
||||
WebConfig (const Json::Value &config, QObject * parent = NULL);
|
||||
|
||||
virtual ~WebConfig (void);
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
private:
|
||||
QObject * _parent;
|
||||
QObject* _parent;
|
||||
QString _baseUrl;
|
||||
quint16 _port;
|
||||
StaticFileServing * _server;
|
||||
quint16 _jsonPort;
|
||||
StaticFileServing* _server;
|
||||
|
||||
const std::string WEBCONFIG_DEFAULT_PATH = "/usr/share/hyperion/webconfig";
|
||||
const quint16 WEBCONFIG_DEFAULT_PORT = 8099;
|
||||
};
|
||||
|
||||
#endif // WEBCONFIG_H
|
||||
|
@ -46,7 +46,7 @@ Logger::Logger ( std::string name, LogLevel minLevel ):
|
||||
_syslogEnabled(true),
|
||||
_loggerId(loggerId++)
|
||||
{
|
||||
#ifdef GLIBC
|
||||
#ifdef __linux__
|
||||
_appname = std::string(program_invocation_short_name);
|
||||
#else
|
||||
_appname = std::string(getprogname());
|
||||
|
@ -8,35 +8,36 @@
|
||||
#include <QPair>
|
||||
#include <QFile>
|
||||
|
||||
StaticFileServing::StaticFileServing (QString baseUrl, quint16 port, QObject * parent)
|
||||
StaticFileServing::StaticFileServing (QString baseUrl, quint16 port, quint16 jsonPort, QObject * parent)
|
||||
: QObject (parent)
|
||||
, m_baseUrl (baseUrl)
|
||||
, _jsonPort (jsonPort)
|
||||
{
|
||||
m_mimeDb = new QMimeDatabase;
|
||||
|
||||
m_server = new QtHttpServer (this);
|
||||
m_server->setServerName (QStringLiteral ("Qt Static HTTP File Server"));
|
||||
_server = new QtHttpServer (this);
|
||||
_server->setServerName (QStringLiteral ("Qt Static HTTP File Server"));
|
||||
|
||||
connect (m_server, &QtHttpServer::started, this, &StaticFileServing::onServerStarted);
|
||||
connect (m_server, &QtHttpServer::stopped, this, &StaticFileServing::onServerStopped);
|
||||
connect (m_server, &QtHttpServer::error, this, &StaticFileServing::onServerError);
|
||||
connect (m_server, &QtHttpServer::requestNeedsReply, this, &StaticFileServing::onRequestNeedsReply);
|
||||
connect (_server, &QtHttpServer::started, this, &StaticFileServing::onServerStarted);
|
||||
connect (_server, &QtHttpServer::stopped, this, &StaticFileServing::onServerStopped);
|
||||
connect (_server, &QtHttpServer::error, this, &StaticFileServing::onServerError);
|
||||
connect (_server, &QtHttpServer::requestNeedsReply, this, &StaticFileServing::onRequestNeedsReply);
|
||||
|
||||
m_server->start (port);
|
||||
_server->start (port);
|
||||
}
|
||||
|
||||
StaticFileServing::~StaticFileServing ()
|
||||
{
|
||||
m_server->stop ();
|
||||
_server->stop ();
|
||||
}
|
||||
|
||||
void StaticFileServing::onServerStarted (quint16 port)
|
||||
{
|
||||
qDebug () << "QtHttpServer started on port" << port << m_server->getServerName ();
|
||||
qDebug () << "QtHttpServer started on port" << port << _server->getServerName ();
|
||||
}
|
||||
|
||||
void StaticFileServing::onServerStopped () {
|
||||
qDebug () << "QtHttpServer stopped" << m_server->getServerName ();
|
||||
qDebug () << "QtHttpServer stopped" << _server->getServerName ();
|
||||
}
|
||||
|
||||
void StaticFileServing::onServerError (QString msg)
|
||||
@ -56,6 +57,16 @@ void StaticFileServing::onRequestNeedsReply (QtHttpRequest * request, QtHttpRepl
|
||||
if (command == QStringLiteral ("GET"))
|
||||
{
|
||||
QString path = request->getUrl ().path ();
|
||||
|
||||
// special uri handling for server commands
|
||||
if ( path == "/serverinfo" )
|
||||
{
|
||||
reply->addHeader ("Content-Type", "text/plain" );
|
||||
reply->appendRawData (QByteArrayLiteral(":") % QString::number(_jsonPort).toUtf8() );
|
||||
return;
|
||||
}
|
||||
|
||||
// get static files
|
||||
if ( path == "/" || path.isEmpty() || ! QFile::exists(m_baseUrl % "/" % path) )
|
||||
path = "index.html";
|
||||
|
||||
|
@ -13,7 +13,7 @@ class StaticFileServing : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit StaticFileServing (QString baseUrl, quint16 port, QObject * parent = NULL);
|
||||
explicit StaticFileServing (QString baseUrl, quint16 port, quint16 jsonPort, QObject * parent = NULL);
|
||||
virtual ~StaticFileServing (void);
|
||||
|
||||
public slots:
|
||||
@ -24,8 +24,9 @@ public slots:
|
||||
|
||||
private:
|
||||
QString m_baseUrl;
|
||||
QtHttpServer * m_server;
|
||||
QtHttpServer * _server;
|
||||
QMimeDatabase * m_mimeDb;
|
||||
quint16 _jsonPort;
|
||||
};
|
||||
|
||||
#endif // STATICFILESERVING_H
|
||||
|
@ -1,14 +1,45 @@
|
||||
#include "webconfig/webconfig.h"
|
||||
#include "StaticFileServing.h"
|
||||
|
||||
WebConfig::WebConfig(std::string baseUrl, quint16 port, QObject * parent) :
|
||||
|
||||
WebConfig::WebConfig(std::string baseUrl, quint16 port, quint16 jsonPort, QObject * parent) :
|
||||
_parent(parent),
|
||||
_baseUrl(QString::fromStdString(baseUrl)),
|
||||
_port(port),
|
||||
_jsonPort(jsonPort),
|
||||
_server(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
WebConfig::WebConfig(const Json::Value &config, QObject * parent) :
|
||||
_parent(parent),
|
||||
_port(WEBCONFIG_DEFAULT_PORT),
|
||||
_server(nullptr)
|
||||
{
|
||||
_baseUrl = QString::fromStdString(WEBCONFIG_DEFAULT_PATH);
|
||||
_jsonPort = 19444;
|
||||
bool webconfigEnable = true;
|
||||
|
||||
if (config.isMember("webConfig"))
|
||||
{
|
||||
const Json::Value & webconfigConfig = config["webConfig"];
|
||||
webconfigEnable = webconfigConfig.get("enable", true).asBool();
|
||||
_port = webconfigConfig.get("port", WEBCONFIG_DEFAULT_PORT).asUInt();
|
||||
_baseUrl = QString::fromStdString( webconfigConfig.get("document_root", WEBCONFIG_DEFAULT_PATH).asString() );
|
||||
}
|
||||
|
||||
if (config.isMember("jsonServer"))
|
||||
{
|
||||
const Json::Value & jsonConfig = config["jsonServer"];
|
||||
_jsonPort = jsonConfig.get("port", 19444).asUInt();
|
||||
}
|
||||
|
||||
|
||||
if ( webconfigEnable )
|
||||
start();
|
||||
}
|
||||
|
||||
|
||||
WebConfig::~WebConfig()
|
||||
{
|
||||
stop();
|
||||
@ -18,7 +49,7 @@ WebConfig::~WebConfig()
|
||||
void WebConfig::start()
|
||||
{
|
||||
if ( _server == nullptr )
|
||||
_server = new StaticFileServing (_baseUrl, _port, this);
|
||||
_server = new StaticFileServing (_baseUrl, _port, _jsonPort, this);
|
||||
}
|
||||
|
||||
void WebConfig::stop()
|
||||
|
@ -195,11 +195,7 @@ void startXBMCVideoChecker(const Json::Value &config, XBMCVideoChecker* &xbmcVid
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ENABLE_QT5
|
||||
void startNetworkServices(const Json::Value &config, Hyperion &hyperion, JsonServer* &jsonServer, ProtoServer* &protoServer, BoblightServer* &boblightServer, WebConfig* &webConfig, XBMCVideoChecker* &xbmcVideoChecker, QObject* parent)
|
||||
#else
|
||||
void startNetworkServices(const Json::Value &config, Hyperion &hyperion, JsonServer* &jsonServer, ProtoServer* &protoServer, BoblightServer* &boblightServer, XBMCVideoChecker* &xbmcVideoChecker)
|
||||
#endif
|
||||
{
|
||||
// Create Json server if configuration is present
|
||||
unsigned int jsonPort = 19444;
|
||||
@ -230,24 +226,6 @@ void startNetworkServices(const Json::Value &config, Hyperion &hyperion, JsonSer
|
||||
}
|
||||
std::cout << "INFO: Proto server created and started on port " << protoServer->getPort() << std::endl;
|
||||
|
||||
#ifdef ENABLE_QT5
|
||||
// webconfig server
|
||||
std::string webconfigPath = "/usr/share/hyperion/webconfig";
|
||||
quint16 webconfigPort = 80;
|
||||
bool webconfigEnable = true;
|
||||
if (config.isMember("webConfig"))
|
||||
{
|
||||
const Json::Value & webconfigConfig = config["webConfig"];
|
||||
webconfigEnable = webconfigConfig.get("enable", true).asBool();
|
||||
webconfigPort = webconfigConfig.get("port", 80).asUInt();
|
||||
webconfigPath = webconfigConfig.get("document_root", "/usr/share/hyperion/webconfig").asString();
|
||||
}
|
||||
|
||||
webConfig = new WebConfig(webconfigPath, webconfigPort, parent);
|
||||
if ( webconfigEnable )
|
||||
webConfig->start();
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_ZEROCONF
|
||||
const Json::Value & deviceConfig = config["device"];
|
||||
const std::string deviceName = deviceConfig.get("name", "").asString();
|
||||
@ -522,11 +500,10 @@ int main(int argc, char** argv)
|
||||
JsonServer * jsonServer = nullptr;
|
||||
ProtoServer * protoServer = nullptr;
|
||||
BoblightServer * boblightServer = nullptr;
|
||||
#ifdef ENABLE_QT5
|
||||
WebConfig * webConfig = nullptr;
|
||||
startNetworkServices(config, hyperion, jsonServer, protoServer, boblightServer, webConfig, xbmcVideoChecker, &app);
|
||||
#else
|
||||
startNetworkServices(config, hyperion, jsonServer, protoServer, boblightServer, xbmcVideoChecker);
|
||||
|
||||
#ifdef ENABLE_QT5
|
||||
WebConfig webConfig(config, &app);
|
||||
#endif
|
||||
|
||||
// ---- grabber -----
|
||||
|
Loading…
Reference in New Issue
Block a user