Fix: Hardened path mapping and verbose logs
This commit is contained in:
24
tools.py
24
tools.py
@@ -44,18 +44,28 @@ def get_system_health() -> str:
|
||||
|
||||
def read_vps_file(filepath: str) -> str:
|
||||
"""Lê um arquivo do sistema de arquivos da VPS através do mapeamento /host_root."""
|
||||
host_path = f"/host_root{filepath}" if not filepath.startswith("/host_root") else filepath
|
||||
# Se ainda assim não começar com /host_root e não for absoluto para o container, tentamos prefixar
|
||||
if not host_path.startswith("/host_root") and filepath.startswith("/"):
|
||||
host_path = "/host_root" + filepath
|
||||
# Garante que o caminho comece com /host_root
|
||||
clean_path = filepath
|
||||
if clean_path.startswith("/host_root"):
|
||||
host_path = clean_path
|
||||
else:
|
||||
# Se o usuário mandou /root/vps..., vira /host_root/root/vps...
|
||||
host_path = os.path.join("/host_root", clean_path.lstrip("/"))
|
||||
|
||||
try:
|
||||
if not os.path.exists("/host_root"):
|
||||
return "ERRO CRÍTICO: O diretório /host_root não existe no container! O mapeamento de volume falhou."
|
||||
|
||||
if not os.path.exists(host_path):
|
||||
return f"Erro: Arquivo {filepath} não encontrado no host (Caminho tentado: {host_path})."
|
||||
# Tenta listar o diretório pai para ajudar no debug
|
||||
parent = os.path.dirname(host_path)
|
||||
content = os.listdir(parent) if os.path.exists(parent) else "Pai não existe"
|
||||
return f"Erro: {filepath} não encontrado (Caminho real: {host_path}). Conteúdo do pai: {content}"
|
||||
|
||||
with open(host_path, 'r') as f:
|
||||
return f.read(2000) # Limite para não estourar o contexto
|
||||
return f.read(2000)
|
||||
except Exception as e:
|
||||
return f"Erro ao ler arquivo: {e}"
|
||||
return f"Erro ao acessar {filepath}: {e}"
|
||||
|
||||
def get_docker_stats() -> str:
|
||||
"""Retorna o uso de CPU/RAM de todos os containers ativos via comando docker stats."""
|
||||
|
||||
Reference in New Issue
Block a user