Fix bug
This commit is contained in:
@@ -15,7 +15,7 @@ sudo menu
|
||||
|
||||
The installer installs required packages, Go, PostgreSQL, Xray, the `sshpanel` systemd service, and the `menu` command. It generates service credentials and writes configuration under `/opt/sshpanel`. It needs network access for system packages, Go, and Xray. An extracted source archive can be installed with `sudo bash install.sh` from its root. If `/usr/local/bin/menu` already exists, the installer saves a timestamped backup before replacing it. Use a fresh server because installation creates new database and configuration credentials.
|
||||
|
||||
Run `sudo menu` for the command menu. `sudo dragoncore` is an alias. The header shows CPU, RAM, disk, uptime, network traffic, SSH and Xray activity, and service status. The menu adjusts to narrow terminals; `sudo menu --mobile` forces the compact layout, or set `DRAGONCORE_COLUMNS=36`. A terminal editor such as `nano` or `$EDITOR` is used for advanced JSON settings.
|
||||
Run `sudo menu` for the command menu. `sudo dragoncore` is an alias. The header shows CPU, RAM, disk, uptime, network traffic, SSH and Xray activity, and service status. Each menu redraw clears the visible terminal; after a command prints results, press Enter to return to the menu. The menu adjusts to narrow terminals; `sudo menu --mobile` forces the compact layout, or set `DRAGONCORE_COLUMNS=36`. A terminal editor such as `nano` or `$EDITOR` is used for advanced JSON settings.
|
||||
|
||||
| Command | Purpose |
|
||||
| --- | --- |
|
||||
|
||||
+26
-5
@@ -467,10 +467,10 @@ def xray_inbounds():
|
||||
print_wrapped(f"{inbound.get('tag')} ({inbound.get('protocol')}/{inbound.get('network') or 'tcp'}, "
|
||||
f"{endpoint}, path {inbound.get('path') or '-'})")
|
||||
for c in inbound.get("clients") or []:
|
||||
print_wrapped(f"{c.get('name') or c.get('email') or c.get('uuid')} "
|
||||
print_wrapped(f"{c.get('name') or c.get('email') or c.get('id') or c.get('uuid')} "
|
||||
f"online={c.get('online', False)} "
|
||||
f"usage={size(c.get('total_bytes', 0))}", " ")
|
||||
print_wrapped(str(c.get('uuid')), " ")
|
||||
print_wrapped(str(c.get('id') or c.get('uuid')), " ")
|
||||
return inbounds
|
||||
|
||||
|
||||
@@ -590,7 +590,8 @@ def xray_delete():
|
||||
def xray_edit():
|
||||
client_uuid = ask("Client UUID")
|
||||
client = next((c for inbound in request("GET", "/api/xray/inbounds") or []
|
||||
for c in inbound.get("clients") or [] if c.get("uuid") == client_uuid), None)
|
||||
for c in inbound.get("clients") or []
|
||||
if (c.get("id") or c.get("uuid")) == client_uuid), None)
|
||||
if not client:
|
||||
raise CLIError("Xray client not found")
|
||||
p = {"uuid": client_uuid, "name": client.get("name") or "",
|
||||
@@ -842,23 +843,43 @@ def render_menu(title, options, vps_status=None, columns=None):
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def clear_screen():
|
||||
if sys.stdout.isatty():
|
||||
sys.stdout.write("\033[2J\033[H")
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
_menu_calls = 0
|
||||
|
||||
|
||||
def menu(title, options):
|
||||
global _menu_calls
|
||||
_menu_calls += 1
|
||||
while True:
|
||||
clear_screen()
|
||||
vps = collect_vps_status() if title == "MAIN MENU" else None
|
||||
print("\n" + render_menu(title, options, vps))
|
||||
print(render_menu(title, options, vps))
|
||||
choice = input("Choose: ").strip().lstrip("0") or "0"
|
||||
if choice == "0":
|
||||
return
|
||||
entry = options.get(choice)
|
||||
if not entry:
|
||||
print("Invalid option.")
|
||||
continue
|
||||
else:
|
||||
current_menu_calls = _menu_calls
|
||||
try:
|
||||
entry[1]()
|
||||
except (CLIError, ValueError, json.JSONDecodeError, OSError) as exc:
|
||||
print("Error:", exc)
|
||||
except KeyboardInterrupt:
|
||||
print("\nCancelled.")
|
||||
if _menu_calls != current_menu_calls:
|
||||
continue # A submenu already showed its own output and prompts.
|
||||
if sys.stdin.isatty() and sys.stdout.isatty():
|
||||
try:
|
||||
input("\nPress Enter to return to menu...")
|
||||
except (EOFError, KeyboardInterrupt):
|
||||
print()
|
||||
|
||||
|
||||
def ssh_menu():
|
||||
|
||||
@@ -71,6 +71,25 @@ class TokenManagementTest(unittest.TestCase):
|
||||
self.assertIn("CPU: 12.5%", mobile)
|
||||
self.assertIn("SSH: 1 on / 2 total", mobile)
|
||||
|
||||
def test_menu_clears_on_open_and_redraw_after_output_pause(self):
|
||||
output = io.StringIO()
|
||||
with redirect_stdout(output), patch.object(output, "isatty", return_value=True), \
|
||||
patch.object(cli.sys, "stdin", SimpleNamespace(isatty=lambda: True)), \
|
||||
patch("builtins.input", side_effect=["1", "", "0"]) as ask:
|
||||
cli.menu("TEST", {"1": ("Show result", lambda: print("RESULT"))})
|
||||
self.assertEqual(output.getvalue().count("\033[2J\033[H"), 2)
|
||||
self.assertIn("RESULT", output.getvalue())
|
||||
self.assertIn("Press Enter to return", ask.call_args_list[1].args[0])
|
||||
|
||||
def test_returning_from_submenu_redraws_without_extra_pause(self):
|
||||
output = io.StringIO()
|
||||
with redirect_stdout(output), patch.object(output, "isatty", return_value=True), \
|
||||
patch.object(cli.sys, "stdin", SimpleNamespace(isatty=lambda: True)), \
|
||||
patch("builtins.input", side_effect=["1", "0", "0"]) as ask:
|
||||
cli.menu("PARENT", {"1": ("Submenu", lambda: cli.menu("CHILD", {}))})
|
||||
self.assertEqual(ask.call_count, 3)
|
||||
self.assertEqual(output.getvalue().count("\033[2J\033[H"), 3)
|
||||
|
||||
def test_user_list_fits_phone_terminal(self):
|
||||
users = [{"username": "account-with-a-long-name", "active_conns": 2,
|
||||
"max_connections": 5, "total_bytes": 1234567,
|
||||
@@ -116,6 +135,20 @@ class TokenManagementTest(unittest.TestCase):
|
||||
with self.assertRaisesRegex(cli.CLIError, "native"):
|
||||
cli.xray_shared_port()
|
||||
|
||||
def test_xray_client_id_is_displayed_and_editable(self):
|
||||
inbounds = [{"tag": "vless", "protocol": "vless", "clients": [
|
||||
{"id": "client-uuid", "name": "alice", "max_conns": 2}
|
||||
]}]
|
||||
with patch.object(cli, "request", return_value=inbounds) as request, \
|
||||
patch.object(cli, "ask", side_effect=["client-uuid", "2"]), \
|
||||
patch.object(cli, "number", return_value=3), \
|
||||
redirect_stdout(io.StringIO()) as output:
|
||||
cli.xray_inbounds()
|
||||
cli.xray_edit()
|
||||
self.assertIn("client-uuid", output.getvalue())
|
||||
self.assertEqual(request.call_args.args[:2], ("POST", "/api/xray/clients/update"))
|
||||
self.assertEqual(request.call_args.args[2]["uuid"], "client-uuid")
|
||||
|
||||
def test_git_update_uses_installed_updater_without_prompt(self):
|
||||
updater = Path(self.temp.name) / "update.sh"
|
||||
updater.write_text("#!/bin/bash\n")
|
||||
|
||||
Reference in New Issue
Block a user