mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
refactoring of webui and event based websocket layer (#219)
* make hyperion websocket api event based * implement new websocket handling for generalconf * migrate all webui stuff to new event based websocket api some cleanup ... now all html templates are in content refactoring of web stuff * add hyperionport to global start impl. removing advanced key * separate dashboard serverinfo is updated every 3 seconds automatily add input selection cleanup and remove not needed stuff * prepare infrastructure for server sided file execution * webui minor fixes * fix compile
This commit is contained in:
@@ -5,11 +5,13 @@
|
||||
|
||||
#include "CgiHandler.h"
|
||||
#include "QtHttpHeader.h"
|
||||
#include <utils/FileUtils.h>
|
||||
|
||||
CgiHandler::CgiHandler (Hyperion * hyperion, QObject * parent)
|
||||
CgiHandler::CgiHandler (Hyperion * hyperion, QString baseUrl, QObject * parent)
|
||||
: QObject(parent)
|
||||
, _hyperion(hyperion)
|
||||
, _hyperionConfig(_hyperion->getJsonConfig())
|
||||
, _baseUrl(baseUrl)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -26,6 +28,7 @@ void CgiHandler::exec(const QStringList & args, QtHttpRequest * request, QtHttpR
|
||||
|
||||
cmd_cfg_jsonserver(args,reply);
|
||||
cmd_cfg_hyperion(args,reply);
|
||||
cmd_runscript(args,reply);
|
||||
throw 1;
|
||||
}
|
||||
catch(int e)
|
||||
@@ -71,3 +74,34 @@ void CgiHandler::cmd_cfg_hyperion(const QStringList & args, QtHttpReply * reply)
|
||||
throw 0;
|
||||
}
|
||||
}
|
||||
|
||||
void CgiHandler::cmd_runscript(const QStringList & args, QtHttpReply * reply)
|
||||
{
|
||||
if ( args.at(0) == "run" )
|
||||
{
|
||||
QStringList scriptFilePathList(args);
|
||||
scriptFilePathList.removeAt(0);
|
||||
|
||||
QString scriptFilePath = scriptFilePathList.join('/');
|
||||
// relative path not allowed
|
||||
if (scriptFilePath.indexOf("..") >=0)
|
||||
{
|
||||
throw 1;
|
||||
}
|
||||
|
||||
scriptFilePath = _baseUrl+"/server_scripts/"+scriptFilePath;
|
||||
QString interpreter = "";
|
||||
if (scriptFilePath.endsWith(".sh")) interpreter = "sh";
|
||||
if (scriptFilePath.endsWith(".py")) interpreter = "python";
|
||||
|
||||
if (QFile::exists(scriptFilePath) && !interpreter.isEmpty())
|
||||
{
|
||||
QByteArray data = FileUtils::command_exec(QString(interpreter + " " + scriptFilePath).toUtf8().constData()).c_str();
|
||||
|
||||
reply->addHeader ("Content-Type", "text/plain");
|
||||
reply->appendRawData (data);
|
||||
throw 0;
|
||||
}
|
||||
throw 1;
|
||||
}
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@ class CgiHandler : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CgiHandler (Hyperion * hyperion, QObject * parent = NULL);
|
||||
CgiHandler (Hyperion * hyperion, QString baseUrl, QObject * parent = NULL);
|
||||
virtual ~CgiHandler (void);
|
||||
|
||||
void exec(const QStringList & args,QtHttpRequest * request, QtHttpReply * reply);
|
||||
@@ -23,11 +23,13 @@ public:
|
||||
// cgi commands
|
||||
void cmd_cfg_jsonserver(const QStringList & args, QtHttpReply * reply);
|
||||
void cmd_cfg_hyperion (const QStringList & args, QtHttpReply * reply);
|
||||
void cmd_runscript (const QStringList & args, QtHttpReply * reply);
|
||||
|
||||
private:
|
||||
Hyperion* _hyperion;
|
||||
QtHttpReply * _reply;
|
||||
const Json::Value &_hyperionConfig;
|
||||
const QString _baseUrl;
|
||||
};
|
||||
|
||||
#endif // CGIHANDLER_H
|
||||
|
@@ -12,7 +12,7 @@ StaticFileServing::StaticFileServing (Hyperion *hyperion, QString baseUrl, quint
|
||||
: QObject (parent)
|
||||
, _hyperion(hyperion)
|
||||
, _baseUrl (baseUrl)
|
||||
, _cgi(hyperion, this)
|
||||
, _cgi(hyperion, baseUrl, this)
|
||||
, _log(Logger::getInstance("WEBSERVER"))
|
||||
{
|
||||
_mimeDb = new QMimeDatabase;
|
||||
@@ -71,7 +71,7 @@ void StaticFileServing::onRequestNeedsReply (QtHttpRequest * request, QtHttpRepl
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
printErrorToReply (reply, "cgi script failed (" % path % ")");
|
||||
printErrorToReply (reply, "script failed (" % path % ")");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@@ -33,7 +33,7 @@ private:
|
||||
QtHttpServer * _server;
|
||||
QMimeDatabase * _mimeDb;
|
||||
CgiHandler _cgi;
|
||||
Logger * _log;
|
||||
Logger * _log;
|
||||
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user