diff --git a/assets/webconfig/i18n/de.json b/assets/webconfig/i18n/de.json index be44aa69..de93af94 100644 --- a/assets/webconfig/i18n/de.json +++ b/assets/webconfig/i18n/de.json @@ -219,6 +219,8 @@ "InfoDialog_nowrite_foottext" : "Die Webkonfiguration wird automatisch wieder freigegeben, sobald das Problem behoben wurde!", "infoDialog_wizrgb_title" : "Erfolg!", "infoDialog_wizrgb_text" : "Deine RGB Byte Reihenfolge ist bereits richtig eingestellt.", + "infoDialog_writeconf_error_title" : "Fehler", + "infoDialog_writeconf_error_text" : "Das speichern der Konfiguration ist fehlgeschlagen.", "wiz_rgb_title" : "RGB Byte Reihenfolge Assistent", "wiz_rgb_intro1" : "Dieser Assisent wird dir dabei helfen die richtige Byte Reihenfolge für deine leds zu finden. Klicke auf Fortfahren um zu beginnen.", "wiz_rgb_intro2" : "Wann benötigt man diesen Assistenten? Zur Erstkonfiguration oder wenn deine LEDs zb rot leuchten sollten, sie aber blau oder grün sind.", diff --git a/assets/webconfig/i18n/en.json b/assets/webconfig/i18n/en.json index 03179473..98e66a21 100644 --- a/assets/webconfig/i18n/en.json +++ b/assets/webconfig/i18n/en.json @@ -219,6 +219,8 @@ "InfoDialog_nowrite_foottext" : "The WebUI will be unlocked automatically after you solved the problem!", "infoDialog_wizrgb_title" : "Success", "infoDialog_wizrgb_text" : "Your RGB Byte Order is already well adjusted.", + "infoDialog_writeconf_error_title" : "Error", + "infoDialog_writeconf_error_text" : "Saving your configuration failed.", "wiz_rgb_title" : "RGB Byte Order Wizard", "wiz_rgb_intro1" : "This wizard will guide you through the finding process of the correct color order for your leds. Click on continue to begin.", "wiz_rgb_intro2" : "When do you need this wizard? Example: You set the color red, but you get green or blue. You could also use it for first configuration.", diff --git a/assets/webconfig/index.html b/assets/webconfig/index.html index faf2f32f..7316fdfb 100644 --- a/assets/webconfig/index.html +++ b/assets/webconfig/index.html @@ -300,7 +300,7 @@ - + diff --git a/assets/webconfig/js/hyperion.js b/assets/webconfig/js/hyperion.js index a47ff92f..8ea0b572 100644 --- a/assets/webconfig/js/hyperion.js +++ b/assets/webconfig/js/hyperion.js @@ -32,7 +32,7 @@ function initRestart() function cron() { - if ( watchdog > 2) + if ( watchdog > 2 ) { var interval_id = window.setInterval("", 9999); // Get a reference to the last for (var i = 1; i < interval_id; i++) @@ -229,8 +229,15 @@ function requestWriteConfig(config) complete_config[i] = val; }); - var config_str = JSON.stringify(complete_config); - sendToHyperion("config","setconfig", '"config":'+config_str); + var config_str = encode_utf8(JSON.stringify(complete_config)); + + $.post( "/cgi/cfg_set", { cfg: config_str }) + .done(function( data ) { + $("html, body").animate({ scrollTop: 0 }, "slow"); + }) + .fail(function() { + showInfoDialog('error', $.i18n('infoDialog_writeconf_error_title'), $.i18n('infoDialog_writeconf_error_text')); + }); } function requestWriteEffect(effectName,effectPy,effectArgs) diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index de7a82f9..c6f17504 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -103,71 +103,56 @@ MultiColorAdjustment * Hyperion::createLedColorsAdjustment(const unsigned ledCnt MultiColorAdjustment * adjustment = new MultiColorAdjustment(ledCnt); const QJsonValue adjustmentConfig = colorConfig["channelAdjustment"]; - if (adjustmentConfig.isNull()) - { - // Old style color transformation config (just one for all leds) - ColorAdjustment * colorAdjustment = createColorAdjustment(colorConfig); - adjustment->addAdjustment(colorAdjustment); - adjustment->setAdjustmentForLed(colorAdjustment->_id, 0, ledCnt-1); - } - else if (adjustmentConfig.isObject()) - { - ColorAdjustment * colorAdjustment = createColorAdjustment(adjustmentConfig.toObject()); - adjustment->addAdjustment(colorAdjustment); - adjustment->setAdjustmentForLed(colorAdjustment->_id, 0, ledCnt-1); - } - else if (adjustmentConfig.isArray()) - { - const QRegExp overallExp("([0-9]+(\\-[0-9]+)?)(,[ ]*([0-9]+(\\-[0-9]+)?))*"); + const QRegExp overallExp("([0-9]+(\\-[0-9]+)?)(,[ ]*([0-9]+(\\-[0-9]+)?))*"); - const QJsonArray & adjustmentConfigArray = adjustmentConfig.toArray(); - for (signed i = 0; i < adjustmentConfigArray.size(); ++i) + const QJsonArray & adjustmentConfigArray = adjustmentConfig.toArray(); + for (signed i = 0; i < adjustmentConfigArray.size(); ++i) + { + const QJsonObject & config = adjustmentConfigArray.at(i).toObject(); + ColorAdjustment * colorAdjustment = createColorAdjustment(config); + adjustment->addAdjustment(colorAdjustment); + + const QString ledIndicesStr = config["leds"].toString("").trimmed(); + if (ledIndicesStr.compare("*") == 0) { - const QJsonObject & config = adjustmentConfigArray.at(i).toObject(); - ColorAdjustment * colorAdjustment = createColorAdjustment(config); - adjustment->addAdjustment(colorAdjustment); - - const QString ledIndicesStr = config["leds"].toString("").trimmed(); - if (ledIndicesStr.compare("*") == 0) - { - // Special case for indices '*' => all leds - adjustment->setAdjustmentForLed(colorAdjustment->_id, 0, ledCnt-1); - Info(CORE_LOGGER, "ColorAdjustment '%s' => [0; %d]", colorAdjustment->_id.c_str(), ledCnt-1); - continue; - } - - if (!overallExp.exactMatch(ledIndicesStr)) - { - Error(CORE_LOGGER, "Given led indices %d not correct format: %s", i, ledIndicesStr.toStdString().c_str()); - continue; - } - - std::stringstream ss; - const QStringList ledIndexList = ledIndicesStr.split(","); - for (int i=0; i 0) - { - ss << ", "; - } - if (ledIndexList[i].contains("-")) - { - QStringList ledIndices = ledIndexList[i].split("-"); - int startInd = ledIndices[0].toInt(); - int endInd = ledIndices[1].toInt(); - - adjustment->setAdjustmentForLed(colorAdjustment->_id, startInd, endInd); - ss << startInd << "-" << endInd; - } - else - { - int index = ledIndexList[i].toInt(); - adjustment->setAdjustmentForLed(colorAdjustment->_id, index, index); - ss << index; - } - } - Info(CORE_LOGGER, "ColorAdjustment '%s' => [%s]", colorAdjustment->_id.c_str(), ss.str().c_str()); + // Special case for indices '*' => all leds + adjustment->setAdjustmentForLed(colorAdjustment->_id, 0, ledCnt-1); + Info(CORE_LOGGER, "ColorAdjustment '%s' => [0; %d]", colorAdjustment->_id.c_str(), ledCnt-1); + continue; } + + if (!overallExp.exactMatch(ledIndicesStr)) + { + Error(CORE_LOGGER, "Given led indices %d not correct format: %s", i, ledIndicesStr.toStdString().c_str()); + continue; + } + + std::stringstream ss; + const QStringList ledIndexList = ledIndicesStr.split(","); + for (int i=0; i 0) + { + ss << ", "; + } + if (ledIndexList[i].contains("-")) + { + QStringList ledIndices = ledIndexList[i].split("-"); + int startInd = ledIndices[0].toInt(); + int endInd = ledIndices[1].toInt(); + + adjustment->setAdjustmentForLed(colorAdjustment->_id, startInd, endInd); + ss << startInd << "-" << endInd; + } + else + { + int index = ledIndexList[i].toInt(); + adjustment->setAdjustmentForLed(colorAdjustment->_id, index, index); + ss << index; + } + } + Info(CORE_LOGGER, "ColorAdjustment '%s' => [%s]", colorAdjustment->_id.c_str(), ss.str().c_str()); } + return adjustment; } diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index dff83e45..7420c41e 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -967,10 +967,6 @@ void JsonClientConnection::handleConfigCommand(const QJsonObject& message, const { handleConfigGetCommand(message, full_command, tan); } - else if (subcommand == "setconfig") - { - handleConfigSetCommand(message, full_command, tan); - } else if (subcommand == "reload") { _hyperion->freeObjects(); @@ -1098,28 +1094,6 @@ void JsonClientConnection::handleSchemaGetCommand(const QJsonObject& message, co sendMessage(result); } -void JsonClientConnection::handleConfigSetCommand(const QJsonObject& message, const QString &command, const int tan) -{ - if(message.size() > 0) - { - if (message.contains("config")) - { - QString errors; - if (!checkJson(message["config"].toObject(), ":/hyperion-schema", errors, true)) - { - sendErrorReply("Error while validating json: " + errors, command, tan); - return; - } - - QJsonObject hyperionConfig = message["config"].toObject(); - QJsonFactory::writeJson(QString::fromStdString(_hyperion->getConfigFileName()), hyperionConfig); - - sendSuccessReply(command, tan); - } - } else - sendErrorReply("Error while parsing json: Message size " + QString(message.size()), command, tan); -} - void JsonClientConnection::handleComponentStateCommand(const QJsonObject& message, const QString &command, const int tan) { const QJsonObject & componentState = message["componentstate"].toObject(); diff --git a/libsrc/jsonserver/JsonClientConnection.h b/libsrc/jsonserver/JsonClientConnection.h index 333b1d1b..10b37fdb 100644 --- a/libsrc/jsonserver/JsonClientConnection.h +++ b/libsrc/jsonserver/JsonClientConnection.h @@ -234,11 +234,6 @@ private: /// void handleConfigGetCommand(const QJsonObject & message, const QString &command, const int tan); - /// - /// Handle an incoming JSON SetConfig message - /// - void handleConfigSetCommand(const QJsonObject & message, const QString &command, const int tan); - /// /// Handle an incoming JSON Component State message /// diff --git a/libsrc/jsonserver/schema/schema-config.json b/libsrc/jsonserver/schema/schema-config.json index 8cd7e0bf..ca07276b 100644 --- a/libsrc/jsonserver/schema/schema-config.json +++ b/libsrc/jsonserver/schema/schema-config.json @@ -10,7 +10,7 @@ "subcommand": { "type" : "string", "required" : true, - "enum" : ["getconfig","setconfig","getschema","reload"] + "enum" : ["getconfig","getschema","reload"] }, "tan" : { "type" : "integer" diff --git a/libsrc/webconfig/CgiHandler.cpp b/libsrc/webconfig/CgiHandler.cpp index 9079ab6c..b4416ffe 100644 --- a/libsrc/webconfig/CgiHandler.cpp +++ b/libsrc/webconfig/CgiHandler.cpp @@ -2,15 +2,20 @@ #include #include #include +#include +#include +#include #include "CgiHandler.h" #include "QtHttpHeader.h" #include #include +#include CgiHandler::CgiHandler (Hyperion * hyperion, QString baseUrl, QObject * parent) : QObject(parent) , _hyperion(hyperion) + , _args(QStringList()) , _hyperionConfig(_hyperion->getQJsonConfig()) , _baseUrl(baseUrl) { @@ -26,10 +31,13 @@ void CgiHandler::exec(const QStringList & args, QtHttpRequest * request, QtHttpR { // QByteArray header = reply->getHeader(QtHttpHeader::Host); // QtHttpRequest::ClientInfo info = request->getClientInfo(); - - cmd_cfg_jsonserver(args,reply); - cmd_cfg_hyperion(args,reply); - cmd_runscript(args,reply); + _args = args; + _request = request; + _reply = reply; + cmd_cfg_jsonserver(); + cmd_cfg_get(); + cmd_cfg_set(); + cmd_runscript(); throw 1; } catch(int e) @@ -39,9 +47,9 @@ void CgiHandler::exec(const QStringList & args, QtHttpRequest * request, QtHttpR } } -void CgiHandler::cmd_cfg_jsonserver(const QStringList & args, QtHttpReply * reply) +void CgiHandler::cmd_cfg_jsonserver() { - if ( args.at(0) == "cfg_jsonserver" ) + if ( _args.at(0) == "cfg_jsonserver" ) { quint16 jsonPort = 19444; if (_hyperionConfig.contains("jsonServer")) @@ -51,24 +59,25 @@ void CgiHandler::cmd_cfg_jsonserver(const QStringList & args, QtHttpReply * repl } // send result as reply - reply->addHeader ("Content-Type", "text/plain" ); - reply->appendRawData (QByteArrayLiteral(":") % QString::number(jsonPort).toUtf8() ); + _reply->addHeader ("Content-Type", "text/plain" ); + _reply->appendRawData (QByteArrayLiteral(":") % QString::number(jsonPort).toUtf8() ); + throw 0; } } -void CgiHandler::cmd_cfg_hyperion(const QStringList & args, QtHttpReply * reply) +void CgiHandler::cmd_cfg_get() { - if ( args.at(0) == "cfg_hyperion" ) + if ( _args.at(0) == "cfg_get" ) { QFile file ( _hyperion->getConfigFileName().c_str() ); if (file.exists ()) { if (file.open (QFile::ReadOnly)) { QByteArray data = file.readAll (); - reply->addHeader ("Content-Type", "text/plain"); - reply->appendRawData (data); + _reply->addHeader ("Content-Type", "text/plain"); + _reply->appendRawData (data); file.close (); } } @@ -76,11 +85,37 @@ void CgiHandler::cmd_cfg_hyperion(const QStringList & args, QtHttpReply * reply) } } -void CgiHandler::cmd_runscript(const QStringList & args, QtHttpReply * reply) +void CgiHandler::cmd_cfg_set() { - if ( args.at(0) == "run" ) + _reply->addHeader ("Content-Type", "text/plain"); + if ( _args.at(0) == "cfg_set" ) { - QStringList scriptFilePathList(args); + QtHttpPostData data = _request->getPostData(); + QJsonParseError error; + if (data.contains("cfg")) + { + QJsonDocument hyperionConfig = QJsonDocument::fromJson(data["cfg"], &error); + + if (error.error == QJsonParseError::NoError) + { + QJsonObject hyperionConfigJsonObj = hyperionConfig.object(); + QJsonFactory::writeJson(QString::fromStdString(_hyperion->getConfigFileName()), hyperionConfigJsonObj); + } + else + { + _reply->appendRawData (QString("Error while validating json: "+error.errorString()).toUtf8()); + } + } + + throw 0; + } +} + +void CgiHandler::cmd_runscript() +{ + if ( _args.at(0) == "run" ) + { + QStringList scriptFilePathList(_args); scriptFilePathList.removeAt(0); QString scriptFilePath = scriptFilePathList.join('/'); @@ -99,8 +134,8 @@ void CgiHandler::cmd_runscript(const QStringList & args, QtHttpReply * reply) { QByteArray data = Process::command_exec(QString(interpreter + " " + scriptFilePath).toUtf8().constData()).c_str(); - reply->addHeader ("Content-Type", "text/plain"); - reply->appendRawData (data); + _reply->addHeader ("Content-Type", "text/plain"); + _reply->appendRawData (data); throw 0; } throw 1; diff --git a/libsrc/webconfig/CgiHandler.h b/libsrc/webconfig/CgiHandler.h index 6181fba7..284c4518 100644 --- a/libsrc/webconfig/CgiHandler.h +++ b/libsrc/webconfig/CgiHandler.h @@ -20,15 +20,18 @@ public: void exec(const QStringList & args,QtHttpRequest * request, QtHttpReply * reply); // 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); + void cmd_cfg_jsonserver(); + void cmd_cfg_get (); + void cmd_cfg_set (); + void cmd_runscript (); private: Hyperion* _hyperion; QtHttpReply * _reply; + QtHttpRequest * _request; + QStringList _args; const QJsonObject &_hyperionConfig; - const QString _baseUrl; + const QString _baseUrl; }; #endif // CGIHANDLER_H diff --git a/libsrc/webconfig/QtHttpClientWrapper.cpp b/libsrc/webconfig/QtHttpClientWrapper.cpp index 9ff08539..4900a935 100644 --- a/libsrc/webconfig/QtHttpClientWrapper.cpp +++ b/libsrc/webconfig/QtHttpClientWrapper.cpp @@ -50,7 +50,7 @@ void QtHttpClientWrapper::onClientDataReceived (void) { QString url = parts.at (1); QString version = parts.at (2); if (version == QtHttpServer::HTTP_VERSION) { - m_currentRequest = new QtHttpRequest (m_serverHandle); + m_currentRequest = new QtHttpRequest (this, m_serverHandle); m_currentRequest->setClientInfo(m_sockClient->localAddress(), m_sockClient->peerAddress()); m_currentRequest->setUrl (QUrl (url)); m_currentRequest->setCommand (command); @@ -76,9 +76,8 @@ void QtHttpClientWrapper::onClientDataReceived (void) { QByteArray value = raw.mid (pos +1).trimmed (); m_currentRequest->addHeader (header, value); if (header == QtHttpHeader::ContentLength) { - int len = -1; bool ok = false; - len = value.toInt (&ok, 10); + const int len = value.toInt (&ok, 10); if (ok) { m_currentRequest->addHeader (QtHttpHeader::ContentLength, QByteArray::number (len)); } @@ -110,6 +109,24 @@ void QtHttpClientWrapper::onClientDataReceived (void) { } switch (m_parsingStatus) { // handle parsing status end/error case RequestParsed: { // a valid request has ben fully parsed + // add post data to request + if ( m_currentRequest->getCommand() == "POST") + { + QtHttpPostData postData; + QByteArray data = m_currentRequest->getRawData(); + QList parts = data.split('&'); + for (int i = 0; i < parts.size(); ++i) + { + QList keyValue = parts.at(i).split('='); + QByteArray value; + if (keyValue.size()>1) + { + value = QByteArray::fromPercentEncoding(keyValue.at(1)); + } + postData.insert(QString::fromUtf8(keyValue.at(0)),value); + } + m_currentRequest->setPostData(postData); + } QtHttpReply reply (m_serverHandle); connect (&reply, &QtHttpReply::requestSendHeaders, this, &QtHttpClientWrapper::onReplySendHeadersRequested); diff --git a/libsrc/webconfig/QtHttpReply.h b/libsrc/webconfig/QtHttpReply.h index 92b57da1..50993ac6 100644 --- a/libsrc/webconfig/QtHttpReply.h +++ b/libsrc/webconfig/QtHttpReply.h @@ -16,11 +16,16 @@ public: explicit QtHttpReply (QtHttpServer * parent); enum StatusCode { - Ok = 200, - BadRequest = 400, - Forbidden = 403, - NotFound = 404, - InternalError = 502, + Ok = 200, + SeeOther = 303, + BadRequest = 400, + Forbidden = 403, + NotFound = 404, + MethodNotAllowed = 405, + InternalError = 500, + NotImplemented = 501, + BadGateway = 502, + ServiceUnavailable = 503, }; int getRawDataSize (void) const; diff --git a/libsrc/webconfig/QtHttpRequest.cpp b/libsrc/webconfig/QtHttpRequest.cpp index 93909b9f..bb39e3cd 100644 --- a/libsrc/webconfig/QtHttpRequest.cpp +++ b/libsrc/webconfig/QtHttpRequest.cpp @@ -3,12 +3,14 @@ #include "QtHttpHeader.h" #include "QtHttpServer.h" -QtHttpRequest::QtHttpRequest (QtHttpServer * parent) +QtHttpRequest::QtHttpRequest (QtHttpClientWrapper * client, QtHttpServer * parent) : QObject (parent) , m_url (QUrl ()) , m_command (QString ()) , m_data (QByteArray ()) , m_serverHandle (parent) + , m_clientHandle (client) + , m_postData (QtHttpPostData()) { // set some additional headers addHeader (QtHttpHeader::ContentLength, QByteArrayLiteral ("0")); @@ -36,10 +38,18 @@ QByteArray QtHttpRequest::getRawData (void) const { return m_data; } +QtHttpPostData QtHttpRequest::getPostData (void) const { + return m_postData; +} + QList QtHttpRequest::getHeadersList (void) const { return m_headersHash.keys (); } +QtHttpClientWrapper * QtHttpRequest::getClient (void) const { + return m_clientHandle; +} + QByteArray QtHttpRequest::getHeader (const QByteArray & header) const { return m_headersHash.value (header, QByteArray ()); } @@ -67,3 +77,7 @@ void QtHttpRequest::addHeader (const QByteArray & header, const QByteArray & val void QtHttpRequest::appendRawData (const QByteArray & data) { m_data.append (data); } + +void QtHttpRequest::setPostData (const QtHttpPostData & data) { + m_postData = data; +} diff --git a/libsrc/webconfig/QtHttpRequest.h b/libsrc/webconfig/QtHttpRequest.h index ac10d79e..52e175a3 100644 --- a/libsrc/webconfig/QtHttpRequest.h +++ b/libsrc/webconfig/QtHttpRequest.h @@ -7,28 +7,35 @@ #include #include #include +#include class QtHttpServer; +class QtHttpClientWrapper; + +using QtHttpPostData = QMap; class QtHttpRequest : public QObject { Q_OBJECT public: - explicit QtHttpRequest (QtHttpServer * parent); + explicit QtHttpRequest (QtHttpClientWrapper * client, QtHttpServer * parent); struct ClientInfo { - QHostAddress serverAddress; - QHostAddress clientAddress; + QHostAddress serverAddress; + QHostAddress clientAddress; }; - int getRawDataSize (void) const; - QUrl getUrl (void) const; - QString getCommand (void) const; - QByteArray getRawData (void) const; - QList getHeadersList (void) const; - ClientInfo getClientInfo (void) const; + int getRawDataSize (void) const; + QUrl getUrl (void) const; + QString getCommand (void) const; + QByteArray getRawData (void) const; + QList getHeadersList (void) const; + QtHttpClientWrapper * getClient (void) const; QByteArray getHeader (const QByteArray & header) const; + QtHttpPostData getPostData (void) const; + + ClientInfo getClientInfo (void) const; public slots: void setUrl (const QUrl & url); @@ -36,14 +43,17 @@ public slots: void setClientInfo (const QHostAddress & server, const QHostAddress & client); void addHeader (const QByteArray & header, const QByteArray & value); void appendRawData (const QByteArray & data); + void setPostData (const QtHttpPostData & data); private: QUrl m_url; QString m_command; QByteArray m_data; QtHttpServer * m_serverHandle; + QtHttpClientWrapper * m_clientHandle; QHash m_headersHash; ClientInfo m_clientInfo; + QtHttpPostData m_postData; }; #endif // QTHTTPREQUEST_H diff --git a/libsrc/webconfig/QtHttpServer.cpp b/libsrc/webconfig/QtHttpServer.cpp index 5b465cbc..8053f0e2 100644 --- a/libsrc/webconfig/QtHttpServer.cpp +++ b/libsrc/webconfig/QtHttpServer.cpp @@ -18,10 +18,18 @@ QtHttpServer::QtHttpServer (QObject * parent) connect (m_sockServer, &QTcpServer::newConnection, this, &QtHttpServer::onClientConnected); } -const QString QtHttpServer::getServerName (void) const { +const QString & QtHttpServer::getServerName (void) const { return m_serverName; } +quint16 QtHttpServer::getServerPort (void) const { + return m_sockServer->serverPort (); +} + +QString QtHttpServer::getErrorString (void) const { + return m_sockServer->errorString (); +} + void QtHttpServer::start (quint16 port) { if (m_sockServer->listen (QHostAddress::Any, port)) { emit started (m_sockServer->serverPort ()); diff --git a/libsrc/webconfig/QtHttpServer.h b/libsrc/webconfig/QtHttpServer.h index 71a6261b..6ddf4b82 100644 --- a/libsrc/webconfig/QtHttpServer.h +++ b/libsrc/webconfig/QtHttpServer.h @@ -19,8 +19,9 @@ public: explicit QtHttpServer (QObject * parent = Q_NULLPTR); static const QString & HTTP_VERSION; - - const QString getServerName (void) const; + const QString & getServerName (void) const; + quint16 getServerPort (void) const; + QString getErrorString (void) const; public slots: void start (quint16 port = 0); diff --git a/libsrc/webconfig/StaticFileServing.cpp b/libsrc/webconfig/StaticFileServing.cpp index f74f9ea8..00e43bca 100644 --- a/libsrc/webconfig/StaticFileServing.cpp +++ b/libsrc/webconfig/StaticFileServing.cpp @@ -76,7 +76,7 @@ static inline void printErrorToReply (QtHttpReply * reply, QString errorMessage) void StaticFileServing::onRequestNeedsReply (QtHttpRequest * request, QtHttpReply * reply) { QString command = request->getCommand (); - if (command == QStringLiteral ("GET")) + if (command == QStringLiteral ("GET") || command == QStringLiteral ("POST")) { QString path = request->getUrl ().path (); QStringList uri_parts = path.split('/', QString::SkipEmptyParts); @@ -87,6 +87,11 @@ void StaticFileServing::onRequestNeedsReply (QtHttpRequest * request, QtHttpRepl uri_parts.removeAt(0); try { + if (command == QStringLiteral ("POST")) + { + QString postData = request->getRawData(); + uri_parts.append(postData.split('&', QString::SkipEmptyParts)); + } _cgi.exec(uri_parts, request, reply); } catch(...) @@ -134,7 +139,7 @@ void StaticFileServing::onRequestNeedsReply (QtHttpRequest * request, QtHttpRepl } else { - printErrorToReply (reply, "Unhandled HTTP/1.1 method " % command % " on static file server !"); + printErrorToReply (reply, "Unhandled HTTP/1.1 method " % command % " on web server !"); } }