#include "statuspagecontroller.h" #include "template.h" #include "yacreader_global.h" #include "db_helper.h" #include "yacreader_libraries.h" #include "QsLog.h" #include using stefanfrings::HttpRequest; using stefanfrings::HttpResponse; // using stefanfrings::HttpSession; using stefanfrings::Template; StatusPageController::StatusPageController() { } void StatusPageController::service(HttpRequest &request, HttpResponse &response) { response.setHeader("Content-Type", "text/html; charset=utf-8"); response.setHeader("Connection", "close"); Template StatusPage = Template( QStringLiteral( "\n" "\n" "\n" "YACReaderLibrary Server\n" "\n" "\n\n" "
\n" "\n" "

YACReaderLibraryServer is up and running.

\n" "

YACReader {yr.version}

\n" "

Server {server.version}

\n" "

OS:\t{os.name} {os.version}

\n" "

Port:\t{os.port}

\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "{loop Library}" "\n" "\n" "\n" "\n" "{end Library}" "

\n" "\n" "\n" "\n"), "StatusPage"); StatusPage.enableWarnings(); // Set template variables StatusPage.setVariable("os.name", QSysInfo::prettyProductName()); StatusPage.setVariable("os.version", QSysInfo::productVersion()); // Getting the port from the request is basically a hack, but should do the trick StatusPage.setVariable("os.port", QString(request.getHeader("host")).split(":")[1]); StatusPage.setVariable("server.version", SERVER_VERSION_NUMBER); StatusPage.setVariable("yr.version", VERSION); // Get library info YACReaderLibraries libraries = DBHelper::getLibraries(); QList library_names = libraries.getNames(); size_t num_libs = libraries.getNames().size(); // Fill template StatusPage.loop("Library", num_libs); for (size_t i = 0; i < num_libs; i++) { StatusPage.setVariable(QString("Library%1.Name").arg(i), library_names.at(i)); StatusPage.setVariable(QString("Library%1.Path").arg(i), libraries.getPath(library_names.at(i))); } response.write(StatusPage.toUtf8(), true); }
LibraryPath
{Library.Name}{Library.Path}