1 parent
7a0446b573
commit
3632f2cd43
27 files changed
+3332
-97
No files matched your search
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "echoion/web/HttpSecurity.hpp"
|
||||
|
||||
#include <Void/Async/ThreadPool.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/beast.hpp>
|
||||
@@ -7,13 +9,16 @@
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <shared_mutex>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace Echoion::Web
|
||||
{
|
||||
@@ -43,6 +48,7 @@ namespace Echoion::Web
|
||||
// Server-wide switch for the Now Playing video preview,
|
||||
// surfaced to the browser via /config.json.
|
||||
bool nowPlayingVideo = true;
|
||||
std::vector<std::string> trustedProxyCidrs;
|
||||
};
|
||||
|
||||
HttpServer();
|
||||
@@ -52,6 +58,12 @@ namespace Echoion::Web
|
||||
void stop();
|
||||
[[nodiscard]] bool isRunning() const { return running_; }
|
||||
|
||||
using TrustedProxyUpdate = std::expected<void, std::string>;
|
||||
[[nodiscard]] static TrustedProxyUpdate validateTrustedProxyCidrs(
|
||||
const std::vector<std::string>& cidrs);
|
||||
[[nodiscard]] TrustedProxyUpdate setTrustedProxyCidrs(
|
||||
const std::vector<std::string>& cidrs);
|
||||
|
||||
// A user's avatar image, served at GET /avatar/<uid>. Installed
|
||||
// by Core (which owns the TeamSpeak plugin handle); best-effort —
|
||||
// nullopt yields a 404 and the UI falls back to initials. It may be
|
||||
@@ -79,6 +91,25 @@ namespace Echoion::Web
|
||||
dashboardProvider_ = std::move(provider);
|
||||
}
|
||||
|
||||
enum class ShortLinkStatus {
|
||||
found,
|
||||
notFound,
|
||||
gone,
|
||||
rateLimited,
|
||||
unavailable,
|
||||
};
|
||||
struct ShortLinkResolution {
|
||||
ShortLinkStatus status = ShortLinkStatus::notFound;
|
||||
std::string location;
|
||||
};
|
||||
using ShortLinkResolver =
|
||||
std::function<ShortLinkResolution(std::string_view key)>;
|
||||
void setShortLinkResolver(ShortLinkResolver resolver)
|
||||
{
|
||||
std::lock_guard lock(shortLinkResolverMutex_);
|
||||
shortLinkResolver_ = std::move(resolver);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void acceptLoop();
|
||||
@@ -96,7 +127,12 @@ namespace Echoion::Web
|
||||
// Serves one request; returns true when the connection should be
|
||||
// kept open for the next request (HTTP keep-alive).
|
||||
bool serveHttp(asio::ip::tcp::socket& socket,
|
||||
const http::request<http::string_body>& req);
|
||||
const http::request<http::string_body>& req,
|
||||
std::string_view clientAddress);
|
||||
[[nodiscard]] std::string clientAddress(
|
||||
const asio::ip::tcp::socket& socket,
|
||||
const http::request<http::string_body>& req) const;
|
||||
[[nodiscard]] bool allowShortLinkRequest(std::string_view peer);
|
||||
|
||||
Config config_;
|
||||
asio::io_context ioContext_;
|
||||
@@ -126,6 +162,11 @@ namespace Echoion::Web
|
||||
std::mutex avatarProviderMutex_;
|
||||
DashboardProvider dashboardProvider_;
|
||||
std::mutex dashboardProviderMutex_;
|
||||
ShortLinkResolver shortLinkResolver_;
|
||||
std::mutex shortLinkResolverMutex_;
|
||||
mutable std::shared_mutex trustedProxyMutex_;
|
||||
std::vector<Security::CidrBlock> trustedProxyNetworks_;
|
||||
Security::ShortLinkRateLimiter shortLinkRateLimiter_;
|
||||
};
|
||||
|
||||
} // namespace Echoion::Web
|
||||
Reference in new issue
Block a user