代理地址限制
This commit is contained in:
1 parent
41fa9dd8cc
commit
aaac8fff12
2 files changed
+41
-9
No files matched your search
@@ -4,6 +4,7 @@ port = 9201
|
|||||||
|
|
||||||
[Proxy]
|
[Proxy]
|
||||||
default = http://127.0.0.1:9200
|
default = http://127.0.0.1:9200
|
||||||
|
opened = http://127.0.0.1:9200;http://127.0.0.1:8006;
|
||||||
|
|
||||||
[Database]
|
[Database]
|
||||||
path = sqlite3.db
|
path = sqlite3.db
|
||||||
+40
-9
@@ -21,6 +21,21 @@ namespace po = boost::program_options;
|
|||||||
|
|
||||||
constexpr const char *_VER = "0.2.1";
|
constexpr const char *_VER = "0.2.1";
|
||||||
|
|
||||||
|
//////////////////////////////////
|
||||||
|
#include <sstream>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
std::vector<std::string> split(const std::string& s, char delim) {
|
||||||
|
std::vector<std::string> tokens;
|
||||||
|
std::istringstream stream(s);
|
||||||
|
std::string token;
|
||||||
|
while (std::getline(stream, token, delim)) {
|
||||||
|
tokens.push_back(token);
|
||||||
|
}
|
||||||
|
return tokens;
|
||||||
|
}
|
||||||
|
//////////////////////////////////
|
||||||
|
|
||||||
class DatabaseException: public ExceptionBase {
|
class DatabaseException: public ExceptionBase {
|
||||||
public:
|
public:
|
||||||
@@ -83,6 +98,7 @@ bool is_special_header(const std::string &header);
|
|||||||
static std::string _ADDR;
|
static std::string _ADDR;
|
||||||
static int _PORT;
|
static int _PORT;
|
||||||
static std::string _DEFT_URL;
|
static std::string _DEFT_URL;
|
||||||
|
static std::vector<std::string> _OPEN_URL;
|
||||||
static std::string _DB_PATH;
|
static std::string _DB_PATH;
|
||||||
static std::string _DEFT_ADMIN_USER = "admin";
|
static std::string _DEFT_ADMIN_USER = "admin";
|
||||||
static std::string _DEFT_ADMIN_PASS = "44112233";
|
static std::string _DEFT_ADMIN_PASS = "44112233";
|
||||||
@@ -150,6 +166,7 @@ int main(int argc, char **argv) {
|
|||||||
_ADDR = cf.get<std::string>("Server.address", "");
|
_ADDR = cf.get<std::string>("Server.address", "");
|
||||||
_PORT = cf.get<int> ("Server.port", -1);
|
_PORT = cf.get<int> ("Server.port", -1);
|
||||||
_DEFT_URL = cf.get<std::string>("Proxy.default", "");
|
_DEFT_URL = cf.get<std::string>("Proxy.default", "");
|
||||||
|
_OPEN_URL = split(cf.get<std::string>("Proxy.opened", ""), ';');
|
||||||
_DB_PATH = cf.get<std::string>("Database.path", "");
|
_DB_PATH = cf.get<std::string>("Database.path", "");
|
||||||
}
|
}
|
||||||
catch (ConfIni::IniConfigureFileParseException &e) {
|
catch (ConfIni::IniConfigureFileParseException &e) {
|
||||||
@@ -418,32 +435,31 @@ http::response<http::string_body> handleProxy(
|
|||||||
try {
|
try {
|
||||||
auto _PUBL = MyRSA::Public_Key::from_pem(_KEYGEN->get_public_key_pem());
|
auto _PUBL = MyRSA::Public_Key::from_pem(_KEYGEN->get_public_key_pem());
|
||||||
|
|
||||||
|
std::string t_url = "";
|
||||||
std::string url = "";
|
std::string url = "";
|
||||||
auto flag = false;
|
std::string auth = "";
|
||||||
{
|
{
|
||||||
|
auto flag = false;
|
||||||
auto it = req.base().find("Target-Url");
|
auto it = req.base().find("Target-Url");
|
||||||
if (it != req.base().end()) {
|
if (it != req.base().end()) {
|
||||||
url = req["Target-Url"];
|
t_url = req["Target-Url"];
|
||||||
}
|
}
|
||||||
|
|
||||||
it = req.base().find("target-url");
|
it = req.base().find("target-url");
|
||||||
if (it != req.base().end()) {
|
if (it != req.base().end()) {
|
||||||
url = req["target-url"];
|
t_url = req["target-url"];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url == "") {
|
if (url == "") {
|
||||||
url = _DEFT_URL;
|
t_url = _DEFT_URL;
|
||||||
flag = true;
|
flag = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
url = t_url;
|
||||||
url += "/";
|
url += "/";
|
||||||
url += req.target();
|
url += req.target();
|
||||||
}
|
|
||||||
|
|
||||||
/* check auth */
|
it = req.base().find("Authorization");
|
||||||
std::string auth = "";
|
|
||||||
{
|
|
||||||
auto it = req.base().find("Authorization");
|
|
||||||
if (it == req.base().end() && !flag) {
|
if (it == req.base().end() && !flag) {
|
||||||
throw std::runtime_error("401");
|
throw std::runtime_error("401");
|
||||||
}
|
}
|
||||||
@@ -464,6 +480,21 @@ http::response<http::string_body> handleProxy(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
std::cout << t_url << std::endl;
|
||||||
|
bool flag = false;
|
||||||
|
for (auto& s: _OPEN_URL) {
|
||||||
|
std::cout << s << std::endl;
|
||||||
|
if (s == t_url) {
|
||||||
|
flag = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!flag) {
|
||||||
|
throw std::runtime_error("403");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto callback = [&res](const auto& ret) {
|
auto callback = [&res](const auto& ret) {
|
||||||
res.body() += ret; // TODO: too big file
|
res.body() += ret; // TODO: too big file
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user