This commit is contained in:
本间白猫 2025-01-07 15:38:23 +08:00
parent 67a5049f3b
commit 1f8419d07a
4 changed files with 38 additions and 12 deletions

View File

@ -10,5 +10,5 @@ RUN pip install --no-cache-dir -r requirements.txt
EXPOSE 1080 EXPOSE 1080
CMD ["python", "ProxyCat.py", "-c", "/app/config/config.ini"] CMD ["python", "ProxyCat.py"]

View File

@ -30,12 +30,23 @@ logging.basicConfig(level=logging.INFO, handlers=[console_handler])
def update_status(server): def update_status(server):
while True: while True:
if server.mode == 'load_balance': try:
status = f"\r{Fore.YELLOW}{get_message('current_proxy', server.language)}: {Fore.GREEN}{server.current_proxy}" if server.mode == 'load_balance':
else: status = f"\r{Fore.YELLOW}{get_message('current_proxy', server.language)}: {Fore.GREEN}{server.current_proxy}"
time_left = server.time_until_next_switch() else:
status = f"\r{Fore.YELLOW}{get_message('current_proxy', server.language)}: {Fore.GREEN}{server.current_proxy} | {Fore.YELLOW}{get_message('next_switch', server.language)}: {Fore.GREEN}{time_left:.1f}{get_message('seconds', server.language)}" time_left = server.time_until_next_switch()
print(status, end='', flush=True) if time_left == float('inf'):
status = f"\r{Fore.YELLOW}{get_message('current_proxy', server.language)}: {Fore.GREEN}{server.current_proxy}"
else:
status = f"\r{Fore.YELLOW}{get_message('current_proxy', server.language)}: {Fore.GREEN}{server.current_proxy} | {Fore.YELLOW}{get_message('next_switch', server.language)}: {Fore.GREEN}{time_left:.1f}{get_message('seconds', server.language)}"
if os.path.exists('/.dockerenv'):
logging.info(status)
else:
print(status, end='', flush=True)
except Exception as e:
logging.error(f"Status update error: {e}")
time.sleep(1) time.sleep(1)
async def handle_client_wrapper(server, reader, writer, clients): async def handle_client_wrapper(server, reader, writer, clients):

View File

@ -1,9 +1,11 @@
version: '3'
services: services:
app: app:
build: . build: .
container_name: proxycat container_name: proxycat
ports:
- "1080:1080"
volumes: volumes:
- "./config:/app/config" - ./config:/app/config
network_mode: host restart: unless-stopped
command: ["python", "ProxyCat.py", "-c", "/app/config/config.ini"] network_mode: "bridge"
restart: always

View File

@ -1,4 +1,4 @@
import asyncio, httpx, logging, re, socket, struct, time, socket, base64, random import asyncio, httpx, logging, re, socket, struct, time, socket, base64, random, os
from modules.modules import get_message, load_ip_list from modules.modules import get_message, load_ip_list
from asyncio import TimeoutError from asyncio import TimeoutError
from itertools import cycle from itertools import cycle
@ -612,3 +612,16 @@ class AsyncProxyServer:
print(f"{direction} 数据传输超时") print(f"{direction} 数据传输超时")
except Exception as e: except Exception as e:
print(f"{direction} 数据传输错误: {e}") print(f"{direction} 数据传输错误: {e}")
def is_docker():
return os.path.exists('/.dockerenv')
async def get_proxy_status(self):
if self.mode == 'load_balance':
return f"{get_message('current_proxy', self.language)}: {self.current_proxy}"
else:
time_left = self.time_until_next_switch()
if time_left == float('inf'):
return f"{get_message('current_proxy', self.language)}: {self.current_proxy}"
else:
return f"{get_message('current_proxy', self.language)}: {self.current_proxy} | {get_message('next_switch', self.language)}: {time_left:.1f}{get_message('seconds', self.language)}"