|
@@ -21,6 +21,7 @@
|
|
|
#include "DomElement.h"
|
|
|
#include "EscapeOStream.h"
|
|
|
#include "FileServe.h"
|
|
|
+#include "FileUtils.h"
|
|
|
#include "WebController.h"
|
|
|
#include "WebRenderer.h"
|
|
|
#include "WebRequest.h"
|
|
@@ -72,9 +73,34 @@ namespace skeletons {
|
|
|
extern const char *Wt_js1;
|
|
|
extern const char *Boot_js1;
|
|
|
extern const char *JQuery_js1;
|
|
|
+ extern const char *LibreJS_js1;
|
|
|
|
|
|
extern std::vector<const char *> JQuery_js();
|
|
|
extern std::vector<const char *> Wt_js();
|
|
|
+
|
|
|
+ const std::string* ParseJsSources()
|
|
|
+ {
|
|
|
+ // libreJS header is used only if the server admin supplies a URL for
|
|
|
+ // at least one @source line in LIBREJS_FILENAME - e.g.
|
|
|
+ // @source - https://example.net/wt-sources
|
|
|
+ const std::string LIBREJS_FILENAME = "libreJS_sources.txt";
|
|
|
+ const std::string* LIBREJS_SOURCES = Wt::FileUtils::fileToString(LIBREJS_FILENAME);
|
|
|
+ if (!LIBREJS_SOURCES) return nullptr;
|
|
|
+
|
|
|
+ std::string librejs_sources = *LIBREJS_SOURCES;
|
|
|
+ std::size_t sources_start = librejs_sources.find("@source ");
|
|
|
+ bool has_sources_line = sources_start != std::string::npos;
|
|
|
+ librejs_sources = (has_sources_line) ? librejs_sources.substr(sources_start + 8) : "";
|
|
|
+ bool has_http_source = librejs_sources.find(" http://") != std::string::npos;
|
|
|
+ bool has_https_source = librejs_sources.find(" https://") != std::string::npos;
|
|
|
+ bool has_ftp_source = librejs_sources.find(" ftp://") != std::string::npos;
|
|
|
+
|
|
|
+ return (has_http_source || has_https_source || has_ftp_source)? LIBREJS_SOURCES: nullptr;
|
|
|
+ }
|
|
|
+
|
|
|
+ const std::string* JS_SOURCES = ParseJsSources();
|
|
|
+ const std::string LIBREJS_HEADER = (!!JS_SOURCES) ? "/*\n" + *JS_SOURCES + LibreJS_js1 + "\n*/\n" : "";
|
|
|
+ const std::string LIBREJS_SCRIPT = (!!JS_SOURCES) ? "<script>\n" + LIBREJS_HEADER + "</script>\n" : "";
|
|
|
}
|
|
|
|
|
|
namespace Wt {
|
|
@@ -433,6 +459,8 @@ void WebRenderer::serveBootstrap(WebResponse& response)
|
|
|
(noJsRedirectUrl,
|
|
|
session_.bootstrapUrl(response, WebSession::KeepInternalPath) + "&js=no");
|
|
|
|
|
|
+ boot.setVar("LIBREJS_HEADER", skeletons::LIBREJS_SCRIPT);
|
|
|
+
|
|
|
boot.setVar("REDIRECT_URL", noJsRedirectUrl.str());
|
|
|
boot.setVar("AUTO_REDIRECT",
|
|
|
"<noscript><meta http-equiv=\"refresh\" content=\"0; url="
|
|
@@ -944,6 +972,8 @@ void WebRenderer::serveMainscript(WebResponse& response)
|
|
|
|
|
|
const bool innerHtml = true;
|
|
|
|
|
|
+ out << skeletons::LIBREJS_HEADER;
|
|
|
+
|
|
|
if (serveSkeletons) {
|
|
|
bool haveJQuery = app->customJQuery();
|
|
|
|