Spaces:
Paused
Paused
Update file-manager/app.py
Browse files- file-manager/app.py +5 -6
file-manager/app.py
CHANGED
|
@@ -13,7 +13,6 @@ def is_sensitive(name):
|
|
| 13 |
return any(h in up for h in SECRET_HINTS)
|
| 14 |
|
| 15 |
def mask_secrets(text):
|
| 16 |
-
# Guide rule 10: never surface real credential values in output.
|
| 17 |
out = []
|
| 18 |
for line in text.splitlines():
|
| 19 |
if any(h in line.upper() for h in SECRET_HINTS) and ("=" in line or ":" in line):
|
|
@@ -35,6 +34,7 @@ input[type=text],select{{background:#000;color:#eee;border:1px solid #333;paddin
|
|
| 35 |
button,input[type=submit]{{background:#F46821;color:#fff;border:0;padding:6px 14px;border-radius:4px;cursor:pointer}}
|
| 36 |
</style></head><body>
|
| 37 |
<div class="tabs bar"><a href="/fm/">📁 Files</a><a href="/fm/term">🖥️ Terminal</a>
|
|
|
|
| 38 |
<span style="color:#777">test mode · storage is ephemeral</span></div>
|
| 39 |
{body}</body></html>"""
|
| 40 |
|
|
@@ -46,10 +46,9 @@ def term():
|
|
| 46 |
output = ""
|
| 47 |
if request.method == "POST":
|
| 48 |
cmd = request.form.get("cmd", "")
|
| 49 |
-
# allow "cd" to persist working directory between commands
|
| 50 |
if cmd.strip().startswith("cd "):
|
| 51 |
target = cmd.strip()[3:].strip()
|
| 52 |
-
new = os.path.abspath(os.path.join(cwd, target))
|
| 53 |
if os.path.isdir(new):
|
| 54 |
cwd, output = new, f"(cwd -> {new})"
|
| 55 |
else:
|
|
@@ -57,12 +56,12 @@ def term():
|
|
| 57 |
elif cmd.strip():
|
| 58 |
try:
|
| 59 |
r = subprocess.run(cmd, shell=True, cwd=cwd, capture_output=True,
|
| 60 |
-
text=True, timeout=
|
| 61 |
output = (r.stdout or "") + (r.stderr or "")
|
| 62 |
if r.returncode != 0 and not output:
|
| 63 |
output = f"[exit code {r.returncode}]"
|
| 64 |
except subprocess.TimeoutExpired:
|
| 65 |
-
output = "[timed out after
|
| 66 |
except Exception as e:
|
| 67 |
output = f"[error: {e}]"
|
| 68 |
output = mask_secrets(output)
|
|
@@ -71,7 +70,7 @@ def term():
|
|
| 71 |
<div class="bar"><b>cwd:</b> {html.escape(cwd)}</div>
|
| 72 |
<form method="post">
|
| 73 |
<input type="hidden" name="cwd" value="{html.escape(cwd)}">
|
| 74 |
-
<input type="text" name="cmd" placeholder="
|
| 75 |
style="width:80%" autofocus value="{html.escape(cmd)}">
|
| 76 |
<input type="submit" value="Run">
|
| 77 |
</form>
|
|
|
|
| 13 |
return any(h in up for h in SECRET_HINTS)
|
| 14 |
|
| 15 |
def mask_secrets(text):
|
|
|
|
| 16 |
out = []
|
| 17 |
for line in text.splitlines():
|
| 18 |
if any(h in line.upper() for h in SECRET_HINTS) and ("=" in line or ":" in line):
|
|
|
|
| 34 |
button,input[type=submit]{{background:#F46821;color:#fff;border:0;padding:6px 14px;border-radius:4px;cursor:pointer}}
|
| 35 |
</style></head><body>
|
| 36 |
<div class="tabs bar"><a href="/fm/">📁 Files</a><a href="/fm/term">🖥️ Terminal</a>
|
| 37 |
+
<a href="/reload">♻️ Reload</a><a href="/gpuinfo">🎮 GPU</a>
|
| 38 |
<span style="color:#777">test mode · storage is ephemeral</span></div>
|
| 39 |
{body}</body></html>"""
|
| 40 |
|
|
|
|
| 46 |
output = ""
|
| 47 |
if request.method == "POST":
|
| 48 |
cmd = request.form.get("cmd", "")
|
|
|
|
| 49 |
if cmd.strip().startswith("cd "):
|
| 50 |
target = cmd.strip()[3:].strip()
|
| 51 |
+
new = target if target.startswith("/") else os.path.abspath(os.path.join(cwd, target))
|
| 52 |
if os.path.isdir(new):
|
| 53 |
cwd, output = new, f"(cwd -> {new})"
|
| 54 |
else:
|
|
|
|
| 56 |
elif cmd.strip():
|
| 57 |
try:
|
| 58 |
r = subprocess.run(cmd, shell=True, cwd=cwd, capture_output=True,
|
| 59 |
+
text=True, timeout=120)
|
| 60 |
output = (r.stdout or "") + (r.stderr or "")
|
| 61 |
if r.returncode != 0 and not output:
|
| 62 |
output = f"[exit code {r.returncode}]"
|
| 63 |
except subprocess.TimeoutExpired:
|
| 64 |
+
output = "[timed out after 120s]"
|
| 65 |
except Exception as e:
|
| 66 |
output = f"[error: {e}]"
|
| 67 |
output = mask_secrets(output)
|
|
|
|
| 70 |
<div class="bar"><b>cwd:</b> {html.escape(cwd)}</div>
|
| 71 |
<form method="post">
|
| 72 |
<input type="hidden" name="cwd" value="{html.escape(cwd)}">
|
| 73 |
+
<input type="text" name="cmd" placeholder="ls -la, df -h, free -h, nproc, pip install ..."
|
| 74 |
style="width:80%" autofocus value="{html.escape(cmd)}">
|
| 75 |
<input type="submit" value="Run">
|
| 76 |
</form>
|