diff --git a/data/debug-interface/debug-interface.qrc b/data/debug-interface/debug-interface.qrc
new file mode 100644
index 00000000..84752ae6
--- /dev/null
+++ b/data/debug-interface/debug-interface.qrc
@@ -0,0 +1,7 @@
+
+
+ logo.svg
+ styles.css
+
+
+
diff --git a/data/debug-interface/logo.svg b/data/debug-interface/logo.svg
new file mode 100644
index 00000000..17065d0b
--- /dev/null
+++ b/data/debug-interface/logo.svg
@@ -0,0 +1,602 @@
+
+
+
+
diff --git a/data/debug-interface/styles.css b/data/debug-interface/styles.css
new file mode 100644
index 00000000..8c1c2f7e
--- /dev/null
+++ b/data/debug-interface/styles.css
@@ -0,0 +1,47 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * *
+ * Copyright (C) 2018 Simon Stürz *
+ * *
+ * This file is part of guh. *
+ * *
+ * Guh is free software: you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation, version 2 of the License. *
+ * *
+ * Guh is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with guh. If not, see . *
+ * *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+
+table {
+ display: table;
+ border-collapse: colapse;
+ border-spacing: 2px;
+ border-color: gray;
+}
+
+p {
+ color: #676767;
+ font-family: "Ubuntu", Helvetica, "Helvetica Neue", Arial, sans-serif;
+ font-size: 100%;
+}
+
+h1, h2, h3, h4, h5, h6 {
+ margin: 0 0 20px 0;
+ font-family: "Ubuntu", Helvetica, "Helvetica Neue", Arial, sans-serif;
+ font-weight: normal;
+ color: #676767;
+ text-transform: none;
+}
+
+html {
+ color: #676767;
+ font-family: "Ubuntu", Arial, Helvetica, sans-serif;
+ background: white;
+}
diff --git a/libguh-core/debugserverhandler.cpp b/libguh-core/debugserverhandler.cpp
index 4643daef..364f4961 100644
--- a/libguh-core/debugserverhandler.cpp
+++ b/libguh-core/debugserverhandler.cpp
@@ -51,6 +51,11 @@ QByteArray DebugServerHandler::createDebugXmlDocument()
writer.writeEmptyElement("meta");
writer.writeAttribute("http-equiv", "Content-Type");
writer.writeAttribute("content", "text/html; charset=utf-8");
+
+ writer.writeEmptyElement("link");
+ writer.writeAttribute("rel", "stylesheet");
+ writer.writeAttribute("href", "/debug/styles.css");
+
writer.writeTextElement("title", QCoreApplication::translate("main", "Debug nymea"));
writer.writeEndElement(); // head
@@ -368,6 +373,24 @@ QByteArray DebugServerHandler::createErrorXmlDocument(HttpReply::HttpStatusCode
return data;
}
+QByteArray DebugServerHandler::loadResourceFile(const QString &resourceFileName)
+{
+ QFile resourceFile(QString(":%1").arg(resourceFileName));
+ if (!resourceFile.open(QFile::ReadOnly | QFile::Text)) {
+ qCWarning(dcWebServer()) << "Could not open resource file" << resourceFile.fileName();
+ return QByteArray();
+ }
+
+ QTextStream inputStream(&resourceFile);
+ return inputStream.readAll().toUtf8();
+}
+
+bool DebugServerHandler::resourceFileExits(const QString &resourceFileName)
+{
+ QFile resourceFile(QString(":%1").arg(resourceFileName));
+ return resourceFile.exists();
+}
+
HttpReply *DebugServerHandler::processDebugRequest(const QString &requestPath)
{
@@ -552,6 +575,58 @@ HttpReply *DebugServerHandler::processDebugRequest(const QString &requestPath)
}
}
+ // Check if a resource file was requested
+
+ if (requestPath.startsWith("/debug/styles.css")) {
+ QString resourceFileName = "/styles.css";
+ // Check if exists
+ if (!resourceFileExits(resourceFileName)) {
+ qCWarning(dcWebServer()) << "The requested resource file" << resourceFileName << "does not exist";
+ HttpReply *reply = RestResource::createErrorReply(HttpReply::NotFound);
+ reply->setHeader(HttpReply::ContentTypeHeader, "text/plain");
+ reply->setPayload(createErrorXmlDocument(HttpReply::NotFound, QCoreApplication::translate("main", "Could not find find") + " " + resourceFileName));
+ return reply;
+ }
+
+ QByteArray data = loadResourceFile(resourceFileName);
+
+ // Check if content loaded
+ if (data.isEmpty()) {
+ qCWarning(dcWebServer()) << "Empty resource file" << resourceFileName;
+ HttpReply *reply = RestResource::createErrorReply(HttpReply::NoContent);
+ reply->setHeader(HttpReply::ContentTypeHeader, "text/plain");
+ reply->setPayload(createErrorXmlDocument(HttpReply::NotFound, QCoreApplication::translate("main", "Could not find find") + " " + resourceFileName));
+ return reply;
+ }
+
+ HttpReply *reply = RestResource::createSuccessReply();
+ reply->setHeader(HttpReply::ContentTypeHeader, "text/css; charset=\"utf-8\";");
+ reply->setPayload(data);
+ return reply;
+ }
+
+
+
+// if (!fileName.endsWith(".png"))
+// return RestResource::createErrorReply(HttpReply::NotFound);
+
+// QByteArray imageData;
+
+// QImage image(":" + fileName);
+// QBuffer buffer(&imageData);
+// buffer.open(QIODevice::WriteOnly);
+// image.save(&buffer, "png");
+
+// if (!imageData.isEmpty()) {
+// HttpReply *reply = RestResource::createSuccessReply();
+// reply->setHeader(HttpReply::ContentTypeHeader, "image/png");
+// reply->setPayload(imageData);
+// return reply;
+// }
+
+// return RestResource::createErrorReply(HttpReply::NotFound);
+
+
qCDebug(dcWebServer()) << "Create debug interface page";
// Fallback default debug page
diff --git a/libguh-core/debugserverhandler.h b/libguh-core/debugserverhandler.h
index 7c9253e5..cfb19d83 100644
--- a/libguh-core/debugserverhandler.h
+++ b/libguh-core/debugserverhandler.h
@@ -38,7 +38,8 @@ public:
private:
QByteArray createDebugXmlDocument();
QByteArray createErrorXmlDocument(HttpReply::HttpStatusCode statusCode, const QString &errorMessage);
-
+ QByteArray loadResourceFile(const QString &resourceFileName);
+ bool resourceFileExits(const QString &resourceFileName);
};
}
diff --git a/libguh-core/libguh-core.pro b/libguh-core/libguh-core.pro
index cb94da49..7aa268e0 100644
--- a/libguh-core/libguh-core.pro
+++ b/libguh-core/libguh-core.pro
@@ -15,7 +15,9 @@ exists("/usr/include/mbedtls/net_sockets.h") {
}
# icons for the webserver
-RESOURCES += $$top_srcdir/icons.qrc
+RESOURCES += $$top_srcdir/icons.qrc \
+ $$top_srcdir/data/debug-interface/debug-interface.qrc
+
HEADERS += guhcore.h \
tcpserver.h \
diff --git a/server/main.cpp b/server/main.cpp
index 23dde4c1..828b01d1 100644
--- a/server/main.cpp
+++ b/server/main.cpp
@@ -191,7 +191,7 @@ int main(int argc, char *argv[])
debugDescription += "\n- " + filterName + " (" + (s_loggingFilters.value(filterName) ? "yes" : "no") + ")";
- QCommandLineOption allOption(QStringList() << "p" << "print-all", QCoreApplication::translate("main", "Enables all debug categories. This parameter overrides all debug category parameters."));
+ QCommandLineOption allOption(QStringList() << "p" << "print-all", QCoreApplication::translate("main", "Enables all debug categories. Single debug categories can be disabled again with -d parameter."));
parser.addOption(allOption);
QCommandLineOption logOption({"l", "log"}, QCoreApplication::translate("main", "Specify a log file to write to, if this option is not specified, logs will be printed to the standard output."), "logfile", "/var/log/guhd.log");