Fixed counter
This commit is contained in:
@@ -207,10 +207,6 @@ class Filter:
|
|||||||
|
|
||||||
def check(self, data):
|
def check(self, data):
|
||||||
return True if self.compiled_regex.search(data) else False
|
return True if self.compiled_regex.search(data) else False
|
||||||
|
|
||||||
def inc_block(self):
|
|
||||||
print("INC", self.blocked)
|
|
||||||
self.blocked+=1
|
|
||||||
|
|
||||||
class Proxy:
|
class Proxy:
|
||||||
def __init__(self, port, filters=None):
|
def __init__(self, port, filters=None):
|
||||||
@@ -231,11 +227,13 @@ class Proxy:
|
|||||||
def regex_filter(pkt, data, by_client):
|
def regex_filter(pkt, data, by_client):
|
||||||
packet = bytes(data[TCP if TCP in data else UDP].payload)
|
packet = bytes(data[TCP if TCP in data else UDP].payload)
|
||||||
try:
|
try:
|
||||||
for filter in self.filters:
|
for i, filter in enumerate(self.filters):
|
||||||
if (by_client and filter.c_to_s) or (not by_client and filter.s_to_c):
|
if (by_client and filter.c_to_s) or (not by_client and filter.s_to_c):
|
||||||
match = filter.check(packet)
|
match = filter.check(packet)
|
||||||
if (filter.is_blacklist and match) or (not filter.is_blacklist and not match):
|
if (filter.is_blacklist and match) or (not filter.is_blacklist and not match):
|
||||||
filter.inc_block()
|
filter.blocked+=1
|
||||||
|
try: self.filters[i] = filter
|
||||||
|
except Exception: pass
|
||||||
pkt.drop()
|
pkt.drop()
|
||||||
return
|
return
|
||||||
except IndexError: pass
|
except IndexError: pass
|
||||||
|
|||||||
@@ -176,9 +176,11 @@ class ProxyManager:
|
|||||||
self.db = db
|
self.db = db
|
||||||
self.proxy_table: Dict[ServiceManager] = {}
|
self.proxy_table: Dict[ServiceManager] = {}
|
||||||
self.lock = asyncio.Lock()
|
self.lock = asyncio.Lock()
|
||||||
|
self.updater_task = None
|
||||||
|
|
||||||
def init_updater(self):
|
def init_updater(self):
|
||||||
asyncio.create_task(self._stats_updater())
|
if not self.updater_task:
|
||||||
|
self.updater_task = asyncio.create_task(self._stats_updater())
|
||||||
|
|
||||||
async def close(self):
|
async def close(self):
|
||||||
for key in list(self.proxy_table.keys()):
|
for key in list(self.proxy_table.keys()):
|
||||||
@@ -202,7 +204,6 @@ class ProxyManager:
|
|||||||
|
|
||||||
async def _stats_updater(self):
|
async def _stats_updater(self):
|
||||||
while True:
|
while True:
|
||||||
print("ALIVE!")
|
|
||||||
try:
|
try:
|
||||||
for key in list(self.proxy_table.keys()):
|
for key in list(self.proxy_table.keys()):
|
||||||
self.proxy_table[key].update_stats()
|
self.proxy_table[key].update_stats()
|
||||||
|
|||||||
Reference in New Issue
Block a user