22 #include "webview_thread.h" 23 #include "static_processor.h" 24 #include "blackboard_processor.h" 25 #include "startpage_processor.h" 26 #include "plugins_processor.h" 28 # include "tf_processor.h" 31 # include "image_processor.h" 33 #include "service_browse_handler.h" 34 #include "header_generator.h" 35 #include "footer_generator.h" 36 #include "user_verifier.h" 38 #include <core/version.h> 39 #include <core/exceptions/system.h> 40 #include <utils/system/file.h> 41 #include <utils/system/hostinfo.h> 42 #include <webview/request_dispatcher.h> 43 #include <webview/page_reply.h> 44 #include <webview/server.h> 45 #include <webview/url_manager.h> 46 #include <webview/nav_manager.h> 47 #include <utils/misc/string_conversions.h> 82 WebviewThread::~WebviewThread()
91 WebReply::set_caching(
config->
get_bool(
"/webview/client_side_caching"));
93 __webview_service = NULL;
94 __service_browse_handler = NULL;
99 __cfg_use_ssl =
false;
108 __cfg_ssl_create =
false;
121 if (__cfg_ssl_key[0] !=
'/')
122 __cfg_ssl_key = std::string(CONFDIR
"/") + __cfg_ssl_key;
124 if (__cfg_ssl_cert[0] !=
'/')
125 __cfg_ssl_cert = std::string(CONFDIR
"/") + __cfg_ssl_cert;
128 __cfg_ssl_cert.c_str());
130 if (! File::exists(__cfg_ssl_key.c_str())) {
131 if (File::exists(__cfg_ssl_cert.c_str())) {
132 throw Exception(
"Key file %s does not exist, but certificate file %s " 133 "does", __cfg_ssl_key.c_str(), __cfg_ssl_cert.c_str());
134 }
else if (__cfg_ssl_create) {
135 ssl_create(__cfg_ssl_key.c_str(), __cfg_ssl_cert.c_str());
137 throw Exception(
"Key file %s does not exist", __cfg_ssl_key.c_str());
139 }
else if (! File::exists(__cfg_ssl_cert.c_str())) {
140 throw Exception(
"Certificate file %s does not exist, but key file %s " 141 "does", __cfg_ssl_key.c_str(), __cfg_ssl_cert.c_str());
145 __cfg_use_basic_auth =
false;
147 __cfg_use_basic_auth =
config->
get_bool(
"/webview/use_basic_auth");
149 __cfg_basic_auth_realm =
"Fawkes Webview";
151 __cfg_basic_auth_realm =
config->
get_bool(
"/webview/basic_auth_realm");
154 __cfg_access_log =
"";
160 __cache_logger.
clear();
163 "_http._tcp", __cfg_port);
164 __webview_service->add_txt(
"fawkesver=%u.%u.%u",
165 FAWKES_VERSION_MAJOR, FAWKES_VERSION_MINOR,
166 FAWKES_VERSION_MICRO);
173 __header_gen, __footer_gen);
178 __webserver =
new WebServer(__cfg_port, __dispatcher,
179 __cfg_ssl_key.c_str(), __cfg_ssl_cert.c_str(),
180 __cfg_ssl_cipher_suite.empty() ? NULL : __cfg_ssl_cipher_suite.c_str(),
181 logger, __cfg_use_ipv4, __cfg_use_ipv6);
183 __webserver =
new WebServer(__cfg_port, __dispatcher,
logger, __cfg_use_ipv4, __cfg_use_ipv6);
186 if (__cfg_use_basic_auth) {
193 if (__cfg_access_log !=
"") {
198 delete __webview_service;
199 delete __service_browse_handler;
209 std::vector<std::string> static_dirs =
config->
get_strings(
"/webview/static-dirs");
210 static_dirs = StringConversions::resolve_paths(static_dirs);
211 std::vector<const char *> static_dirs_cstr = std::vector<const char *>(static_dirs.size());
212 for(
unsigned int i = 0; i < static_dirs.size(); i++)
214 static_dirs_cstr[i] = static_dirs[i].c_str();
224 logger, thread_collector);
247 if (__cfg_use_ipv4 && __cfg_use_ipv6) {
249 }
else if (__cfg_use_ipv4) {
251 }
else if (__cfg_use_ipv6) {
254 logger->
log_info(
"WebviewThread",
"Listening for HTTP%s connections on port %u (%s)",
255 __cfg_use_ssl ?
"S" :
"", __cfg_port, afs.c_str());
293 delete __webview_service;
294 delete __service_browse_handler;
297 delete __static_processor;
298 delete __blackboard_processor;
299 delete __startpage_processor;
300 delete __plugins_processor;
302 delete __tf_processor;
305 delete __image_processor;
321 WebviewThread::ssl_create(
const char *ssl_key_file,
const char *ssl_cert_file)
324 "This may take a while...");
328 if (asprintf(&cmd,
"openssl req -new -x509 -batch -nodes -days 365 " 329 "-subj \"/C=XX/L=World/O=Fawkes/CN=%s.local\" " 330 "-out \"%s\" -keyout \"%s\" >/dev/null 2>&1",
331 h.
short_name(), ssl_cert_file, ssl_key_file) == -1)
336 int status = system(cmd);
339 if (WEXITSTATUS(status) != 0) {
340 throw Exception(
"Failed to auto-generate key/certificate pair");
WebNavManager * webview_nav_manager
Webview navigation manager.
Thread aspect that allows to provide a logger to Fawkes.
void setup_basic_auth(const char *realm, WebUserVerifier *verifier)
Setup basic authentication.
virtual void unwatch_service(const char *service_type, ServiceBrowseHandler *h)=0
Remove browse handler for specific service.
PluginManager * plugin_manager
This is the member used to access the PluginManager.
Encapsulation of the libmicrohttpd webserver.
const char * short_name()
Get short hostname (up to first dot).
virtual void init()
Initialize the thread.
virtual void finalize()
Finalize the thread.
virtual void log_info(const char *component, const char *format,...)=0
Log informational message.
static const char * TF_URL_PREFIX
Prefix for the WebTfRequestProcessor.
void clear()
Clear messages.
WebviewThread()
Constructor.
ServicePublisher * service_publisher
Service publisher to publish services on the network.
virtual void unpublish_service(NetworkService *service)=0
Revoke service publication.
virtual void publish_service(NetworkService *service)=0
Publish service.
Image stream web processor.
static const char * STATIC_URL_PREFIX
Prefix for the WebStaticRequestProcessor.
Fawkes library namespace.
virtual bool get_bool(const char *path)=0
Get value from configuration which is of type bool.
void process()
Process requests.
Thread class encapsulation of pthreads.
void set_prepfin_conc_loop(bool concurrent=true)
Set concurrent execution of prepare_finalize() and loop().
Transfrom data web request processor.
Static file web processor.
Logger * logger
This is the Logger member used to access the logger.
static const char * IMAGE_URL_PREFIX
Prefix for the WebMJPEGRequestProcessor.
WebRequestManager * webview_request_manager
Webview request manager.
Base class for exceptions in Fawkes.
WebUrlManager * webview_url_manager
Webview request processor manager.
void unregister_baseurl(const char *url_prefix)
Remove a request processor.
BlackBoard web request processor.
void setup_request_manager(WebRequestManager *request_manager)
Setup this server as request manager.
NetworkNameResolver * nnresolver
Network name resolver to lookup IP addresses of hostnames and vice versa.
Webview user verification.
const char * name() const
Get name of thread.
static const char * BLACKBOARD_URL_PREFIX
Prefix for the WebBlackBoardRequestProcessor.
void add_nav_entry(std::string baseurl, std::string name)
Add a navigation entry.
Representation of a service announced or found via service discovery (i.e.
ServiceBrowser * service_browser
Service browser to browse services on the network.
static const char * PLUGINS_URL_PREFIX
Prefix for the WebPluginsRequestProcessor.
virtual void log_debug(const char *component, const char *format,...)=0
Log debug message.
virtual std::vector< std::string > get_strings(const char *path)=0
Get list of values from configuration which is of type string.
void setup_access_log(const char *filename)
Setup access log.
Browse handler to detect other Webview instances on the network.
void remove_nav_entry(std::string baseurl)
Remove a navigation entry.
virtual unsigned int get_uint(const char *path)=0
Get value from configuration which is of type unsigned int.
virtual void loop()
Code to execute in the thread.
Configuration * config
This is the Configuration member used to access the configuration.
virtual void watch_service(const char *service_type, ServiceBrowseHandler *h)=0
Add browse handler for specific service.
void register_baseurl(const char *url_prefix, WebRequestProcessor *processor)
Add a request processor.
System ran out of memory and desired operation could not be fulfilled.
virtual std::string get_string(const char *path)=0
Get value from configuration which is of type string.
BlackBoard * blackboard
This is the BlackBoard instance you can use to interact with the BlackBoard.
Plugins web request processor.