Migrate from boost::regex to std::regex to increase stability
This commit is contained in:
@@ -14,7 +14,7 @@ ADD ./backend/requirements.txt /execute/requirements.txt
|
|||||||
RUN pip install --no-cache-dir -r /execute/requirements.txt
|
RUN pip install --no-cache-dir -r /execute/requirements.txt
|
||||||
|
|
||||||
COPY ./backend/ /execute/
|
COPY ./backend/ /execute/
|
||||||
RUN c++ -O3 -o proxy/proxy proxy/proxy.cpp -pthread -lboost_system -lboost_regex
|
RUN c++ -O3 -o proxy/proxy proxy/proxy.cpp -pthread -lboost_system
|
||||||
COPY ./config/supervisord.conf /etc/supervisor/supervisord.conf
|
COPY ./config/supervisord.conf /etc/supervisor/supervisord.conf
|
||||||
COPY ./config/nginx.conf /tmp/nginx.conf
|
COPY ./config/nginx.conf /tmp/nginx.conf
|
||||||
COPY ./config/start_nginx.sh /tmp/start_nginx.sh
|
COPY ./config/start_nginx.sh /tmp/start_nginx.sh
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <csignal>
|
#include <csignal>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include <boost/regex.hpp>
|
#include <regex>
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
#include <boost/enable_shared_from_this.hpp>
|
#include <boost/enable_shared_from_this.hpp>
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
#include <cctype> // is*
|
#include <cctype> // is*
|
||||||
|
|
||||||
//#define DEBUG
|
#define DEBUG
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -39,10 +39,10 @@ unhexlify(InputIterator first, InputIterator last, OutputIterator ascii) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<pair<string,boost::regex>> regex_s_c_w, regex_c_s_w, regex_s_c_b, regex_c_s_b;
|
vector<pair<string,std::regex>> regex_s_c_w, regex_c_s_w, regex_s_c_b, regex_c_s_b;
|
||||||
const char* config_file;
|
const char* config_file;
|
||||||
|
|
||||||
bool filter_data(unsigned char* data, const size_t& bytes_transferred, vector<pair<string,boost::regex>> const &blacklist, vector<pair<string,boost::regex>> const &whitelist){
|
bool filter_data(unsigned char* data, const size_t& bytes_transferred, vector<pair<string,std::regex>> const &blacklist, vector<pair<string,std::regex>> const &whitelist){
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
cout << "---------------- Packet ----------------" << endl;
|
cout << "---------------- Packet ----------------" << endl;
|
||||||
for(int i=0;i<bytes_transferred;i++){
|
for(int i=0;i<bytes_transferred;i++){
|
||||||
@@ -50,31 +50,31 @@ bool filter_data(unsigned char* data, const size_t& bytes_transferred, vector<pa
|
|||||||
}
|
}
|
||||||
cout << "\n" << "---------------- End Packet ----------------" << endl;
|
cout << "\n" << "---------------- End Packet ----------------" << endl;
|
||||||
#endif
|
#endif
|
||||||
for (pair<string,boost::regex> ele:blacklist){
|
for (pair<string,std::regex> ele:blacklist){
|
||||||
boost::cmatch what;
|
std::cmatch what;
|
||||||
try{
|
try{
|
||||||
if (boost::regex_match(reinterpret_cast<const char*>(data),
|
std::regex_search(reinterpret_cast<const char*>(data), what, ele.second);
|
||||||
reinterpret_cast<const char*>(data) + bytes_transferred, what, ele.second)){
|
if(what.size() > 0){
|
||||||
cout << "BLOCKED " << ele.first << endl;
|
cout << "BLOCKED " << ele.first << endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch(...){
|
} catch(...){
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
cout << "Error while matching regex: " << ele.first << endl;
|
cerr << "Error while matching regex: " << ele.first << endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (pair<string,boost::regex> ele:whitelist){
|
for (pair<string,std::regex> ele:whitelist){
|
||||||
boost::cmatch what;
|
std::cmatch what;
|
||||||
try{
|
try{
|
||||||
if (!boost::regex_match(reinterpret_cast<const char*>(data),
|
std::regex_search(reinterpret_cast<const char*>(data), what, ele.second);
|
||||||
reinterpret_cast<const char*>(data) + bytes_transferred, what, ele.second)){
|
if(what.size() < 0){
|
||||||
cout << "BLOCKED " << ele.first << endl;
|
cout << "BLOCKED " << ele.first << endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch(...){
|
} catch(...){
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
cout << "Error while matching regex: " << ele.first << endl;
|
cerr << "Error while matching regex: " << ele.first << endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -325,23 +325,22 @@ namespace tcp_proxy
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void push_regex(char* arg, bool case_sensitive, vector<pair<string,boost::regex>> &v){
|
void push_regex(char* arg, bool case_sensitive, vector<pair<string,std::regex>> &v){
|
||||||
size_t expr_len = (strlen(arg)-2)/2;
|
size_t expr_len = (strlen(arg)-2)/2;
|
||||||
char expr[expr_len];
|
char expr[expr_len];
|
||||||
unhexlify(arg+2, arg+strlen(arg)-1, expr);
|
unhexlify(arg+2, arg+strlen(arg)-1, expr);
|
||||||
|
string expr_str(expr, expr_len);
|
||||||
try{
|
try{
|
||||||
if (case_sensitive){
|
if (case_sensitive){
|
||||||
boost::regex regex(reinterpret_cast<char*>(expr),
|
std::regex regex(expr_str);
|
||||||
reinterpret_cast<char*>(expr) + expr_len);
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
cout << "Added case sensitive regex " << expr << endl;
|
cout << "Added case sensitive regex " << expr_str << endl;
|
||||||
#endif
|
#endif
|
||||||
v.push_back(make_pair(string(arg), regex));
|
v.push_back(make_pair(string(arg), regex));
|
||||||
} else {
|
} else {
|
||||||
boost::regex regex(reinterpret_cast<char*>(expr),
|
std::regex regex(expr_str,std::regex_constants::icase);
|
||||||
reinterpret_cast<char*>(expr) + expr_len, boost::regex::icase);
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
cout << "Added case insensitive regex " << expr << endl;
|
cout << "Added case insensitive regex " << expr_str << endl;
|
||||||
#endif
|
#endif
|
||||||
v.push_back(make_pair(string(arg), regex));
|
v.push_back(make_pair(string(arg), regex));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user