X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fmodules%2Fm_httpd.cpp;h=eefb3ed93c09f10f74950efa9e6d97ecaddecbc3;hb=6f4aee365b5af9a9c6f733be8dbfc3365d15a866;hp=978a60ab76e8a959fca18f52a76f4190deb719ea;hpb=89f36a6f1c13465cebe56ee1e12fec1dec40679a;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_httpd.cpp b/src/modules/m_httpd.cpp index 978a60ab7..eefb3ed93 100644 --- a/src/modules/m_httpd.cpp +++ b/src/modules/m_httpd.cpp @@ -3,9 +3,9 @@ * * Copyright (C) 2019 linuxdaemon * Copyright (C) 2018 edef - * Copyright (C) 2013-2014, 2017-2019 Sadie Powell + * Copyright (C) 2013-2014, 2017-2020 Sadie Powell * Copyright (C) 2012-2016 Attila Molnar - * Copyright (C) 2012, 2019 Robby + * Copyright (C) 2012 Robby * Copyright (C) 2009 Uli Schlachter * Copyright (C) 2009 Daniel De Graaf * Copyright (C) 2008 Robin Burchell @@ -95,6 +95,7 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru { if (!messagecomplete) { + ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "HTTP socket %d timed out", GetFd()); Close(); return false; } @@ -229,6 +230,8 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru // IOHook may have errored if (!getError().empty()) { + ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "HTTP socket %d encountered a hook error: %s", + GetFd(), getError().c_str()); Close(); return; } @@ -254,19 +257,25 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru ServerInstance->GlobalCulls.AddItem(this); } - void OnError(BufferedSocketError) CXX11_OVERRIDE + void OnError(BufferedSocketError err) CXX11_OVERRIDE { + ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "HTTP socket %d encountered an error: %d - %s", + GetFd(), err, getError().c_str()); Close(); } - void SendHTTPError(unsigned int response) + void SendHTTPError(unsigned int response, const char* errstr = NULL) { + if (!errstr) + errstr = http_status_str((http_status)response); + + ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Sending HTTP error %u: %s", response, errstr); static HTTPHeaders empty; std::string data = InspIRCd::Format( "" "

Error %u

%s


" "Powered by InspIRCd", - response, http_status_str((http_status)response)); + response, errstr); Page(data, response, &empty); } @@ -284,7 +293,7 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru else rheaders.RemoveHeader("Content-Type"); - /* Supporting Connection: keep-alive causes a whole world of hurt syncronizing timeouts, + /* Supporting Connection: keep-alive causes a whole world of hurt synchronizing timeouts, * so remove it, its not essential for what we need. */ rheaders.SetHeader("Connection", "Close"); @@ -298,8 +307,10 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru if (parser.upgrade || HTTP_PARSER_ERRNO(&parser)) return; http_parser_execute(&parser, &parser_settings, recvq.data(), recvq.size()); - if (parser.upgrade || HTTP_PARSER_ERRNO(&parser)) + if (parser.upgrade) SendHTTPError(status_code ? status_code : 400); + else if (HTTP_PARSER_ERRNO(&parser)) + SendHTTPError(status_code ? status_code : 400, http_errno_description((http_errno)parser.http_errno)); } void ServeData() @@ -340,7 +351,32 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru return false; if (url.field_set & (1 << UF_PATH)) - out.path = uri.substr(url.field_data[UF_PATH].off, url.field_data[UF_PATH].len); + { + // Normalise the path. + std::vector pathsegments; + irc::sepstream pathstream(uri.substr(url.field_data[UF_PATH].off, url.field_data[UF_PATH].len), '/'); + for (std::string pathsegment; pathstream.GetToken(pathsegment); ) + { + if (pathsegment == ".") + { + // Stay at the current level. + continue; + } + + if (pathsegment == "..") + { + // Traverse up to the previous level. + if (!pathsegments.empty()) + pathsegments.pop_back(); + continue; + } + + pathsegments.push_back(pathsegment); + } + + out.path.reserve(url.field_data[UF_PATH].len); + out.path.append("/").append(stdalgo::string::join(pathsegments, '/')); + } if (url.field_set & (1 << UF_FRAGMENT)) out.fragment = uri.substr(url.field_data[UF_FRAGMENT].off, url.field_data[UF_FRAGMENT].len); @@ -446,7 +482,7 @@ class ModuleHttpServer : public Module Version GetVersion() CXX11_OVERRIDE { - return Version("Provides HTTP serving facilities to modules", VF_VENDOR); + return Version("Allows the server administrator to serve various useful resources over HTTP.", VF_VENDOR); } };