|
@@ -482,40 +482,10 @@ class OutboundClient:
|
|
|
def __init__(self, agent, app):
|
|
|
self.app = app
|
|
|
self.logger = app.logger
|
|
|
- self.whitelist = []
|
|
|
- self.update_whitelist() # 初始化加载白名单
|
|
|
-
|
|
|
- # 定时更新白名单
|
|
|
- threading.Thread(target=self.refresh_whitelist, daemon=True).start()
|
|
|
-
|
|
|
-
|
|
|
- self.dataHandleServer = DataHandleServer(app)
|
|
|
- #threading.Thread(target=self.start, args=('0.0.0.0', 8084, agent, logger)).start()
|
|
|
server_thread = threading.Thread(target=self.start, args=('0.0.0.0', 8084, agent))
|
|
|
server_thread.daemon = True # 设置守护线程
|
|
|
server_thread.start()
|
|
|
|
|
|
- def update_whitelist(self):
|
|
|
- with self.app.app_context():
|
|
|
- phones = Whitelist.query.filter_by(del_flag=0).all()
|
|
|
- self.whitelist = [phone.phone for phone in phones]
|
|
|
- self.logger.info("Whitelist updated: %s", self.whitelist)
|
|
|
-
|
|
|
- def refresh_whitelist(self):
|
|
|
- while True:
|
|
|
- time.sleep(3600) # 每 1小时 更新一次
|
|
|
- self.update_whitelist()
|
|
|
-
|
|
|
- def load_whitelist(self):
|
|
|
- return self.whitelist
|
|
|
-
|
|
|
- def load_agent_monitor(self):
|
|
|
- with self.app.app_context():
|
|
|
- agents = AgentMonitor.query.filter_by(check_state=0,service_state=2).all()
|
|
|
- agent_nums = [agent.agent_num for agent in agents]
|
|
|
- return agent_nums
|
|
|
-
|
|
|
-
|
|
|
class ESLRequestHandler(socketserver.BaseRequestHandler):
|
|
|
def setup(self):
|
|
|
try:
|
|
@@ -618,18 +588,44 @@ class OutboundClient:
|
|
|
|
|
|
|
|
|
class CustomTCPServer(socketserver.TCPServer):
|
|
|
- def __init__(self, server_address, RequestHandlerClass, agent, app,whitelist_loader,load_agent_monitor,dataHandleServer):
|
|
|
+ def __init__(self, server_address, RequestHandlerClass, agent, app):
|
|
|
+ super().__init__(server_address, RequestHandlerClass)
|
|
|
self.agent = agent
|
|
|
+ self.app = app
|
|
|
self.cache = Cache(app)
|
|
|
self.logger = app.logger
|
|
|
- self.load_whitelist = whitelist_loader
|
|
|
- self.load_agent_monitor = load_agent_monitor
|
|
|
- self.dataHandleServer = dataHandleServer
|
|
|
- super().__init__(server_address, RequestHandlerClass)
|
|
|
+ self.whitelist = []
|
|
|
+ self.update_whitelist() # 初始化加载白名单
|
|
|
+ self.dataHandleServer = DataHandleServer(app)
|
|
|
+ # 定时更新白名单
|
|
|
+ threading.Thread(target=self.refresh_whitelist, daemon=True).start()
|
|
|
+
|
|
|
+ def update_whitelist(self):
|
|
|
+ with self.app.app_context():
|
|
|
+ phones = Whitelist.query.filter_by(del_flag=0).all()
|
|
|
+ self.whitelist = [phone.phone for phone in phones]
|
|
|
+ self.logger.info("Whitelist updated: %s", self.whitelist)
|
|
|
+
|
|
|
+
|
|
|
+ def refresh_whitelist(self):
|
|
|
+ while True:
|
|
|
+ time.sleep(3600) # 每 1小时 更新一次
|
|
|
+ self.update_whitelist()
|
|
|
+
|
|
|
+
|
|
|
+ def load_whitelist(self):
|
|
|
+ return self.whitelist
|
|
|
+
|
|
|
+
|
|
|
+ def load_agent_monitor(self):
|
|
|
+ with self.app.app_context():
|
|
|
+ agents = AgentMonitor.query.filter_by(check_state=0, service_state=2).all()
|
|
|
+ agent_nums = [agent.agent_num for agent in agents]
|
|
|
+ return agent_nums
|
|
|
|
|
|
def start(self, HOST='0.0.0.0', PORT=8084, agent=None):
|
|
|
# HOST, PORT = "0.0.0.0", 8084
|
|
|
# 创建一个 TCP 服务器
|
|
|
- with self.CustomTCPServer((HOST, PORT), self.ESLRequestHandler, agent, self.app, self.load_whitelist, self.load_agent_monitor,self.dataHandleServer) as server:
|
|
|
+ with self.CustomTCPServer((HOST, PORT), self.ESLRequestHandler, agent, self.app) as server:
|
|
|
print(f"ESL server listening on {HOST}:{PORT}")
|
|
|
server.serve_forever()
|