23 #include "static_processor.h" 24 #include <webview/file_reply.h> 25 #include <webview/error_reply.h> 27 #include <core/exception.h> 28 #include <logging/logger.h> 51 std::vector<const char *> htdocs_dirs,
56 if(htdocs_dirs.size() <= 0)
58 throw Exception(errno,
"htdocs_dirs is empty");
60 __htdocs_dirs = std::vector<char *>(htdocs_dirs.size());
61 __htdocs_dirs_len = std::vector<size_t>(htdocs_dirs.size());
62 for(
unsigned int i = 0; i < htdocs_dirs.size(); i++)
64 char htdocs_rp[PATH_MAX];
65 if (realpath(htdocs_dirs[i], htdocs_rp) != NULL)
67 __htdocs_dirs[i] = strdup(htdocs_rp);
68 __htdocs_dirs_len[i] = strlen(__htdocs_dirs[i]);
71 throw Exception(errno,
"Failed to resolve htdocs path '%s'", htdocs_dirs[i]);
75 __baseurl = strdup(baseurl);
76 __baseurl_len = strlen(__baseurl);
83 for(
unsigned int i = 0; i < __htdocs_dirs.size(); i++)
85 free(__htdocs_dirs[i]);
93 if ( strncmp(__baseurl, request->
url().c_str(), __baseurl_len) == 0 ) {
97 for(
unsigned int i = 0; i < __htdocs_dirs.size(); i++)
99 std::string file_path = std::string(__htdocs_dirs[i]) + request->
url().substr(__baseurl_len);
102 char *realfile = realpath(file_path.c_str(), rf);
106 if (strncmp(realfile, __htdocs_dirs[i], __htdocs_dirs_len[i]) == 0) {
111 __logger->log_error(
"WebStaticReqProc",
112 "Cannot fulfill request for file %s," 113 " exception follows", request->
url().c_str());
114 __logger->log_error(
"WebStaticReqProc", e);
121 "Access forbidden, breakout detected.");
126 if (errno == ENOENT) {
128 }
else if (errno == EACCES) {
132 if (strerror_r(errno, tmp,
sizeof(tmp)) == 0) {
134 "File access failed: %s", tmp);
137 "File access failed: Unknown error");
142 __logger->log_error(
"WebStaticReqProc",
"Called for invalid base url " 143 "(url: %s, baseurl: %s)", request->
url().c_str(), __baseurl);
Dynamic raw file transfer reply.
virtual fawkes::WebReply * process_request(const fawkes::WebRequest *request)
Process a request.
Fawkes library namespace.
Base class for exceptions in Fawkes.
iterator begin()
Get iterator for messages.
Web request meta data carrier.
WebviewStaticRequestProcessor(const char *baseurl, std::vector< const char *> htdocs_dir, fawkes::Logger *logger)
Constructor.
virtual ~WebviewStaticRequestProcessor()
Destructor.
const std::string & url() const
Get URL.