23 #include "webview_thread.h"
24 #include "static_processor.h"
25 #include "blackboard_processor.h"
26 #include "startpage_processor.h"
27 #include "plugins_processor.h"
28 #include "service_browse_handler.h"
29 #include "header_generator.h"
30 #include "footer_generator.h"
31 #include "user_verifier.h"
33 #include <core/version.h>
34 #include <core/exceptions/system.h>
35 #include <utils/system/file.h>
36 #include <utils/system/hostinfo.h>
37 #include <webview/request_dispatcher.h>
38 #include <webview/page_reply.h>
39 #include <webview/server.h>
40 #include <webview/url_manager.h>
41 #include <webview/nav_manager.h>
45 using namespace fawkes;
72 WebviewThread::~WebviewThread()
81 bool __cfg_use_ssl =
false;
87 __cfg_ssl_create =
false;
95 if (__cfg_ssl_key[0] !=
'/')
96 __cfg_ssl_key = std::string(CONFDIR
"/") + __cfg_ssl_key;
98 if (__cfg_ssl_cert[0] !=
'/')
99 __cfg_ssl_cert = std::string(CONFDIR
"/") + __cfg_ssl_cert;
102 __cfg_ssl_cert.c_str());
104 if (! File::exists(__cfg_ssl_key.c_str())) {
105 if (File::exists(__cfg_ssl_cert.c_str())) {
106 throw Exception(
"Key file %s does not exist, but certificate file %s "
107 "does", __cfg_ssl_key.c_str(), __cfg_ssl_cert.c_str());
108 }
else if (__cfg_ssl_create) {
109 ssl_create(__cfg_ssl_key.c_str(), __cfg_ssl_cert.c_str());
111 throw Exception(
"Key file %s does not exist", __cfg_ssl_key.c_str());
113 }
else if (! File::exists(__cfg_ssl_cert.c_str())) {
114 throw Exception(
"Certificate file %s does not exist, but key file %s "
115 "does", __cfg_ssl_key.c_str(), __cfg_ssl_cert.c_str());
119 bool __cfg_use_basic_auth =
false;
121 __cfg_use_basic_auth =
config->
get_bool(
"/webview/use_basic_auth");
123 __cfg_basic_auth_realm =
"Fawkes Webview";
125 __cfg_basic_auth_realm =
config->
get_bool(
"/webview/basic_auth_realm");
129 __cache_logger.
clear();
132 "_http._tcp", __cfg_port);
133 __webview_service->
add_txt(
"fawkesver=%u.%u.%u",
134 FAWKES_VERSION_MAJOR, FAWKES_VERSION_MINOR,
135 FAWKES_VERSION_MICRO);
142 __header_gen, __footer_gen);
147 __webserver =
new WebServer(__cfg_port, __dispatcher, __cfg_ssl_key.c_str(),
148 __cfg_ssl_cert.c_str(),
logger);
153 if (__cfg_use_basic_auth) {
159 delete __webview_service;
160 delete __service_browse_handler;
180 logger->
log_info(
"WebviewThread",
"Listening for HTTP connections on port %u", __cfg_port);
203 delete __webview_service;
204 delete __service_browse_handler;
207 delete __static_processor;
208 delete __blackboard_processor;
209 delete __startpage_processor;
210 delete __plugins_processor;
225 WebviewThread::ssl_create(
const char *ssl_key_file,
const char *ssl_cert_file)
228 "This may take a while...");
232 if (asprintf(&cmd,
"openssl req -new -x509 -batch -nodes -days 365 "
233 "-subj \"/C=XX/L=World/O=Fawkes/CN=%s.local\" "
234 "-out \"%s\" -keyout \"%s\" >/dev/null 2>&1",
235 h.
short_name(), ssl_cert_file, ssl_key_file) == -1)
240 int status = system(cmd);
243 if (WEXITSTATUS(status) != 0) {
244 throw Exception(
"Failed to auto-generate key/certificate pair");