2019-10-09 20:29:41 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-01-18 20:19:10 +00:00
|
|
|
#include <string>
|
2019-10-09 20:29:41 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <unordered_set>
|
|
|
|
|
|
|
|
|
2020-01-18 20:19:10 +00:00
|
|
|
namespace Poco { class URI; }
|
|
|
|
namespace Poco { namespace Util { class AbstractConfiguration; } }
|
|
|
|
|
2019-10-09 20:29:41 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
2019-10-10 12:58:06 +00:00
|
|
|
class RemoteHostFilter
|
2019-10-09 20:29:41 +00:00
|
|
|
{
|
2019-11-05 12:40:49 +00:00
|
|
|
/**
|
2020-01-18 20:19:10 +00:00
|
|
|
* This class checks if URL is allowed.
|
2019-11-05 12:40:49 +00:00
|
|
|
* If primary_hosts and regexp_hosts are empty all urls are allowed.
|
|
|
|
*/
|
2019-10-09 20:29:41 +00:00
|
|
|
public:
|
2019-11-05 12:40:49 +00:00
|
|
|
void checkURL(const Poco::URI & uri) const; /// If URL not allowed in config.xml throw UNACCEPTABLE_URL Exception
|
2019-10-09 20:29:41 +00:00
|
|
|
|
2019-11-05 12:40:49 +00:00
|
|
|
void setValuesFromConfig(const Poco::Util::AbstractConfiguration & config);
|
2019-10-09 20:29:41 +00:00
|
|
|
|
2019-11-05 12:40:49 +00:00
|
|
|
void checkHostAndPort(const std::string & host, const std::string & port) const; /// Does the same as checkURL, but for host and port.
|
2019-10-09 20:29:41 +00:00
|
|
|
|
|
|
|
private:
|
2021-02-04 06:21:05 +00:00
|
|
|
bool is_allow_by_default = true;
|
2019-10-09 20:29:41 +00:00
|
|
|
std::unordered_set<std::string> primary_hosts; /// Allowed primary (<host>) URL from config.xml
|
|
|
|
std::vector<std::string> regexp_hosts; /// Allowed regexp (<hots_regexp>) URL from config.xml
|
|
|
|
|
2020-01-18 20:19:10 +00:00
|
|
|
/// Checks if the primary_hosts and regexp_hosts contain str. If primary_hosts and regexp_hosts are empty return true.
|
|
|
|
bool checkForDirectEntry(const std::string & str) const;
|
2019-10-09 20:29:41 +00:00
|
|
|
};
|
2019-10-10 13:53:26 +00:00
|
|
|
}
|