Minor fixes
This commit is contained in:
@@ -46,26 +46,28 @@ class Proxy:
|
||||
filter_map = self.compile_filters()
|
||||
filters_codes = list(filter_map.keys()) if not in_pause else []
|
||||
proxy_binary_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),"./proxy")
|
||||
self.__write_config(filters_codes)
|
||||
|
||||
self.process = subprocess.Popen(
|
||||
[proxy_binary_path, str(self.public_host), str(self.public_port), str(self.internal_host), str(self.internal_port), self.config_file_path],
|
||||
stdout=subprocess.PIPE, universal_newlines=True
|
||||
)
|
||||
for stdout_line in iter(self.process.stdout.readline, ""):
|
||||
if stdout_line.startswith("BLOCKED"):
|
||||
regex_id = stdout_line.split()[1]
|
||||
filter_map[regex_id].blocked+=1
|
||||
if self.callback_blocked_update: self.callback_blocked_update(filter_map[regex_id])
|
||||
self.process.stdout.close()
|
||||
return self.process.wait()
|
||||
try:
|
||||
self.__write_config(filters_codes)
|
||||
|
||||
self.process = subprocess.Popen(
|
||||
[proxy_binary_path, str(self.public_host), str(self.public_port), str(self.internal_host), str(self.internal_port), self.config_file_path],
|
||||
stdout=subprocess.PIPE, universal_newlines=True
|
||||
)
|
||||
for stdout_line in iter(self.process.stdout.readline, ""):
|
||||
if stdout_line.startswith("BLOCKED"):
|
||||
regex_id = stdout_line.split()[1]
|
||||
filter_map[regex_id].blocked+=1
|
||||
if self.callback_blocked_update: self.callback_blocked_update(filter_map[regex_id])
|
||||
self.process.stdout.close()
|
||||
return self.process.wait()
|
||||
finally:
|
||||
self.__delete_config()
|
||||
|
||||
def stop(self):
|
||||
if self.process:
|
||||
self.process.terminate()
|
||||
try:
|
||||
self.process.wait(timeout=3)
|
||||
return True
|
||||
except Exception:
|
||||
self.process.kill()
|
||||
return False
|
||||
@@ -82,6 +84,10 @@ class Proxy:
|
||||
with open(self.config_file_path,'w') as config_file:
|
||||
for line in filters_codes:
|
||||
config_file.write(line + '\n')
|
||||
|
||||
def __delete_config(self):
|
||||
if os.path.exists(self.config_file_path):
|
||||
os.remove(self.config_file_path)
|
||||
|
||||
def reload(self):
|
||||
if self.isactive():
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
boost::asio::io_service *ios_loop = nullptr;
|
||||
|
||||
int to_int(int c) {
|
||||
if (not isxdigit(c)) return -1; // error: non-hexadecimal digit found
|
||||
if (isdigit(c)) return c - '0';
|
||||
@@ -380,8 +382,15 @@ void update_regex(){
|
||||
void signal_handler(int signal_num)
|
||||
{
|
||||
if (signal_num == SIGUSR1){
|
||||
#ifdef DEBUG
|
||||
cout << "Updating configurtation" << endl;
|
||||
#endif
|
||||
update_regex();
|
||||
}else if(signal_num == SIGTERM){
|
||||
if (ios_loop != nullptr) ios_loop->stop();
|
||||
exit(0);
|
||||
}else if (signal_num == SIGSEGV){
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -398,13 +407,16 @@ int main(int argc, char* argv[])
|
||||
const std::string local_host = argv[1];
|
||||
const std::string forward_host = argv[3];
|
||||
|
||||
|
||||
signal(SIGUSR1, signal_handler);\
|
||||
update_regex();
|
||||
signal(SIGUSR1, signal_handler);
|
||||
signal(SIGTERM, signal_handler);
|
||||
signal(SIGSEGV, signal_handler);
|
||||
|
||||
config_file = argv[5];
|
||||
update_regex();
|
||||
|
||||
|
||||
boost::asio::io_service ios;
|
||||
ios_loop = &ios;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user