feat: add RolesPage.tsx, patch_all_modules.py for all 4 addon modules

This commit is contained in:
2026-06-11 21:29:54 -05:00
parent ded0d6f1b1
commit 3236acab16
4 changed files with 483 additions and 0 deletions

87
scripts/patch_routes.py Normal file
View File

@@ -0,0 +1,87 @@
#!/usr/bin/env python3
"""
Patch routes.ts and ServerRouter.tsx to inject addon routes (network tab nav link).
This patcher understands Pterodactyl's actual routing structure.
"""
import sys
import os
PANEL = '/var/www/pterodactyl'
ROUTES_FILE = f'{PANEL}/resources/scripts/routers/routes.ts'
SERVER_ROUTER = f'{PANEL}/resources/scripts/routers/ServerRouter.tsx'
# ─── 1. Patch routes.ts ───────────────────────────────────────────────────────
print("=== Patching routes.ts ===")
content = open(ROUTES_FILE).read()
ADDON_IMPORT = "import NetworkTab from '@/addons/advanced-admin/network/NetworkTab';"
ADDON_ROUTE = """,
{
path: '/addon-network',
permission: null,
name: 'Live Network',
component: NetworkTab,
}"""
patched = False
# Add import near top if not present
if ADDON_IMPORT not in content:
# Insert after last existing import line
lines = content.splitlines(keepends=True)
last_import = 0
for i, line in enumerate(lines):
if line.strip().startswith('import ') or line.strip().startswith('const ') and 'lazy' in line:
last_import = i
lines.insert(last_import + 1, ADDON_IMPORT + '\n')
content = ''.join(lines)
print(f" Added import at line {last_import + 2}")
else:
print(" Import already present")
# Add route entry before closing of server array
if '/addon-network' not in content:
# Find the last route entry (before closing ], server array end)
# Insert before the closing ` ],` that ends the server array
# The server array ends with the activity route, then ` ],`
insert_anchor = " {\n path: '/activity',\n permission: 'activity.*',\n name: 'Activity',\n component: ServerActivityLogContainer,"
closing = " },\n ],\n} as Routes;"
if insert_anchor in content and closing in content:
# Find and insert our route before the closing `] as Routes`
content = content.replace(
" },\n ],\n} as Routes;",
f" }},{ADDON_ROUTE},\n ],\n}} as Routes;"
)
patched = True
print(" Added /addon-network route entry")
else:
print(" WARNING: Could not find anchor for route insertion")
print(" Trying simpler approach...")
# Simpler: insert before `] as Routes`
if " ],\n} as Routes;" in content:
content = content.replace(
" ],\n} as Routes;",
f"{ADDON_ROUTE},\n ],\n}} as Routes;"
)
patched = True
print(" Added route entry (simple method)")
else:
print(" Route already present")
patched = True
open(ROUTES_FILE, 'w').write(content)
print(f" routes.ts saved. Patched={patched}")
# ─── 2. Clean up ServerRouter.tsx (remove the broken import we added) ─────────
print("\n=== Cleaning ServerRouter.tsx ===")
sr_content = open(SERVER_ROUTER).read()
bad_import = "import NetworkTab from '@/addons/advanced-admin/network/NetworkTab';\n"
if bad_import in sr_content:
sr_content = sr_content.replace(bad_import, '')
open(SERVER_ROUTER, 'w').write(sr_content)
print(" Removed stray NetworkTab import from ServerRouter.tsx")
else:
print(" ServerRouter.tsx is clean")
print("\nDone. Now rebuild the frontend.")