refactor: delete .SANDBOX_BANNED_HOSTS file if SANDBOX_PYTHON_BANNED_KEYWORDS is empty/
parent
da73582093
commit
ad1742fd0f
|
|
@ -28,14 +28,14 @@ class ToolExecutor:
|
||||||
os.system(f"chown -R {self.user}:root {self.sandbox_path}")
|
os.system(f"chown -R {self.user}:root {self.sandbox_path}")
|
||||||
self.banned_keywords = CONFIG.get("SANDBOX_PYTHON_BANNED_KEYWORDS", 'nothing_is_banned').split(',');
|
self.banned_keywords = CONFIG.get("SANDBOX_PYTHON_BANNED_KEYWORDS", 'nothing_is_banned').split(',');
|
||||||
try:
|
try:
|
||||||
|
banned_hosts_file_path = f'{self.sandbox_path}/.SANDBOX_BANNED_HOSTS'
|
||||||
|
if os.path.exists(banned_hosts_file_path):
|
||||||
|
os.remove(banned_hosts_file_path)
|
||||||
banned_hosts = CONFIG.get("SANDBOX_PYTHON_BANNED_HOSTS", '').strip()
|
banned_hosts = CONFIG.get("SANDBOX_PYTHON_BANNED_HOSTS", '').strip()
|
||||||
if banned_hosts:
|
if banned_hosts:
|
||||||
hostname = socket.gethostname()
|
hostname = socket.gethostname()
|
||||||
local_ip = socket.gethostbyname(hostname)
|
local_ip = socket.gethostbyname(hostname)
|
||||||
banned_hosts = f"{banned_hosts},{hostname},{local_ip}"
|
banned_hosts = f"{banned_hosts},{hostname},{local_ip}"
|
||||||
banned_hosts_file_path = f'{self.sandbox_path}/.SANDBOX_BANNED_HOSTS'
|
|
||||||
if os.path.exists(banned_hosts_file_path):
|
|
||||||
os.remove(banned_hosts_file_path)
|
|
||||||
with open(banned_hosts_file_path, "w") as f:
|
with open(banned_hosts_file_path, "w") as f:
|
||||||
f.write(banned_hosts)
|
f.write(banned_hosts)
|
||||||
os.chmod(banned_hosts_file_path, 0o644)
|
os.chmod(banned_hosts_file_path, 0o644)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue