General bug fixes
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
from signal import SIGUSR1
|
from signal import SIGUSR1
|
||||||
from secrets import token_urlsafe
|
from secrets import token_urlsafe
|
||||||
import subprocess, re, os
|
import subprocess, re, os
|
||||||
|
from threading import Lock
|
||||||
|
|
||||||
#c++ -o proxy proxy.cpp
|
#c++ -o proxy proxy.cpp
|
||||||
|
|
||||||
@@ -28,6 +28,8 @@ class Filter:
|
|||||||
|
|
||||||
class Proxy:
|
class Proxy:
|
||||||
def __init__(self, internal_port, public_port, callback_blocked_update=None, filters=None, public_host="0.0.0.0", internal_host="127.0.0.1"):
|
def __init__(self, internal_port, public_port, callback_blocked_update=None, filters=None, public_host="0.0.0.0", internal_host="127.0.0.1"):
|
||||||
|
self.filter_map = {}
|
||||||
|
self.filter_map_lock = Lock()
|
||||||
self.public_host = public_host
|
self.public_host = public_host
|
||||||
self.public_port = public_port
|
self.public_port = public_port
|
||||||
self.internal_host = internal_host
|
self.internal_host = internal_host
|
||||||
@@ -43,8 +45,8 @@ class Proxy:
|
|||||||
|
|
||||||
def start(self, in_pause=False):
|
def start(self, in_pause=False):
|
||||||
if self.process is None:
|
if self.process is None:
|
||||||
filter_map = self.compile_filters()
|
self.filter_map = self.compile_filters()
|
||||||
filters_codes = list(filter_map.keys()) if not in_pause else []
|
filters_codes = list(self.filter_map.keys()) if not in_pause else []
|
||||||
proxy_binary_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),"./proxy")
|
proxy_binary_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),"./proxy")
|
||||||
try:
|
try:
|
||||||
self.__write_config(filters_codes)
|
self.__write_config(filters_codes)
|
||||||
@@ -56,8 +58,9 @@ class Proxy:
|
|||||||
for stdout_line in iter(self.process.stdout.readline, ""):
|
for stdout_line in iter(self.process.stdout.readline, ""):
|
||||||
if stdout_line.startswith("BLOCKED"):
|
if stdout_line.startswith("BLOCKED"):
|
||||||
regex_id = stdout_line.split()[1]
|
regex_id = stdout_line.split()[1]
|
||||||
filter_map[regex_id].blocked+=1
|
with self.filter_map_lock:
|
||||||
if self.callback_blocked_update: self.callback_blocked_update(filter_map[regex_id])
|
self.filter_map[regex_id].blocked+=1
|
||||||
|
if self.callback_blocked_update: self.callback_blocked_update(self.filter_map[regex_id])
|
||||||
self.process.stdout.close()
|
self.process.stdout.close()
|
||||||
return self.process.wait()
|
return self.process.wait()
|
||||||
finally:
|
finally:
|
||||||
@@ -91,10 +94,11 @@ class Proxy:
|
|||||||
|
|
||||||
def reload(self):
|
def reload(self):
|
||||||
if self.isactive():
|
if self.isactive():
|
||||||
filter_map = self.compile_filters()
|
with self.filter_map_lock:
|
||||||
filters_codes = list(filter_map.keys())
|
self.filter_map = self.compile_filters()
|
||||||
self.__write_config(filters_codes)
|
filters_codes = list(self.filter_map.keys())
|
||||||
self.trigger_reload_config()
|
self.__write_config(filters_codes)
|
||||||
|
self.trigger_reload_config()
|
||||||
|
|
||||||
def isactive(self):
|
def isactive(self):
|
||||||
return True if self.process else False
|
return True if self.process else False
|
||||||
|
|||||||
@@ -407,12 +407,14 @@ int main(int argc, char* argv[])
|
|||||||
const std::string local_host = argv[1];
|
const std::string local_host = argv[1];
|
||||||
const std::string forward_host = argv[3];
|
const std::string forward_host = argv[3];
|
||||||
|
|
||||||
|
config_file = argv[5];
|
||||||
|
|
||||||
update_regex();
|
update_regex();
|
||||||
signal(SIGUSR1, signal_handler);
|
signal(SIGUSR1, signal_handler);
|
||||||
signal(SIGTERM, signal_handler);
|
signal(SIGTERM, signal_handler);
|
||||||
signal(SIGSEGV, signal_handler);
|
signal(SIGSEGV, signal_handler);
|
||||||
|
|
||||||
config_file = argv[5];
|
|
||||||
|
|
||||||
|
|
||||||
boost::asio::io_service ios;
|
boost::asio::io_service ios;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from asyncore import file_dispatcher
|
from asyncore import file_dispatcher
|
||||||
from imp import reload
|
from imp import reload
|
||||||
|
from pstats import Stats
|
||||||
from proxy import Filter, Proxy
|
from proxy import Filter, Proxy
|
||||||
import random, string, os, threading, sqlite3, time, atexit, socket
|
import random, string, os, threading, sqlite3, time, atexit, socket
|
||||||
from kthread import KThread
|
from kthread import KThread
|
||||||
@@ -261,8 +262,9 @@ class ProxyManager:
|
|||||||
else:
|
else:
|
||||||
self.__update_status_db(id, previous_status)
|
self.__update_status_db(id, previous_status)
|
||||||
|
|
||||||
if restart_required: proxy.restart()
|
if previous_status != STATUS.STOP:
|
||||||
elif reload_required: proxy.reload()
|
if restart_required: proxy.restart(in_pause=(previous_status == STATUS.PAUSE))
|
||||||
|
elif reload_required and previous_status != STATUS.PAUSE: proxy.reload()
|
||||||
|
|
||||||
signal.wait()
|
signal.wait()
|
||||||
signal.clear()
|
signal.clear()
|
||||||
|
|||||||
Reference in New Issue
Block a user